@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Bean
public Docket createRestApi() {
ParameterBuilder aParameterBuilder = new ParameterBuilder();
aParameterBuilder.name("X-Emp-Id").description("userId").modelRef(new ModelRef("int")).parameterType("header").required(true).build();
ParameterBuilder aParameterBuilder1 = new ParameterBuilder();
aParameterBuilder1.name("X-Emp-No").description("userCode").modelRef(new ModelRef("String")).parameterType("header").required(true).build();
List<Parameter> aParameters = new ArrayList<Parameter>();
aParameters.add(aParameterBuilder.build());
aParameters.add(aParameterBuilder1.build());
return new Docket(DocumentationType.SWAGGER_2)
.groupName("com.xx.xx")
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.xx.xx"))
.paths(PathSelectors.any())
.build()
.useDefaultResponseMessages(false)
.globalOperationParameters(aParameters);
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder()
.title("xxx")
.description("API文档")
.termsOfServiceUrl("https://xx.com.cn")
.version("1.0")
.build();
}
}