从Swagger文档生成Yaml或Json文件 [英] Generate Yaml or Json file from Swagger documentation
问题描述
我已经使用swagger-springmvc注释开发了一些由swagger记录的Rest Web服务. 现在,我想使用swagger-editor生成客户端Rest Web服务代码,但是swagger-editor需要Yaml或Json文件.您知道是否有生成此文件的方法吗? 在此先感谢
I have developpe some Rest web service documented by swagger, using swagger-springmvc annotions. Now, I want to use swagger-editor to generate client side Rest web service code, but swagger-editor require Yaml or Json file. Do you know if there is a way to generate this file ? Thanks at advance
可以通过使用swagger-mvn-plugin来完成,但是我没有找到如何执行此操作的示例?
EDIT : It's can be done by using swagger-mvn-plugin , but I don't found an example on how to do it ?
推荐答案
我回答自己:).您可以使用 swagger-maven-plugin生成客户端和服务器端文档(yaml,json和html)
I reply to my self :) . You can generate client and server side documentation (yaml, json and html) by using swagger-maven-plugin
将此添加到您的pom.xml:
Add this to your 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> ........
您可以在以下地址下载* .hbs模板: https://github.com/kongchen/swagger-maven-example
You can download *.hbs template at this address: https://github.com/kongchen/swagger-maven-example
执行mvn swagger:generate
Json文档将在您的项目/generated/swagger/
目录中生成.
将其粘贴到此地址:
http://editor.swagger.io
Execute mvn swagger:generate
Json documentation will be generated at your project /generated/swagger/
directory.
Past it on this address :
http://editor.swagger.io
并生成所需的内容(首选技术中的服务器端或客户端API)
And generate what ever you want (Server side or Client side API in your preferred technology)
这篇关于从Swagger文档生成Yaml或Json文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!