从Swagger文档生成Yaml或Json文件

从Swagger文档生成Yaml或Json文件,json,rest,yaml,swagger,swagger-editor,Json,Rest,Yaml,Swagger,Swagger Editor,我使用swagger-springmvc注释开发了一些由swagger编写的RESTWeb服务。 现在,我想使用swagger编辑器生成客户端Rest web服务代码,但swagger编辑器需要Yaml或Json文件。你知道有没有办法生成这个文件? 提前谢谢 编辑: 这可以通过使用swagger mvn插件来实现,但我没有找到一个如何实现的示例?我回复我自己:)。您可以使用生成客户端和服务器端文档(yaml、json和html) 将此添加到pom.xml中: ..... <plugin&

我使用swagger-springmvc注释开发了一些由swagger编写的RESTWeb服务。 现在,我想使用swagger编辑器生成客户端Rest web服务代码,但swagger编辑器需要Yaml或Json文件。你知道有没有办法生成这个文件? 提前谢谢

编辑: 这可以通过使用swagger mvn插件来实现,但我没有找到一个如何实现的示例?

我回复我自己:)。您可以使用生成客户端和服务器端文档(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> ........
。。。。。
com.github.kongchen

执行
mvn招摇过市:生成

Json文档将在您的项目
/generated/swagger/
目录下生成。 在此地址上的过去日期:

并生成您想要的内容(首选技术中的服务器端或客户端API)