OpenAPI自动生成代码

前后分离后接口实现先定义采用yaml的方式。

核心关键字:OpenAPI、swagger

教程:https://www.cnblogs.com/meihuashou/articles/16471654.html

swagger yaml 规范3.0

Basic Structure

swagger yaml 规范2.0

Basic Structure

swagger-api

GitHub - swagger-api/swagger-codegen: swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.

生成代码基于swagger2.0的代码官方例子

https://github.com/OpenAPITools/openapi-generator/tree/master/samples/server/petstore/springboot/src/main

一个能运行的例子

GitHub - thomasJoei/swagger-codegen-springboot: Ready to use example of Swagger codegen, using swagger-codegen-maven-plugin.

swagger-codegen-maven-pluging官方

https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen-maven-plugin

需要设置swagger生成的代码的文件夹为source

Swagger Documentation

java - Remove ResponseEntity in swagger-codegen-maven-plugin api class - Stack Overflow 

swagger codegen 和OpenAPI codegen的区别

https://openapi-generator.tech/docs/faq/#what-is-the-difference-between-swagger-codegen-and-openapi-generator

多个接口文件可以参考Use Groovy to customize the Maven build process | Red Hat Developer

json - Generate code for multiple swaggers in the same project - Stack Overflow

数据类型:Data Types

多个接口文件的核心:

1、先保证单个的可以正常编译(A和B)

2、复制A接口yml文件及相关定义的yml文件到同B项目对应目录

3、修改B项目的pom.xml

3.1)复制一份(是一对)execution,然后对原来的execution增加id标签(如没有id标签的话增加)并将id的值命名为g01,原来B项目的execution的id标签的id值命名为g02

4、编译即可 

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值