使用swagger2markup生成文档

package com.yangfan.core.config;

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 org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringRunner;

import java.net.URL;
import java.nio.file.Paths;

@RunWith(SpringRunner.class)
public class exportConfig {
    @Test
    public void generateAsciiDocs() throws Exception {
        //    输出Ascii格式
        Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
                .withMarkupLanguage(MarkupLanguage.ASCIIDOC)
                .withOutputLanguage(Language.ZH)
                .withPathsGroupedBy(GroupBy.TAGS)
                .withGeneratedExamples()
                .withoutInlineSchema()
                .build();

        Swagger2MarkupConverter.from(new URL("http://127.0.0.1:8089/yf/v2/api-docs"))
                .withConfig(config)
                .build()
                .toFolder(Paths.get("src/docs/asciidoc/generated/all"));
    }
}

 

多模块中随便放在任意模块,主要是url的路径是否正确,生成了adoc

使用swagger2markup生成文档_第1张图片


    
        
            io.github.swagger2markup
            swagger2markup-maven-plugin
            1.2.0
            
                
                http://localhost:8765/v2/api-docs?group=api
                src/docs/asciidoc/generated/all
                
                    
                    ASCIIDOC
                
            
        

        
            org.asciidoctor
            asciidoctor-maven-plugin
            1.5.3
            
            
                
                    org.asciidoctor
                    asciidoctorj-pdf
                    1.5.0-alpha.10.1
                
                
                    org.jruby
                    jruby-complete
                    1.7.21
                
            
            
            
                src/docs/asciidoc/generated/all
                coderay
                
                    left
                
            
            
            
                
                    output-html
                    generate-resources
                    
                        process-asciidoc
                    
                    
                        html5
                        src/docs/asciidoc/html
                    
                

                
                    output-pdf
                    generate-resources
                    
                        process-asciidoc
                    
                    
                        pdf
                        src/docs/asciidoc/pdf
                    
                

            
        
    

 

依次执行mvn指令:mvn asciidoctor:process-asciidoc 和 mvn generate-resources

 

生成文件如图:

使用swagger2markup生成文档_第2张图片

 

你可能感兴趣的:(java)