MK-*_*rou 2 rest json yaml swagger swagger-editor
我使用swagger-springmvc注释开发了一些由swagger记录的Rest Web服务.现在,我想使用swagger-editor生成客户端Rest Web服务代码,但swagger-editor需要Yaml或Json文件.你知道是否有办法生成这个文件?提前谢谢
编辑: 这可以通过使用swagger-mvn-plugin完成,但我没有找到如何做到的例子?
我回复自己:).您可以使用swagger-maven-plugin生成客户端和服务器端文档(yaml,json和html)
将其添加到您的pom.xml:
.....
<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>your-email@email.com</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> ........
Run Code Online (Sandbox Code Playgroud)
您可以在以下地址下载*.hbs模板:https: //github.com/kongchen/swagger-maven-example
mvn swagger:generate
将在项目/generated/swagger/目录中生成执行Json文档.过了这个地址:http:
//editor.swagger.io
并生成您想要的任何内容(您首选技术中的服务器端或客户端API)
| 归档时间: |
|
| 查看次数: |
11104 次 |
| 最近记录: |