swagger2生成接口文档,word

配置类

@Configuration
@EnableSwagger2
public class SwaggerConfig implements WebMvcConfigurer {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //加了ApiOperation注解的类,才生成接口文档
//                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                //包下的类,才生成接口文档
                .apis(RequestHandlerSelectors.basePackage("com.xxx.controller"))
                .paths(PathSelectors.any())
                .build()
                .securitySchemes(security());
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("XXXX")
                .description(""接口文档")
                .termsOfServiceUrl(""")
                .version("1.0.0")
                .build();
    }

    private List<ApiKey> security() {
        return newArrayList(
                new ApiKey("token", "token", "header")
        );
    }

}

浏览器访问:

http://ip:port/项目名/v2/api-docs

在线工具将json解析到word内

在线swagger转word文档|swagger导出word文档 - Kalvin在线工具

猜你喜欢

转载自blog.csdn.net/weiqiang915/article/details/128957374