1. Maven 配置

    
        io.github.swagger2markup
        swagger2markup
        1.3.1
    

    
        nl.jworks.markdown_to_asciidoc
        markdown_to_asciidoc
        1.0
    

    
        org.pegdown
        pegdown
        1.6.0
        test
    

2. plugin 配置

  
        
            io.github.swagger2markup
            swagger2markup-maven-plugin
            1.2.0
            
                
                http://127.0.0.1:9092
                src/docs/asciidoc/generated
                
                    
                    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
                coderay
                
                    left
                
            
            
            
                
                    output-html
                    generate-resources
                    
                        process-asciidoc
                    
                    
                        html5
                        src/docs/asciidoc/html
                    
                

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

            
        

3.新建GneratorSwaggerPdfAndHtml --- UT

@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class GneratorSwaggerPdfAndHtml {
public void generateAsciiDocs() throws Exception {
// 输出Ascii格式
Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
.withMarkupLanguage(MarkupLanguage.ASCIIDOC)
.build();
Swagger2MarkupConverter.from(new URL("http://localhost:9092/v2/api-docs"))
.withConfig(config)
.build()
.toFolder(Paths.get("src/docs/asciidoc/generated"));
}
}

4. Swagger2AutoConfiguration 配置

本地 Swagger2AutoConfiguration类,继承WebMvcConfigurationSupport,并重写addResourceHandlers方法
@Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
       registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

5.编译命令生成PDF,Html

先执行命令mvn asciidoctor:process-asciidoc

Run 此UT,会生成Adoc文件。

然后执行 命令 mvn generate-resources 生成PDF和HTML