注意:DocumentationType.SWAGGER_12和 DocumentationType.SWAGGER_2 情况下HttpServletResponse流输出会变成乱码。
@EnableKnife4j
@EnableSwagger2
@Configuration
@Import(BeanValidatorPluginsConfiguration.class)
public class SwaggerConfigurer {
@Value("${swagger-ui.enabled:true}")
private boolean isOpen;
@Bean
public Docket createCommonApi() {
return new Docket(DocumentationType.OAS_30)
.enable(isOpen)
.apiInfo(apiInfo())
.protocols(new HashSet<>(Arrays.asList("https", "http")))
.select()
.apis(RequestHandlerSelectors.basePackage("com.xx.controller"))
.paths(PathSelectors.any())
.build().groupName("ALL-API");
}
public ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("xx技术系统-对外API文档")
.description("接口文档")
.termsOfServiceUrl("https://localhost:8087/xx/doc.html")
.contact(new Contact("xx技术有限公司", "https://www.xx.com", "xx@qq.com"))
.version("1.0.0")
.build();
}
}
当DocumentationType.OAS_30的时候,HttpServletResponse 输出就正常了。