Browse Source

swagger静态文档

Progr1mmer 6 years ago
parent
commit
114fe506fb

+ 14 - 1
pom.xml

@ -42,9 +42,11 @@
        <version.fastdfs>1.27</version.fastdfs>
        <version.swagger>2.7.0</version.swagger>
        <version.swagger-ui>2.7.0</version.swagger-ui>
        <version.swagger2markup>1.3.2</version.swagger2markup>
        <version.springfox-staticdocs>2.6.1</version.springfox-staticdocs>
        <version.mysql>5.1.45</version.mysql>
        <version.commons-dbcp2>2.1.1</version.commons-dbcp2>
        <version.commons-lang3>3.2.1</version.commons-lang3>
        <version.commons-lang3>3.4</version.commons-lang3>
        <version.commons.collections>3.2.1</version.commons.collections>
        <version.hibernate>5.0.12.Final</version.hibernate>
        <version.hibernate-validator>6.0.10.Final</version.hibernate-validator>
@ -60,6 +62,7 @@
        <version.json>20160212</version.json>
        <version.json-lib>2.4</version.json-lib>
        <version.pinyin4j>2.5.0</version.pinyin4j>
    </properties>
    <dependencyManagement>
@ -82,6 +85,16 @@
                <artifactId>springfox-swagger-ui</artifactId>
                <version>${version.swagger-ui}</version>
            </dependency>
            <dependency>
                <groupId>io.springfox</groupId>
                <artifactId>springfox-staticdocs</artifactId>
                <version>${version.springfox-staticdocs}</version>
            </dependency>
            <dependency>
                <groupId>io.github.swagger2markup</groupId>
                <artifactId>swagger2markup</artifactId>
                <version>${version.swagger2markup}</version>
            </dependency>
            <!-- Mysql library -->
            <dependency>

+ 8 - 0
swagger-starter/pom.xml

@ -20,5 +20,13 @@
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-staticdocs</artifactId>
        </dependency>
        <dependency>
            <groupId>io.github.swagger2markup</groupId>
            <artifactId>swagger2markup</artifactId>
        </dependency>
    </dependencies>
</project>

+ 46 - 0
swagger-starter/src/main/java/com/yihu/swagger/SwaggerDocsExample.java

@ -0,0 +1,46 @@
package com.yihu.swagger;
import io.github.swagger2markup.GroupBy;
import io.github.swagger2markup.Language;
import io.github.swagger2markup.Swagger2MarkupConfig;
import io.github.swagger2markup.Swagger2MarkupConverter;
import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder;
import io.github.swagger2markup.markup.builder.MarkupLanguage;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
/**
 * Swagger-ui静态文档生示例
 * 1.启动服务
 * 2.运行此main方法
 * 3.编译项目
 * Created by progr1mmer on 2018/8/21.
 *
 */
public class SwaggerDocsExample {
    public static void main(String[] args) throws Exception {
        //1.请求 http://ip:port/swagger-resources获取group
        String group = "Default";
        //2.定义请求地址 new URL("http://ip:port/v2/api-docs?group=" + groupName)
        URL remoteSwaggerFile = new URL("http://127.0.0.1:10020/v2/api-docs?group=" + group);
        //3.定义文件输出路径 Paths.get("svr/svr-base/build/" + group)
        Path outputFile = Paths.get("svr/svr-base/build/" + group); //文档输出地址
        Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
                .withMarkupLanguage(MarkupLanguage.ASCIIDOC)
                .withOutputLanguage(Language.ZH)
                .withPathsGroupedBy(GroupBy.TAGS)
                .withGeneratedExamples()
                .withoutInlineSchema()
                //.withBasePathPrefix()
                .build();
        Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(remoteSwaggerFile)
                .withConfig(config)
                .build();
        converter.toFile(outputFile);
    }
}