1
我使用swagger-springmvc注释开发了一些由swagger记录的其他Web服务。 现在,我想用swagger编辑器来生成客户端Rest Web服务代码,但是Swagger编辑器需要Yaml或Json文件。你知道是否有办法生成这个文件? 感谢在前进从Swagger文档生成Yaml或Json文件
编辑: 它可以通过使用招摇,MVN-插件来实现,但我不发现如何做到这一点的例子吗?
我使用swagger-springmvc注释开发了一些由swagger记录的其他Web服务。 现在,我想用swagger编辑器来生成客户端Rest Web服务代码,但是Swagger编辑器需要Yaml或Json文件。你知道是否有办法生成这个文件? 感谢在前进从Swagger文档生成Yaml或Json文件
编辑: 它可以通过使用招摇,MVN-插件来实现,但我不发现如何做到这一点的例子吗?
我回复我的自我:)。
.....
<plugin>
<groupId>com.github.kongchen</groupId>
<artifactId>swagger-maven-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<apiSources>
<apiSource>
<springmvc>true</springmvc>
<locations>com.yourcontrollers.package.v1</locations>
<schemes>http,https</schemes>
<host>localhost:8080</host>
<basePath>/api-doc</basePath>
<info>
<title>Your API name</title>
<version>v1</version>
<description> description of your API</description>
<termsOfService>
http://www.yourterms.com
</termsOfService>
<contact>
<email>[email protected]</email>
<name>Your Name</name>
<url>http://www.contact-url.com</url>
</contact>
<license>
<url>http://www.licence-url.com</url>
<name>Commercial</name>
</license>
</info>
<!-- Support classpath or file absolute path here.
1) classpath e.g: "classpath:/markdown.hbs", "classpath:/templates/hello.html"
2) file e.g: "${basedir}/src/main/resources/markdown.hbs",
"${basedir}/src/main/resources/template/hello.html" -->
<templatePath>${basedir}/templates/strapdown.html.hbs</templatePath>
<outputPath>${basedir}/generated/document.html</outputPath>
<swaggerDirectory>generated/swagger-ui</swaggerDirectory>
<securityDefinitions>
<securityDefinition>
<name>basicAuth</name>
<type>basic</type>
</securityDefinition>
</securityDefinitions>
</apiSource>
</apiSources>
</configuration>
</plugin> ........
您可以下载* .hbs模板地址为::您可以通过使用swagger-maven-plugin
添加到您的pom.xml生成客户端和服务器端文件(YAML,JSON和HTML) https://github.com/kongchen/swagger-maven-example
执行mvn swagger:生成 JSon文档将在您的项目/ generated/swagger /目录中生成。 过去,该地址: http://editor.swagger.io
,并生成你想要什么都(在你的首选技术,服务器端或客户端API)