下面列出了org.springframework.boot.autoconfigure.SpringBootApplication#springfox.documentation.builders.PathSelectors 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 创建RestApi 并包扫描controller
* @return
*/
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
//分组名称
// .groupName("2.X版本")
.select()
// // 对所有api进行监控
// .apis(RequestHandlerSelectors.any())
.apis(RequestHandlerSelectors.basePackage(basePackage))
//不显示错误的接口地址
.paths(PathSelectors.any())
//错误路径不监控
.paths(Predicates.not(PathSelectors.regex("/error.*")))
// .build();
.build()
.securityContexts(Lists.newArrayList(securityContext())).securitySchemes(Lists.<SecurityScheme>newArrayList(apiKey()));
}
@Bean
public Docket weiXinApi() {
Parameter parameter = new ParameterBuilder()
.name("Authorization")
.description("token")
.modelRef(new ModelRef("string"))
.parameterType("header")
.required(false)
.defaultValue("token ")
.build();
return new Docket(DocumentationType.SWAGGER_2)
.groupName("微信API接口文档")
.globalOperationParameters(Collections.singletonList(parameter))
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.andy.pay.wx"))
.paths(PathSelectors.any())
.build();
}
@Bean
public Docket createRestApi() {
// 获取需要扫描的包
String[] basePackages = getBasePackages();
ApiSelectorBuilder apiSelectorBuilder = new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select();
// 如果扫描的包为空,则默认扫描类上有@Api注解的类
if (ArrayUtils.isEmpty(basePackages)) {
apiSelectorBuilder.apis(RequestHandlerSelectors.withClassAnnotation(Api.class));
} else {
// 扫描指定的包
apiSelectorBuilder.apis(basePackage(basePackages));
}
Docket docket = apiSelectorBuilder.paths(PathSelectors.any())
.build()
.enable(swaggerProperties.isEnable())
.ignoredParameterTypes(ignoredParameterTypes)
.globalOperationParameters(getParameters());
return docket;
}
@Bean
public Docket apiDocket() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(new ApiInfoBuilder()
.title("Certificate Generator")
.description("Certificate Generator for Testing Purposes of PSD2 Sandbox Environment")
.contact(new Contact(
"adorsys GmbH & Co. KG",
"https://adorsys.de",
"[email protected]"))
.version(buildProperties.getVersion() + " " + buildProperties.get("build.number"))
.build())
.groupName("Certificate Generator API")
.select()
.apis(RequestHandlerSelectors.basePackage("de.adorsys.psd2.sandbox.certificate"))
.paths(PathSelectors.any())
.build();
}
@Bean
public Docket apiDocklet() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(new ApiInfoBuilder()
.title("TPP backend application")
.description("TPP backend application of PSD2 Sandbox Environment")
.contact(new Contact(
"Adorsys GmbH & Co. KG",
"https://adorsys.de",
"[email protected]")
)
.version(buildProperties.getVersion() + " " + buildProperties.get("build.number"))
.build())
.groupName("TPP-API")
.select()
.apis(RequestHandlerSelectors
.basePackage("de.adorsys.psd2.sandbox.tpp.rest"))
.paths(PathSelectors.any())
.build()
.securitySchemes(singletonList(securitySchema()));
}
/**
* Will exposed on $HOST:$PORT/swagger-ui.html
*
* @return
*/
@Bean
public Docket apiDocumentation() {
return new Docket(SWAGGER_2)
.select()
.apis(basePackage("se.magnus.microservices.composite.product"))
.paths(PathSelectors.any())
.build()
.globalResponseMessage(POST, emptyList())
.globalResponseMessage(GET, emptyList())
.globalResponseMessage(DELETE, emptyList())
.apiInfo(new ApiInfo(
apiTitle,
apiDescription,
apiVersion,
apiTermsOfServiceUrl,
new Contact(apiContactName, apiContactUrl, apiContactEmail),
apiLicense,
apiLicenseUrl,
emptyList()
));
}
/**
* Will exposed on $HOST:$PORT/swagger-ui.html
*
* @return
*/
@Bean
public Docket apiDocumentation() {
return new Docket(SWAGGER_2)
.select()
.apis(basePackage("se.magnus.microservices.composite.product"))
.paths(PathSelectors.any())
.build()
.globalResponseMessage(POST, emptyList())
.globalResponseMessage(GET, emptyList())
.globalResponseMessage(DELETE, emptyList())
.apiInfo(new ApiInfo(
apiTitle,
apiDescription,
apiVersion,
apiTermsOfServiceUrl,
new Contact(apiContactName, apiContactUrl, apiContactEmail),
apiLicense,
apiLicenseUrl,
emptyList()
));
}
/**
* 动态产生Docket分组信息
*
* @return
*/
@Autowired
public void dynamicConfiguration() {
ConfigurableApplicationContext context = (ConfigurableApplicationContext) applicationContext;
DefaultListableBeanFactory beanFactory = (DefaultListableBeanFactory) context.getBeanFactory();
String systemName = "Microservice PaaS";
ApiInfoBuilder apiInfoBuilder = new ApiInfoBuilder()
.description("mPaas前端后端对应接口")
.version("1.0.1")
.license("Code Farmer Framework(iByte) Org.");
Map<String, ModuleMappingInfo> moduleInfo = mappingHelper.getMappingInfos();
for (Map.Entry<String, ModuleMappingInfo> entry : moduleInfo.entrySet()) {
beanFactory.registerSingleton(entry.getKey(), new Docket(DocumentationType.SWAGGER_2)
.groupName(entry.getKey())
.apiInfo(apiInfoBuilder.title(systemName + NamingConstant.DOT + entry.getKey()).build())
.select()
.apis(genSubPackage(entry.getKey()))
.paths(Predicates.or(PathSelectors.ant(NamingConstant.PATH_PREFIX_DATA + "/**"),
PathSelectors.ant(NamingConstant.PATH_PREFIX_API + "/**")))
.build());
}
}
/**
* 创建RestApi 并包扫描controller
* @return
*/
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
//分组名称
// .groupName("2.X版本")
.select()
// // 对所有api进行监控
// .apis(RequestHandlerSelectors.any())
.apis(RequestHandlerSelectors.basePackage(basePackage))
//不显示错误的接口地址
.paths(PathSelectors.any())
//错误路径不监控
.paths(Predicates.not(PathSelectors.regex("/error.*")))
// .build();
.build()
.securityContexts(Lists.newArrayList(securityContext())).securitySchemes(Lists.<SecurityScheme>newArrayList(apiKey()));
}
@Bean
@Autowired
public Docket complete(ServletContext servletContext) {
List<ResponseMessage> responseMessageList = newArrayList();
return new Docket(SWAGGER_2)
.pathProvider(new RelativePathProvider(servletContext) {
@Override
public String getApplicationBasePath() {
return "/dubbo";
}
})
.apiInfo(apiInfo())
.select()
.apis(ExtendRequestHandlerSelectors.dubboApi())
.paths(PathSelectors.any())
.build()
.groupName("dubbo")
.produces(Sets.newHashSet("application/json", "text/plain"))
.consumes(Collections.singleton("application/json"))
.useDefaultResponseMessages(false)
.globalResponseMessage(RequestMethod.GET, responseMessageList)
.globalResponseMessage(RequestMethod.POST, responseMessageList);
}
@Bean
public Docket createRestApi() {
ParameterBuilder tokenPar = new ParameterBuilder();
List<Parameter> pars = new ArrayList<Parameter>();
tokenPar.name("x-access-token").description("令牌").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
pars.add(tokenPar.build());
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.qianlq.core.controller"))
.paths(PathSelectors.any())
.build()
.globalOperationParameters(pars);
}
/**
* Will exposed on $HOST:$PORT/swagger-ui.html
*
* @return
*/
@Bean
public Docket apiDocumentation() {
return new Docket(SWAGGER_2)
.select()
.apis(basePackage("se.magnus.microservices.composite.product"))
.paths(PathSelectors.any())
.build()
.globalResponseMessage(POST, emptyList())
.globalResponseMessage(GET, emptyList())
.globalResponseMessage(DELETE, emptyList())
.apiInfo(new ApiInfo(
apiTitle,
apiDescription,
apiVersion,
apiTermsOfServiceUrl,
new Contact(apiContactName, apiContactUrl, apiContactEmail),
apiLicense,
apiLicenseUrl,
emptyList()
));
}
@Bean
public Docket createRestApi(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.neu.his.cloud.service.bms.controller"))
.paths(PathSelectors.any())
.build();
// .securitySchemes(securitySchemes())
// .securityContexts(securityContexts());
}
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.flowci.core"))
.paths(PathSelectors.any())
.build();
}
@Bean
public Docket createRestApi(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.neu.his.cloud.zuul.controller"))
.paths(PathSelectors.any())
.build()
.securitySchemes(securitySchemes())
.securityContexts(securityContexts());
}
@Bean
public Docket onrampSwagger() {
return new Docket(SWAGGER_2)
.groupName("onramp")
.securitySchemes(Collections.singletonList(new BasicAuth(BASIC_AUTH)))
.securityContexts(Collections.singletonList(securityContext()))
.apiInfo(new ApiInfoBuilder().title("Onramp").build())
.useDefaultResponseMessages(false)
.tags(new Tag("onramp", "Submit messages"))
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.regex("/onramp.*"))
.build();
}
@Bean
public Docket paverSwagger() {
return new Docket(SWAGGER_2)
.groupName("paver")
.securitySchemes(Collections.singletonList(new BasicAuth(BASIC_AUTH)))
.securityContexts(Collections.singletonList(securityContext()))
.apiInfo(new ApiInfoBuilder().title("Paver").build())
.useDefaultResponseMessages(false)
.tags(new Tag("road", "Administer roads"), new Tag("schema", "Administer schemas"))
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.regex("/paver.*"))
.build();
}
@Bean
public Docket documentation() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
.paths(PathSelectors.any())
.build();
}
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.produces(Sets.newHashSet("application/json"))
.consumes(Sets.newHashSet("application/json"))
.protocols(Sets.newHashSet("http", "https"))
.apiInfo(apiInfo())
.forCodeGeneration(true)
.select()
// 指定controller存放的目录路径
.apis(RequestHandlerSelectors.basePackage("com.xncoding.jwt.api"))
// .paths(PathSelectors.ant("/api/v1/*"))
.paths(PathSelectors.any())
.build();
}
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
.apis(RequestHandlerSelectors
.basePackage("com.yoke.poseidon.cart.web"))
.paths(PathSelectors.any()).build();
}
@Bean
public Docket createRestApi(){
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
//为当前包下controller生成API文档
.apis(RequestHandlerSelectors.basePackage("com.macro.mall.tiny.controller"))
//为有@Api注解的Controller生成API文档
// .apis(RequestHandlerSelectors.withClassAnnotation(Api.class))
//为有@ApiOperation注解的方法生成API文档
// .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.paths(PathSelectors.any())
.build();
}
/**
* 配置swagger基本信息
* - BasePackage
* 默认使用SpringBoot项目扫描bean根目录
* 如果存在配置时则使用SwaggerProperties.basePackage作为扫描根目录
*
* @return Docket实例
*/
@Bean
public Docket docket() {
String basePackage = swaggerProperties.getBasePackage();
if (StringUtils.isEmpty(basePackage)) {
basePackage = AutoConfigurationPackages.get(beanFactory).get(0);
}
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).securitySchemes(Collections.singletonList(apiKey())).securityContexts(Collections.singletonList(securityContext())).select().apis(RequestHandlerSelectors.basePackage(basePackage)).paths(PathSelectors.any()).build();
}
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("cn.icedsoul.groupservice"))
.paths(PathSelectors.any())
.build();
}
@Bean
public Docket customImplementation() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("org.yzh.web.controller"))
.paths(PathSelectors.any())
.build();
}
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.basePackage("com.tmobile.opensource.casquatch.examples.springrest"))
.paths(PathSelectors.any())
.build();
}
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.wu.parker"))
.paths(PathSelectors.any())
.build();
}
@Bean
public Docket api() {
ParameterBuilder tokenPar = new ParameterBuilder();
List<springfox.documentation.service.Parameter> pars = new ArrayList<springfox.documentation.service.Parameter>();
tokenPar.name("Authorization").description("令牌").modelRef(new ModelRef("string")).parameterType("header")
.required(false).build();
pars.add(tokenPar.build());
return new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class)).paths(PathSelectors.any())
.build().globalOperationParameters(pars);
}
@Bean
public Docket createRestApi() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.select()
.apis(RequestHandlerSelectors.basePackage("com.macro.mall.portal.controller"))
.paths(PathSelectors.any())
.build()
.securitySchemes(securitySchemes())
.securityContexts(securityContexts());
}
@Bean
public Docket documentation() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.withClassAnnotation(RestController.class))
.paths(PathSelectors.any())
.build();
}
@Bean
public Docket createRestApi() {
ParameterBuilder aParameterBuilder = new ParameterBuilder();
aParameterBuilder
.name("Authorization")
.description("Authorization")
.modelRef(new ModelRef("string"))
.parameterType("header")
.description("Bearer授权模式,'Bearer '开始")
.required(false)
.build()
;
List<Parameter> aParameters = new ArrayList<>();
aParameters.add(aParameterBuilder.build());
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(apiInfo())
.ignoredParameterTypes(Principal.class)
.ignoredParameterTypes(JwtAuthenticationToken.class)
// .globalOperationParameters(aParameters)
.select()
.apis(RequestHandlerSelectors.basePackage("com.revengemission.sso.oauth2.resource.coupon.controller"))
.paths(PathSelectors.any())
.build()
.securitySchemes(securitySchemes())
.securityContexts(securityContexts());
}