diff --git a/openapi/src/main/java/io/micronaut/openapi/visitor/ElementUtils.java b/openapi/src/main/java/io/micronaut/openapi/visitor/ElementUtils.java index 9f41ad30cd..d82564976d 100644 --- a/openapi/src/main/java/io/micronaut/openapi/visitor/ElementUtils.java +++ b/openapi/src/main/java/io/micronaut/openapi/visitor/ElementUtils.java @@ -63,33 +63,33 @@ public final class ElementUtils { public static final AnnotationValue[] EMPTY_ANNOTATION_VALUES_ARRAY = new AnnotationValue[0]; public static final List CONTAINER_TYPES = List.of( - Optional.class.getName(), - Future.class.getName(), - Callable.class.getName(), - CompletionStage.class.getName(), - "org.reactivestreams.Publisher", - "io.reactivex.Single", - "io.reactivex.Observable", - "io.reactivex.Maybe", - "io.reactivex.rxjava3.core.Single", - "io.reactivex.rxjava3.core.Observable", - "io.reactivex.rxjava3.core.Maybe", - "kotlinx.coroutines.flow.Flow", - "org.springframework.web.context.request.async.DeferredResult" + Optional.class.getName(), + Future.class.getName(), + Callable.class.getName(), + CompletionStage.class.getName(), + "org.reactivestreams.Publisher", + "io.reactivex.Single", + "io.reactivex.Observable", + "io.reactivex.Maybe", + "io.reactivex.rxjava3.core.Single", + "io.reactivex.rxjava3.core.Observable", + "io.reactivex.rxjava3.core.Maybe", + "kotlinx.coroutines.flow.Flow", + "org.springframework.web.context.request.async.DeferredResult" ); public static final List FILE_TYPES = List.of( - // this class from micronaut-http-server - "io.micronaut.http.server.types.files.FileCustomizableResponseType", - File.class.getName(), - InputStream.class.getName(), - ByteBuffer.class.getName() + // this class from micronaut-http-server + "io.micronaut.http.server.types.files.FileCustomizableResponseType", + File.class.getName(), + InputStream.class.getName(), + ByteBuffer.class.getName() ); public static final List VOID_TYPES = List.of( - void.class.getName(), - Void.class.getName(), - "kotlin.Unit" + void.class.getName(), + Void.class.getName(), + "kotlin.Unit" ); private ElementUtils() { @@ -97,16 +97,16 @@ private ElementUtils() { public static boolean isSingleResponseType(ClassElement returnType) { return (returnType.isAssignable("io.reactivex.Single") - || returnType.isAssignable("io.reactivex.rxjava3.core.Single") - || returnType.isAssignable("org.reactivestreams.Publisher")) - && returnType.getFirstTypeArgument().isPresent() - && isResponseType(returnType.getFirstTypeArgument().orElse(null)); + || returnType.isAssignable("io.reactivex.rxjava3.core.Single") + || returnType.isAssignable("org.reactivestreams.Publisher")) + && returnType.getFirstTypeArgument().isPresent() + && isResponseType(returnType.getFirstTypeArgument().orElse(null)); } public static boolean isResponseType(ClassElement returnType) { return returnType != null - && (returnType.isAssignable(HttpResponse.class) - || returnType.isAssignable("org.springframework.http.HttpEntity")); + && (returnType.isAssignable(HttpResponse.class) + || returnType.isAssignable("org.springframework.http.HttpEntity")); } /** @@ -117,7 +117,7 @@ public static boolean isResponseType(ClassElement returnType) { */ public static boolean isNullable(TypedElement element) { return element.isNullable() - || element.getType().isOptional(); + || element.getType().isOptional(); } /** @@ -135,11 +135,11 @@ public static boolean isFileUpload(ClassElement type) { } String typeName = type.getName(); return type.isAssignable(FileUpload.class) - || "io.micronaut.http.multipart.StreamingFileUpload".equals(typeName) - || "io.micronaut.http.multipart.CompletedFileUpload".equals(typeName) - || "io.micronaut.http.multipart.CompletedPart".equals(typeName) - || "io.micronaut.http.multipart.PartData".equals(typeName) - || "org.springframework.web.multipart.MultipartFile".equals(typeName); + || "io.micronaut.http.multipart.StreamingFileUpload".equals(typeName) + || "io.micronaut.http.multipart.CompletedFileUpload".equals(typeName) + || "io.micronaut.http.multipart.CompletedPart".equals(typeName) + || "io.micronaut.http.multipart.PartData".equals(typeName) + || "org.springframework.web.multipart.MultipartFile".equals(typeName); } /** @@ -150,13 +150,13 @@ public static boolean isFileUpload(ClassElement type) { */ public static boolean isNotNullable(Element element) { return element.isAnnotationPresent("javax.validation.constraints.NotNull$List") - || element.isAnnotationPresent("jakarta.validation.constraints.NotNull$List") - || element.isAnnotationPresent("javax.validation.constraints.NotBlank$List") - || element.isAnnotationPresent("jakarta.validation.constraints.NotBlank$List") - || element.isAnnotationPresent("javax.validation.constraints.NotEmpty$List") - || element.isAnnotationPresent("jakarta.validation.constraints.NotEmpty$List") - || element.isNonNull() - || element.booleanValue(JsonProperty.class, "required").orElse(false); + || element.isAnnotationPresent("jakarta.validation.constraints.NotNull$List") + || element.isAnnotationPresent("javax.validation.constraints.NotBlank$List") + || element.isAnnotationPresent("jakarta.validation.constraints.NotBlank$List") + || element.isAnnotationPresent("javax.validation.constraints.NotEmpty$List") + || element.isAnnotationPresent("jakarta.validation.constraints.NotEmpty$List") + || element.isNonNull() + || element.booleanValue(JsonProperty.class, "required").orElse(false); } /** @@ -197,8 +197,8 @@ public static boolean isVoid(ClassElement type) { */ public static boolean isReactiveAndVoid(ClassElement type) { return type.isAssignable("io.reactivex.Completable") - || type.isAssignable("io.reactivex.rxjava3.core.Completable") - || (isContainerType(type) && type.getFirstTypeArgument().isPresent() && isVoid(type.getFirstTypeArgument().get())); + || type.isAssignable("io.reactivex.rxjava3.core.Completable") + || (isContainerType(type) && type.getFirstTypeArgument().isPresent() && isVoid(type.getFirstTypeArgument().get())); } private static boolean findAnyAssignable(ClassElement type, List typeNames) { @@ -216,42 +216,58 @@ public static boolean isIgnoredParameter(TypedElement parameter) { boolean isHidden = schemaAnn != null && schemaAnn.booleanValue(PROP_HIDDEN).orElse(false); return isHidden - || parameter.isAnnotationPresent(Hidden.class) - || parameter.isAnnotationPresent(JsonIgnore.class) - || parameter.isAnnotationPresent(Header.class) && parameter.getType().isAssignable(Map.class) - || parameter.booleanValue(Parameter.class, PROP_HIDDEN).orElse(false) - || parameter.hasAnnotation("io.micronaut.session.annotation.SessionValue") - || parameter.hasAnnotation("org.springframework.web.bind.annotation.SessionAttribute") - || parameter.hasAnnotation("org.springframework.web.bind.annotation.SessionAttributes") - || isIgnoredParameterType(parameter.getType()); + || parameter.isAnnotationPresent(Hidden.class) + || parameter.isAnnotationPresent(JsonIgnore.class) + || parameter.isAnnotationPresent(Header.class) && parameter.getType().isAssignable(Map.class) + || parameter.booleanValue(Parameter.class, PROP_HIDDEN).orElse(false) + || parameter.hasAnnotation("io.micronaut.session.annotation.SessionValue") + || parameter.hasAnnotation("org.springframework.web.bind.annotation.SessionAttribute") + || parameter.hasAnnotation("org.springframework.web.bind.annotation.SessionAttributes") + || parameter.hasAnnotation("jakarta.ws.rs.core.Context") + || isIgnoredParameterType(parameter.getType()); } public static boolean isIgnoredParameterType(ClassElement parameterType) { return parameterType == null - || parameterType.isAssignable(Principal.class) - || parameterType.isAssignable("io.micronaut.session.Session") - || parameterType.isAssignable("io.micronaut.security.authentication.Authentication") - || parameterType.isAssignable("io.micronaut.http.HttpHeaders") - || parameterType.isAssignable("kotlin.coroutines.Continuation") - || parameterType.isAssignable(HttpRequest.class) - || parameterType.isAssignable("io.micronaut.http.BasicAuth") - // servlet API - || parameterType.isAssignable("jakarta.servlet.http.HttpServletRequest") - || parameterType.isAssignable("jakarta.servlet.http.HttpServletResponse") - || parameterType.isAssignable("jakarta.servlet.http.HttpSession") - || parameterType.isAssignable("jakarta.servlet.http.PushBuilder") - // spring - || parameterType.isAssignable("java.io.Reader") - || parameterType.isAssignable("java.io.OutputStream") - || parameterType.isAssignable("java.io.Writer") - || parameterType.isAssignable("org.springframework.web.util.UriComponentsBuilder") - || parameterType.isAssignable("org.springframework.web.bind.support.SessionStatus") - || parameterType.isAssignable("org.springframework.web.context.request.RequestAttributes") - || parameterType.isAssignable("org.springframework.http.HttpEntity") - || parameterType.isAssignable("org.springframework.http.HttpMethod") - || parameterType.isAssignable("org.springframework.validation.BindingResult") - || parameterType.isAssignable("org.springframework.validation.Errors") - ; + || parameterType.isAssignable(Principal.class) + || parameterType.isAssignable("io.micronaut.session.Session") + || parameterType.isAssignable("io.micronaut.security.authentication.Authentication") + || parameterType.isAssignable("io.micronaut.http.HttpHeaders") + || parameterType.isAssignable("kotlin.coroutines.Continuation") + || parameterType.isAssignable(HttpRequest.class) + || parameterType.isAssignable("io.micronaut.http.BasicAuth") + + // servlet API + || parameterType.isAssignable("jakarta.servlet.http.HttpServletRequest") + || parameterType.isAssignable("jakarta.servlet.http.HttpServletResponse") + || parameterType.isAssignable("jakarta.servlet.http.HttpSession") + || parameterType.isAssignable("jakarta.servlet.ServletConfig") + || parameterType.isAssignable("jakarta.servlet.ServletContext") + || parameterType.isAssignable("jakarta.servlet.ServletRequest") + || parameterType.isAssignable("jakarta.servlet.ServletResponse") + + // jax-rs + || parameterType.isAssignable("jakarta.ws.rs.core.Application") + || parameterType.isAssignable("jakarta.ws.rs.core.HttpHeaders") + || parameterType.isAssignable("jakarta.ws.rs.core.Request") + || parameterType.isAssignable("jakarta.ws.rs.core.SecurityContext") + || parameterType.isAssignable("jakarta.ws.rs.core.UriInfo") + || parameterType.isAssignable("jakarta.ws.rs.core.Configuration") + || parameterType.isAssignable("jakarta.ws.rs.container.ResourceContext") + || parameterType.isAssignable("jakarta.ws.rs.ext.Providers") + + // spring + || parameterType.isAssignable("java.io.Reader") + || parameterType.isAssignable("java.io.OutputStream") + || parameterType.isAssignable("java.io.Writer") + || parameterType.isAssignable("org.springframework.web.util.UriComponentsBuilder") + || parameterType.isAssignable("org.springframework.web.bind.support.SessionStatus") + || parameterType.isAssignable("org.springframework.web.context.request.RequestAttributes") + || parameterType.isAssignable("org.springframework.http.HttpEntity") + || parameterType.isAssignable("org.springframework.http.HttpMethod") + || parameterType.isAssignable("org.springframework.validation.BindingResult") + || parameterType.isAssignable("org.springframework.validation.Errors") + ; } public static AnnotationMetadata getAnnotationMetadata(Element el) {