在github上看了swagger-api项目(https://github.com/swagger-api/swagger-codegen)中的一些文档以及swagger-codegen的使用说明,还是觉得有些麻烦,该项目中有提到使用swagger-codegen-maven-plugin但是看了下给的样例,swagger的yaml文件还是用的几年前更新的老的样例,而使用openapi3.0规范的yaml文件无法进行代码生成。在maven中央仓库中找到这样一个插件:openapi-generator-maven-plugin,在项目中使用形式如下:
Pom依赖:
org.springframework.boot
spring-boot-maven-plugin
org.openapitools
openapi-generator-maven-plugin
3.3.1
generate
${project.basedir}/src/swagger/马上开课openapi3.0文档.yaml
spring
com.example.openapigenerator.rest
com.example.openapigenerator.rest.dto
${project.basedir}
ApiUtil.java
true
将yaml文件放置在inputSpec指定的位置;生成的文件出现在output+apiPackage指定的位置;生成的model文件出现在output+modelPackage指定的位置。
测试使用的yaml文件:
openapi: 3.0.0
info:
title: xxxxAPI文档