springfox.documentation.RequestHandler Java Examples
The following examples show how to use
springfox.documentation.RequestHandler.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SmartSwaggerDynamicGroupConfig.java From smart-admin with MIT License | 6 votes |
private Docket baseDocket() { // 请求类型过滤规则 Predicate<RequestHandler> controllerPredicate = getControllerPredicate(); // controller 包路径 Predicate<RequestHandler> controllerPackage = RequestHandlerSelectors.basePackage(packAge); return new Docket(DocumentationType.SWAGGER_2) .groupName(groupName) .forCodeGeneration(true) .select() .apis(controllerPackage) .apis(controllerPredicate) .paths(PathSelectors.any()) .build() .apiInfo(this.serviceApiInfo()) .securitySchemes(securitySchemes()) .securityContexts(securityContexts()); }
Example #2
Source File: SmartSwaggerDynamicGroupConfig.java From smart-admin with MIT License | 6 votes |
private Predicate<RequestHandler> getControllerPredicate() { groupName = groupList.get(groupIndex); List<String> apiTags = groupMap.get(groupName); Predicate<RequestHandler> methodPredicate = (input) -> { Api api = null; Optional<Api> apiOptional = input.findControllerAnnotation(Api.class); if (apiOptional.isPresent()) { api = apiOptional.get(); } List<String> tags = Arrays.asList(api.tags()); if (api != null && apiTags.containsAll(tags)) { return true; } return false; }; groupIndex++; return Predicates.and(RequestHandlerSelectors.withClassAnnotation(RestController.class), methodPredicate); }
Example #3
Source File: ScanPluginAsGroupSwaggerConfig.java From onetwo with Apache License 2.0 | 6 votes |
final protected void registerDocketsByWebApiAnnotation(int index, String appName, Class<?> rootClass) { Collection<Predicate<RequestHandler>> predicates = createPackagePredicateByClass(rootClass); logger.info("register docket for rootClass: {}", rootClass); // Docket docket = createDocket(index+".1 ["+appName+"]外部接口", appName, Arrays.asList(webApi(predicates))); String docketBeanName = appName+"Docket"; logger.info("docket[{}] created...", docketBeanName); this.registerDocketIfNotExist(docketBeanName, index+".1 ["+appName+"]外部接口", appName, Arrays.asList(webApi(predicates))); /*if (!applicationContext.containsBeanDefinition(docketBeanName)) { SpringUtils.registerAndInitSingleton(applicationContext, docketBeanName, docket); logger.info("docket[{}] registered", docketBeanName); } else { logger.info("docket[{}] ignored", docketBeanName); }*/ docketBeanName = appName+"InnerDocket"; logger.info("docket[{}] created...", docketBeanName); this.registerDocketIfNotExist(docketBeanName, index+".2 ["+appName+"]内部接口", appName, Arrays.asList(notWebApi(predicates))); /*Docket innerDocket = createDocket(index+".2 ["+appName+"]内部接口", appName, Arrays.asList(notWebApi(predicates))); if (!applicationContext.containsBeanDefinition(docketBeanName)) { SpringUtils.registerAndInitSingleton(applicationContext, docketBeanName, innerDocket); logger.info("docket[{}] registered", docketBeanName); } else { logger.info("docket[{}] ignored", docketBeanName); }*/ }
Example #4
Source File: AbstractSwaggerConfig.java From onetwo with Apache License 2.0 | 6 votes |
protected Docket createDocket(String groupName, String applicationName, Collection<Predicate<RequestHandler>> packages){ Docket docket = new Docket(DocumentationType.SWAGGER_2) .ignoredParameterTypes(ApiIgnore.class) .groupName(groupName) .alternateTypeRules( AlternateTypeRules.newRule( typeResolver.resolve(DeferredResult.class, typeResolver.resolve(ResponseEntity.class, WildcardType.class)), typeResolver.resolve(WildcardType.class) ) ) // .pathProvider(pathProvider) .select() .apis(Predicates.or(packages)) .paths(PathSelectors.any()) .build() .globalOperationParameters(createGlobalParameters()) .apiInfo(apiInfo(applicationName)); addGlobalResponseMessages(docket); return docket; }
Example #5
Source File: PageableParameterBuilderPluginTest.java From jhipster with Apache License 2.0 | 6 votes |
@BeforeEach public void setup() throws Exception { MockitoAnnotations.initMocks(this); Method method = this.getClass().getMethod("test", new Class<?>[]{Pageable.class, Integer.class}); resolver = new TypeResolver(); RequestHandler handler = new WebMvcRequestHandler(new HandlerMethodResolver(resolver), null, new HandlerMethod(this, method)); DocumentationContext docContext = mock(DocumentationContext.class); RequestMappingContext reqContext = new RequestMappingContext(docContext, handler); builder = spy(new OperationBuilder(null)); context = new OperationContext(builder, RequestMethod.GET, reqContext, 0); List<TypeNameProviderPlugin> plugins = new LinkedList<>(); extractor = new TypeNameExtractor(resolver, SimplePluginRegistry.create(plugins), new JacksonEnumTypeDeterminer()); plugin = new PageableParameterBuilderPlugin(extractor, resolver); }
Example #6
Source File: SwaggerConfig.java From metasfresh-webui-api-legacy with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("unused") private static final Predicate<RequestHandler> basePackages(final Class<?>... classes) { final Set<Predicate<RequestHandler>> predicates = new HashSet<>(classes.length); for (final Class<?> clazz : classes) { final String packageName = clazz.getPackage().getName(); predicates.add(RequestHandlerSelectors.basePackage(packageName)); } if(predicates.size() == 1) { return predicates.iterator().next(); } return Predicates.or(predicates); }
Example #7
Source File: AutoScanPluginSwaggerConfig.java From onetwo with Apache License 2.0 | 5 votes |
protected Docket createDocket(Set<Predicate<RequestHandler>> packages){ Docket docket = new Docket(DocumentationType.SWAGGER_2) .ignoredParameterTypes(ApiIgnore.class) // .pathProvider(pathProvider) .select() .apis(Predicates.or(packages)) .paths(PathSelectors.any()) .build() .apiInfo(apiInfo(getServiceName())); return docket; }
Example #8
Source File: Swagger2Configuration.java From AthenaServing with Apache License 2.0 | 5 votes |
@Bean public Docket createRestApi() { Predicate<RequestHandler> predicate = new Predicate<RequestHandler>() { @Override public boolean apply(RequestHandler input) { if (input.isAnnotatedWith(ApiOperation.class))// 只有添加了ApiOperation注解的method才在API中显示 return true; return false; } }; return new Docket(DocumentationType.SWAGGER_2).// apiInfo(apiInfo()).select().// apis(predicate).// paths(PathSelectors.any()).build(); }
Example #9
Source File: AutoScanPluginSwaggerConfig.java From onetwo with Apache License 2.0 | 5 votes |
protected Set<Predicate<RequestHandler>> getAllApiDocPackages(){ Set<Predicate<RequestHandler>> packages = Sets.newHashSet(); packages.addAll(getPluginBasePackages()); String scanPackageName = getScanPackageName();//ClassUtils.getPackageName(ServiceApplication.class); if(StringUtils.isNotBlank(scanPackageName)){ packages.add(RequestHandlerSelectors.basePackage(scanPackageName)); } return packages; }
Example #10
Source File: AutoScanPluginSwaggerConfig.java From onetwo with Apache License 2.0 | 5 votes |
protected Set<Predicate<RequestHandler>> getPluginBasePackages(){ if(pluginManager!=null){ return pluginManager.getPlugins() .stream() .map(p->RequestHandlerSelectors.basePackage(ClassUtils.getPackageName(p.getRootClass()))) .collect(Collectors.toSet()); } return Collections.emptySet(); }
Example #11
Source File: ScanPluginAsGroupSwaggerConfig.java From onetwo with Apache License 2.0 | 5 votes |
protected void registerDocketIfNotExist(String docketBeanName, String groupName, String appName, Collection<Predicate<RequestHandler>> packages) { Docket innerDocket = createDocket(groupName, appName, packages); if (!applicationContext.containsBeanDefinition(docketBeanName)) { SpringUtils.registerAndInitSingleton(applicationContext, docketBeanName, innerDocket); logger.info("docket[{}] registered", docketBeanName); } else { logger.info("docket[{}] ignored", docketBeanName); } }
Example #12
Source File: ScanPluginAsGroupSwaggerConfig.java From onetwo with Apache License 2.0 | 5 votes |
final protected Collection<Predicate<RequestHandler>> createPackagePredicate(String... packNames) { return Stream.of(packNames) .map(packName -> { return RequestHandlerSelectors.basePackage(packName); }) .collect(Collectors.toSet()); }
Example #13
Source File: ScanPluginAsGroupSwaggerConfig.java From onetwo with Apache License 2.0 | 5 votes |
final protected Collection<Predicate<RequestHandler>> createPackagePredicateByClass(Class<?>... rootClass) { return Stream.of(rootClass) .map(c -> { return RequestHandlerSelectors.basePackage(ClassUtils.getPackageName(c)); }) .collect(Collectors.toSet()); }
Example #14
Source File: AbstractSwaggerConfig.java From onetwo with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") protected Predicate<RequestHandler> notWebApi(Collection<Predicate<RequestHandler>> packages){ return rh->{ return Predicates.or(packages).apply(rh) && !WebApiRequestMappingCombiner.findWebApiAttrs(rh.getHandlerMethod().getMethod(), rh.declaringClass()) .isPresent(); }; }
Example #15
Source File: AbstractSwaggerConfig.java From onetwo with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") protected Predicate<RequestHandler> webApi(Collection<Predicate<RequestHandler>> packages){ return rh->{ return Predicates.or(packages).apply(rh) && WebApiRequestMappingCombiner.findWebApiAttrs(rh.getHandlerMethod().getMethod(), rh.declaringClass()) .isPresent(); }; }
Example #16
Source File: SwaggerConfig.java From fileServer with Apache License 2.0 | 5 votes |
@Bean public Docket createRestApi() { Predicate<RequestHandler> predicate = new Predicate<RequestHandler>() { @Override public boolean apply(RequestHandler input) { Class<?> declaringClass = input.declaringClass(); boolean isController = declaringClass.isAnnotationPresent(Controller.class); boolean isRestController = declaringClass.isAnnotationPresent(RestController.class); String className = declaringClass.getName(); String pattern = "com\\.codingapi\\.file\\.local\\.server\\.controller\\..*Controller"; boolean has = Pattern.matches(pattern, className); if(has){ if(isController){ if(input.isAnnotatedWith(ResponseBody.class)){ return true; } } if(isRestController){ return true; } return false; } return false; } }; return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .useDefaultResponseMessages(false) .select() .apis(predicate) .build(); }
Example #17
Source File: SwaggerConfig.java From fileServer with Apache License 2.0 | 5 votes |
@Bean public Docket createRestApi() { Predicate<RequestHandler> predicate = new Predicate<RequestHandler>() { @Override public boolean apply(RequestHandler input) { Class<?> declaringClass = input.declaringClass(); boolean isController = declaringClass.isAnnotationPresent(Controller.class); boolean isRestController = declaringClass.isAnnotationPresent(RestController.class); String className = declaringClass.getName(); String pattern = "com\\.codingapi\\.file\\.fastdfs\\.server\\.controller\\..*Controller"; boolean has = Pattern.matches(pattern, className); if(has){ if(isController){ if(input.isAnnotatedWith(ResponseBody.class)){ return true; } } if(isRestController){ return true; } return false; } return false; } }; return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .useDefaultResponseMessages(false) .select() .apis(predicate) .build(); }
Example #18
Source File: Knife4jController.java From yshopmall with Apache License 2.0 | 5 votes |
private Function<RequestHandlerProvider, ? extends Iterable<RequestHandler>> handlers() { return new Function<RequestHandlerProvider, Iterable<RequestHandler>>() { @Override public Iterable<RequestHandler> apply(RequestHandlerProvider input) { return input.requestHandlers(); } }; }
Example #19
Source File: ApiRequestHandlerProvider.java From swagger-more with Apache License 2.0 | 5 votes |
@Override public List<RequestHandler> requestHandlers() { return byPatternsCondition().sortedCopy(nullToEmptyList(serviceBeans).stream() .filter(bean -> AnnotatedElementUtils.hasAnnotation(bean.getInterfaceClass(), Api.class)) .reduce(newArrayList(), toMappingEntries(), (o1, o2) -> o1) .stream().map(toRequestHandler()).collect(Collectors.toList())); }
Example #20
Source File: SwaggerUtil.java From blade-tool with GNU Lesser General Public License v3.0 | 4 votes |
private static Optional<? extends Class<?>> declaringClass(RequestHandler input) { return Optional.fromNullable(input.declaringClass()); }
Example #21
Source File: AutoScanPluginSwaggerConfig.java From onetwo with Apache License 2.0 | 4 votes |
@Bean public Docket api(){ Set<Predicate<RequestHandler>> packages = getAllApiDocPackages(); Docket docket = createDocket(packages); return docket; }
Example #22
Source File: AutoScanPluginSwaggerConfig.java From onetwo with Apache License 2.0 | 4 votes |
protected Predicate<RequestHandler> notWebApi(){ Set<Predicate<RequestHandler>> packages = getAllApiDocPackages(); return notWebApi(packages); }
Example #23
Source File: AutoScanPluginSwaggerConfig.java From onetwo with Apache License 2.0 | 4 votes |
protected Predicate<RequestHandler> webApi(){ Set<Predicate<RequestHandler>> packages = getAllApiDocPackages(); return webApi(packages); }
Example #24
Source File: SwaggerConfig.java From spring-security with Apache License 2.0 | 4 votes |
private static Optional<? extends Class<?>> declaringClass(RequestHandler input) { return Optional.fromNullable(input.declaringClass()); }
Example #25
Source File: ApiRequestHandlerProvider.java From swagger-more with Apache License 2.0 | 4 votes |
private Function<HandlerMethod, RequestHandler> toRequestHandler() { return handlerMethod -> new ApiRequestHandler(methodResolver, handlerMethod, allAsRequestBody(handlerMethod) ? annotateBody(handlerMethod) : methodResolver.methodParameters(handlerMethod)); }
Example #26
Source File: ApiRequestHandler.java From swagger-more with Apache License 2.0 | 4 votes |
@Override public RequestHandler combine(RequestHandler other) { return other; }
Example #27
Source File: ExtendRequestHandlerSelectors.java From swagger-more with Apache License 2.0 | 4 votes |
public static Predicate<RequestHandler> dubboApi() { return input -> input instanceof ApiRequestHandler; }
Example #28
Source File: Swagger2Config.java From spring-boot-plus with Apache License 2.0 | 4 votes |
public static Predicate<RequestHandler> basePackage(final String[] basePackages) { return input -> declaringClass(input).transform(handlerPackage(basePackages)).or(true); }
Example #29
Source File: Swagger2Config.java From spring-boot-plus with Apache License 2.0 | 4 votes |
@SuppressWarnings("deprecation") private static Optional<? extends Class<?>> declaringClass(RequestHandler input) { return Optional.fromNullable(input.declaringClass()); }
Example #30
Source File: Knife4jController.java From yshopmall with Apache License 2.0 | 4 votes |
private void initGlobalRequestMappingArray(SwaggerExt swaggerExt) { if (this.globalHandlerMappings.size() == 0) { String parentPath = ""; if (!StringUtils.isEmpty(swaggerExt.getBasePath()) && !"/".equals(swaggerExt.getBasePath())) { parentPath = parentPath + swaggerExt.getBasePath(); } try { List<RequestHandler> requestHandlers = FluentIterable.from(this.handlerProviders).transformAndConcat(this.handlers()).toList(); Iterator<RequestHandler> var4 = requestHandlers.iterator(); while(true) { RequestHandler requestHandler; do { if (!var4.hasNext()) { return; } requestHandler = var4.next(); } while(!(requestHandler instanceof WebMvcRequestHandler)); WebMvcRequestHandler webMvcRequestHandler = (WebMvcRequestHandler)requestHandler; Set<String> patterns = webMvcRequestHandler.getRequestMapping().getPatternsCondition().getPatterns(); Set<RequestMethod> restMethods = webMvcRequestHandler.getRequestMapping().getMethodsCondition().getMethods(); HandlerMethod handlerMethod = webMvcRequestHandler.getHandlerMethod(); Class<?> controllerClazz = ClassUtils.getUserClass(handlerMethod.getBeanType()); Method method = ClassUtils.getMostSpecificMethod(handlerMethod.getMethod(), controllerClazz); String url; for(Iterator<String> var12 = patterns.iterator(); var12.hasNext(); this.globalHandlerMappings.add(new RestHandlerMapping(parentPath + url, controllerClazz, method, restMethods))) { url = var12.next(); if (LOGGER.isDebugEnabled()) { LOGGER.debug("url:" + url + "\r\nclass:" + controllerClazz.toString() + "\r\nmethod:" + method.toString()); } } } } catch (Exception var14) { LOGGER.error(var14.getMessage(), var14); } } }