/** * Returns a List of repeatable annotations 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 List of repeatable annotations if it is found */ public static <A extends Annotation> List<A> getRepeatableAnnotations(Method method, Class<A> annotationClass) { A[] annotations = method.getAnnotationsByType(annotationClass); if (annotations == null || annotations.length == 0) { for (Annotation metaAnnotation : method.getAnnotations()) { annotations = metaAnnotation.annotationType().getAnnotationsByType(annotationClass); if (annotations != null && annotations.length > 0) { return Arrays.asList(annotations); } } Method superclassMethod = getOverriddenMethod(method); if (superclassMethod != null) { return getRepeatableAnnotations(superclassMethod, annotationClass); } } if (annotations == null) { return null; } return Arrays.asList(annotations); }
List<io.swagger.v3.oas.annotations.security.SecurityScheme> apiSecurityScheme = ReflectionUtils.getRepeatableAnnotations(cls, io.swagger.v3.oas.annotations.security.SecurityScheme.class); List<io.swagger.v3.oas.annotations.security.SecurityRequirement> apiSecurityRequirements = ReflectionUtils.getRepeatableAnnotations(cls, io.swagger.v3.oas.annotations.security.SecurityRequirement.class); List<io.swagger.v3.oas.annotations.security.SecurityRequirement> apiSecurity = ReflectionUtils.getRepeatableAnnotations(method, io.swagger.v3.oas.annotations.security.SecurityRequirement.class); List<io.swagger.v3.oas.annotations.callbacks.Callback> apiCallbacks = ReflectionUtils.getRepeatableAnnotations(method, io.swagger.v3.oas.annotations.callbacks.Callback.class); List<Server> apiServers = ReflectionUtils.getRepeatableAnnotations(method, Server.class); List<io.swagger.v3.oas.annotations.tags.Tag> apiTags = ReflectionUtils.getRepeatableAnnotations(method, io.swagger.v3.oas.annotations.tags.Tag.class); List<io.swagger.v3.oas.annotations.Parameter> apiParameters = ReflectionUtils.getRepeatableAnnotations(method, io.swagger.v3.oas.annotations.Parameter.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);
List<io.swagger.v3.oas.annotations.security.SecurityScheme> apiSecurityScheme = ReflectionUtils.getRepeatableAnnotations(cls, io.swagger.v3.oas.annotations.security.SecurityScheme.class); List<io.swagger.v3.oas.annotations.security.SecurityRequirement> apiSecurityRequirements = ReflectionUtils.getRepeatableAnnotations(cls, io.swagger.v3.oas.annotations.security.SecurityRequirement.class); List<io.swagger.v3.oas.annotations.security.SecurityRequirement> apiSecurity = ReflectionUtils.getRepeatableAnnotations(method, io.swagger.v3.oas.annotations.security.SecurityRequirement.class); List<io.swagger.v3.oas.annotations.callbacks.Callback> apiCallbacks = ReflectionUtils.getRepeatableAnnotations(method, io.swagger.v3.oas.annotations.callbacks.Callback.class); List<Server> apiServers = ReflectionUtils.getRepeatableAnnotations(method, Server.class); List<io.swagger.v3.oas.annotations.tags.Tag> apiTags = ReflectionUtils.getRepeatableAnnotations(method, io.swagger.v3.oas.annotations.tags.Tag.class); List<io.swagger.v3.oas.annotations.Parameter> apiParameters = ReflectionUtils.getRepeatableAnnotations(method, io.swagger.v3.oas.annotations.Parameter.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);
/** * Returns a List of repeatable annotations 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 List of repeatable annotations if it is found */ public static <A extends Annotation> List<A> getRepeatableAnnotations(Method method, Class<A> annotationClass) { A[] annotations = method.getAnnotationsByType(annotationClass); if (annotations == null || annotations.length == 0) { for (Annotation metaAnnotation : method.getAnnotations()) { annotations = metaAnnotation.annotationType().getAnnotationsByType(annotationClass); if (annotations != null && annotations.length > 0) { return Arrays.asList(annotations); } } Method superclassMethod = getOverriddenMethod(method); if (superclassMethod != null) { return getRepeatableAnnotations(superclassMethod, annotationClass); } } if (annotations == null) { return null; } return Arrays.asList(annotations); }
.getRepeatableAnnotations(cls, io.swagger.v3.oas.annotations.security.SecurityScheme.class); List<io.swagger.v3.oas.annotations.security.SecurityRequirement> apiSecurityRequirements = ReflectionUtils .getRepeatableAnnotations(cls, io.swagger.v3.oas.annotations.security.SecurityRequirement.class); .getRepeatableAnnotations(method, io.swagger.v3.oas.annotations.security.SecurityRequirement.class); .getRepeatableAnnotations(method, io.swagger.v3.oas.annotations.callbacks.Callback.class); List<Server> apiServers = ReflectionUtils.getRepeatableAnnotations(method, Server.class); List<io.swagger.v3.oas.annotations.tags.Tag> apiTags = ReflectionUtils.getRepeatableAnnotations(method, io.swagger.v3.oas.annotations.tags.Tag.class); List<io.swagger.v3.oas.annotations.Parameter> apiParameters = ReflectionUtils.getRepeatableAnnotations(method, io.swagger.v3.oas.annotations.Parameter.class); .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);