配置類
@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線上工具