annotation = getAnnotation(superClass, annotationClass); annotation = getAnnotation(anInterface, annotationClass); if (annotation != null) { return annotation;
protected boolean isOperationHidden(Method method) { io.swagger.v3.oas.annotations.Operation apiOperation = ReflectionUtils.getAnnotation(method, io.swagger.v3.oas.annotations.Operation.class); if (apiOperation != null && apiOperation.hidden()) { return true; } Hidden hidden = method.getAnnotation(Hidden.class); if (hidden != null) { return true; } if (config != null && !Boolean.TRUE.equals(config.isReadAllResources()) && apiOperation == null) { return true; } return false; }
/** * Returns an annotation by type from a method. * * @param method is the method to find * @param annotationClass is the type of annotation * @param <A> is the type of annotation * @return annotation if it is found */ public static <A extends Annotation> A getAnnotation(Method method, Class<A> annotationClass) { A annotation = method.getAnnotation(annotationClass); if (annotation == null) { for (Annotation metaAnnotation : method.getAnnotations()) { annotation = metaAnnotation.annotationType().getAnnotation(annotationClass); if (annotation != null) { return annotation; } } Method superclassMethod = getOverriddenMethod(method); if (superclassMethod != null) { annotation = getAnnotation(superclassMethod, annotationClass); } } return annotation; }
@Test public void getAnnotationTest() throws NoSuchMethodException { final Method method = Child.class.getMethod("annotationHolder"); Assert.assertNotNull(ReflectionUtils.getAnnotation(method, Schema.class)); Assert.assertNull(ReflectionUtils.getAnnotation(method, ApiResponse.class)); }
@Test public void testDerivedAnnotation() { final Path annotation = ReflectionUtils.getAnnotation(Child.class, javax.ws.rs.Path.class); Assert.assertNotNull(annotation); Assert.assertEquals(annotation.value(), "parentInterfacePath"); }
final javax.ws.rs.Path apiPath = ReflectionUtils.getAnnotation(cls, javax.ws.rs.Path.class); ExternalDocumentation apiExternalDocs = ReflectionUtils.getAnnotation(cls, ExternalDocumentation.class); io.swagger.v3.oas.annotations.tags.Tag[] apiTags = ReflectionUtils.getRepeatableAnnotationsArray(cls, io.swagger.v3.oas.annotations.tags.Tag.class); io.swagger.v3.oas.annotations.servers.Server[] apiServers = ReflectionUtils.getRepeatableAnnotationsArray(cls, io.swagger.v3.oas.annotations.servers.Server.class); javax.ws.rs.Consumes classConsumes = ReflectionUtils.getAnnotation(cls, javax.ws.rs.Consumes.class); javax.ws.rs.Produces classProduces = ReflectionUtils.getAnnotation(cls, javax.ws.rs.Produces.class); OpenAPIDefinition openAPIDefinition = ReflectionUtils.getAnnotation(cls, OpenAPIDefinition.class); javax.ws.rs.Produces methodProduces = ReflectionUtils.getAnnotation(method, javax.ws.rs.Produces.class); javax.ws.rs.Consumes methodConsumes = ReflectionUtils.getAnnotation(method, javax.ws.rs.Consumes.class); javax.ws.rs.Path methodPath = ReflectionUtils.getAnnotation(method, javax.ws.rs.Path.class); io.swagger.v3.oas.annotations.Operation apiOperation = ReflectionUtils.getAnnotation(method, io.swagger.v3.oas.annotations.Operation.class); JsonView jsonViewAnnotation; JsonView jsonViewAnnotationForRequestBody; jsonViewAnnotationForRequestBody = null; } else { jsonViewAnnotation = ReflectionUtils.getAnnotation(method, JsonView.class); io.swagger.v3.oas.annotations.Operation apiOperation = ReflectionUtils.getAnnotation(method, io.swagger.v3.oas.annotations.Operation.class); List<io.swagger.v3.oas.annotations.responses.ApiResponse> apiResponses = ReflectionUtils.getRepeatableAnnotations(method, io.swagger.v3.oas.annotations.responses.ApiResponse.class); io.swagger.v3.oas.annotations.parameters.RequestBody apiRequestBody = ReflectionUtils.getAnnotation(method, io.swagger.v3.oas.annotations.parameters.RequestBody.class);
annotation = getAnnotation(superClass, annotationClass); annotation = getAnnotation(anInterface, annotationClass); if (annotation != null) { return annotation;
protected boolean isOperationHidden(Method method) { io.swagger.v3.oas.annotations.Operation apiOperation = ReflectionUtils.getAnnotation(method, io.swagger.v3.oas.annotations.Operation.class); if (apiOperation != null && apiOperation.hidden()) { return true; } Hidden hidden = method.getAnnotation(Hidden.class); if (hidden != null) { return true; } if (config != null && !Boolean.TRUE.equals(config.isReadAllResources()) && apiOperation == null) { return true; } return false; }
/** * Returns an annotation by type from a method. * * @param method is the method to find * @param annotationClass is the type of annotation * @param <A> is the type of annotation * @return annotation if it is found */ public static <A extends Annotation> A getAnnotation(Method method, Class<A> annotationClass) { A annotation = method.getAnnotation(annotationClass); if (annotation == null) { for (Annotation metaAnnotation : method.getAnnotations()) { annotation = metaAnnotation.annotationType().getAnnotation(annotationClass); if (annotation != null) { return annotation; } } Method superclassMethod = getOverriddenMethod(method); if (superclassMethod != null) { annotation = getAnnotation(superclassMethod, annotationClass); } } return annotation; }
protected boolean isOperationHidden(Method method) { io.swagger.v3.oas.annotations.Operation apiOperation = ReflectionUtils.getAnnotation(method, io.swagger.v3.oas.annotations.Operation.class); if (apiOperation != null && apiOperation.hidden()) { return true; } Hidden hidden = method.getAnnotation(Hidden.class); if (hidden != null) { return true; } if (config != null && !Boolean.TRUE.equals(config.isReadAllResources()) && apiOperation == null) { return true; } return false; }
Consumes methodConsumes = ReflectionUtils.getAnnotation(method, Consumes.class); Consumes classConsumes = ReflectionUtils.getAnnotation(method.getDeclaringClass(), Consumes.class); JsonView jsonViewAnnotation = ReflectionUtils.getAnnotation(method, JsonView.class);
methodProduces = ReflectionUtils.getAnnotation(method, Produces.class); classProduces = ReflectionUtils.getAnnotation(method.getDeclaringClass(), Produces.class);
static void processFormParam(Parameter formParameter, Operation operation, MethodDoc methodDoc, Components components) { Option<Method> methodOpt = ReflectionKit.loadMethod(methodDoc); if (methodOpt.isDefined()) { Method method = methodOpt.get(); Consumes methodConsumes = ReflectionUtils.getAnnotation(method, Consumes.class); Consumes classConsumes = ReflectionUtils.getAnnotation(method.getDeclaringClass(), Consumes.class); RequestBody requestBody = operation.getRequestBody() != null ? operation.getRequestBody() : new RequestBody(); requestBody.description(formParameter.getDescription()); if (!Strings.isNullOrEmpty(formParameter.getDescription())) { requestBody.setDescription(formParameter.getDescription()); } Content content = processContent(requestBody.getContent(), formParameter.getSchema(), methodConsumes, classConsumes, true); requestBody.setContent(content); setRequestBodyExamples(formParameter, requestBody); operation.setRequestBody(requestBody); } }
final javax.ws.rs.Path apiPath = ReflectionUtils.getAnnotation(cls, javax.ws.rs.Path.class); ExternalDocumentation apiExternalDocs = ReflectionUtils.getAnnotation(cls, ExternalDocumentation.class); io.swagger.v3.oas.annotations.tags.Tag[] apiTags = ReflectionUtils.getRepeatableAnnotationsArray(cls, io.swagger.v3.oas.annotations.tags.Tag.class); io.swagger.v3.oas.annotations.servers.Server[] apiServers = ReflectionUtils.getRepeatableAnnotationsArray(cls, io.swagger.v3.oas.annotations.servers.Server.class); javax.ws.rs.Consumes classConsumes = ReflectionUtils.getAnnotation(cls, javax.ws.rs.Consumes.class); javax.ws.rs.Produces classProduces = ReflectionUtils.getAnnotation(cls, javax.ws.rs.Produces.class); OpenAPIDefinition openAPIDefinition = ReflectionUtils.getAnnotation(cls, OpenAPIDefinition.class); javax.ws.rs.Produces methodProduces = ReflectionUtils.getAnnotation(method, javax.ws.rs.Produces.class); javax.ws.rs.Consumes methodConsumes = ReflectionUtils.getAnnotation(method, javax.ws.rs.Consumes.class); javax.ws.rs.Path methodPath = ReflectionUtils.getAnnotation(method, javax.ws.rs.Path.class); io.swagger.v3.oas.annotations.Operation apiOperation = ReflectionUtils.getAnnotation(method, io.swagger.v3.oas.annotations.Operation.class); JsonView jsonViewAnnotation; JsonView jsonViewAnnotationForRequestBody; jsonViewAnnotationForRequestBody = null; } else { jsonViewAnnotation = ReflectionUtils.getAnnotation(method, JsonView.class); io.swagger.v3.oas.annotations.Operation apiOperation = ReflectionUtils.getAnnotation(method, io.swagger.v3.oas.annotations.Operation.class); List<io.swagger.v3.oas.annotations.responses.ApiResponse> apiResponses = ReflectionUtils.getRepeatableAnnotations(method, io.swagger.v3.oas.annotations.responses.ApiResponse.class); io.swagger.v3.oas.annotations.parameters.RequestBody apiRequestBody = ReflectionUtils.getAnnotation(method, io.swagger.v3.oas.annotations.parameters.RequestBody.class);
final javax.ws.rs.Path apiPath = ReflectionUtils.getAnnotation(cls, javax.ws.rs.Path.class); .getRepeatableAnnotations(cls, io.swagger.v3.oas.annotations.security.SecurityRequirement.class); ExternalDocumentation apiExternalDocs = ReflectionUtils.getAnnotation(cls, ExternalDocumentation.class); io.swagger.v3.oas.annotations.tags.Tag[] apiTags = ReflectionUtils.getRepeatableAnnotationsArray(cls, io.swagger.v3.oas.annotations.tags.Tag.class); io.swagger.v3.oas.annotations.servers.Server[] apiServers = ReflectionUtils.getRepeatableAnnotationsArray(cls, io.swagger.v3.oas.annotations.servers.Server.class); javax.ws.rs.Consumes classConsumes = ReflectionUtils.getAnnotation(cls, javax.ws.rs.Consumes.class); javax.ws.rs.Produces classProduces = ReflectionUtils.getAnnotation(cls, javax.ws.rs.Produces.class); OpenAPIDefinition openAPIDefinition = ReflectionUtils.getAnnotation(cls, OpenAPIDefinition.class); javax.ws.rs.Produces methodProduces = ReflectionUtils.getAnnotation(method, javax.ws.rs.Produces.class); javax.ws.rs.Consumes methodConsumes = ReflectionUtils.getAnnotation(method, javax.ws.rs.Consumes.class); javax.ws.rs.Path methodPath = ReflectionUtils.getAnnotation(method, javax.ws.rs.Path.class); io.swagger.v3.oas.annotations.Operation apiOperation = ReflectionUtils.getAnnotation(method, io.swagger.v3.oas.annotations.Operation.class); JsonView jsonViewAnnotation = ReflectionUtils.getAnnotation(method, JsonView.class); if (apiOperation != null && apiOperation.ignoreJsonView()) io.swagger.v3.oas.annotations.Operation apiOperation = ReflectionUtils.getAnnotation(method, io.swagger.v3.oas.annotations.Operation.class); io.swagger.v3.oas.annotations.parameters.RequestBody apiRequestBody = ReflectionUtils.getAnnotation(method, io.swagger.v3.oas.annotations.parameters.RequestBody.class); ExternalDocumentation apiExternalDocumentation = ReflectionUtils.getAnnotation(method, ExternalDocumentation.class);
Method method = methodOpt.get(); Annotation[][] paramAnnotations = ReflectionUtils.getParameterAnnotations(method); Consumes methodConsumes = ReflectionUtils.getAnnotation(method, Consumes.class); Consumes classConsumes = ReflectionUtils.getAnnotation(method.getDeclaringClass(), Consumes.class); JsonView jsonViewAnnotation = ReflectionUtils.getAnnotation(method, JsonView.class);