Создайте файл Yaml или Json из документации Swagger.

У меня есть разработка веб-службы Rest, задокументированной swagger, с использованием аннотаций swagger-springmvc. Теперь я хочу использовать swagger-editor для создания кода веб-службы Rest на стороне клиента, но для swagger-editor требуется файл Yaml или Json. Вы знаете, есть ли способ создать этот файл? заранее спасибо

EDIT: это можно сделать с помощью swagger-mvn-plugin , но я не нашел примера того, как это сделать?


person MK-rou    schedule 17.12.2015    source источник


Ответы (1)


Отвечаю сам себе :). Вы можете создавать документацию на стороне клиента и сервера (yaml, json и html), используя swagger-maven-plugin< /а>

Добавьте это в свой 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>[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 по этому адресу: https://github.com/kongchen/swagger-maven-example

Документация Execute mvn swagger:generate Json будет сгенерирована в каталоге вашего проекта /generated/swagger/. Вставьте его по этому адресу: http://editor.swagger.io

И генерируйте то, что хотите (серверный или клиентский API в предпочитаемой вами технологии)

person MK-rou    schedule 06.01.2016