diff --git a/extension-spring/src/main/java/io/smallrye/openapi/spring/SpringAnnotationScanner.java b/extension-spring/src/main/java/io/smallrye/openapi/spring/SpringAnnotationScanner.java index 75c5e190d..6bbc4cea0 100644 --- a/extension-spring/src/main/java/io/smallrye/openapi/spring/SpringAnnotationScanner.java +++ b/extension-spring/src/main/java/io/smallrye/openapi/spring/SpringAnnotationScanner.java @@ -59,7 +59,6 @@ public boolean isWrapperType(Type type) { @Override public boolean isAsyncResponse(final MethodInfo method) { - // TODO: Implement this. return false; } @@ -89,13 +88,13 @@ public boolean isScannerInternalResponse(Type returnType) { @Override public boolean isMultipartOutput(Type returnType) { - // TODO: Check this + // XXX: Check this return SpringConstants.MULTIPART_OUTPUTS.contains(returnType.name()); } @Override public boolean isMultipartInput(Type inputType) { - // TODO: Check this + // XXX: Check this return SpringConstants.MULTIPART_INPUTS.contains(inputType.name()); } @@ -105,6 +104,7 @@ public boolean isFrameworkContextType(Type type) { } @Override + @SuppressWarnings("deprecation") public boolean containsScannerAnnotations(List instances, List extensions) { for (AnnotationInstance instance : instances) { @@ -144,7 +144,7 @@ private boolean hasRequestMappingMethod(final MethodInfo method, final String re /** * Find and process all Spring Controllers - * TODO: Also support org.springframework.stereotype.Controller annotations ? + * Future: Also support org.springframework.stereotype.Controller annotations ? * * @param context the scanning context * @param openApi the openAPI model @@ -279,11 +279,11 @@ private void processControllerMethod(final ClassInfo resourceClass, // Figure out the current @Produces and @Consumes (if any) String[] defaultConsumes = getDefaultConsumes(context, method, getResourceParameters(resourceClass, method)); context.setDefaultConsumes(defaultConsumes); - context.setCurrentConsumes(getMediaTypes(method, SpringConstants.MAPPING_CONSUMES, defaultConsumes).orElse(null)); + context.setCurrentConsumes(getMediaTypes(method, SpringConstants.MAPPING_CONSUMES).orElse(null)); String[] defaultProduces = getDefaultProduces(context, method); context.setDefaultProduces(defaultProduces); - context.setCurrentProduces(getMediaTypes(method, SpringConstants.MAPPING_PRODUCES, defaultProduces).orElse(null)); + context.setCurrentProduces(getMediaTypes(method, SpringConstants.MAPPING_PRODUCES).orElse(null)); // Process any @Operation annotation Optional maybeOperation = processOperation(context, resourceClass, method); @@ -368,11 +368,10 @@ private ResourceParameters getResourceParameters(final ClassInfo resourceClass, final MethodInfo method) { Function reader = t -> context.io().parameterIO().read(t); return SpringParameterProcessor.process(context, currentAppPath, resourceClass, - method, reader, - context.getExtensions()); + method, reader); } - Optional getMediaTypes(MethodInfo resourceMethod, String property, String[] defaultValue) { + Optional getMediaTypes(MethodInfo resourceMethod, String property) { Set annotationNames = new HashSet<>(SpringConstants.HTTP_METHODS); annotationNames.add(SpringConstants.REQUEST_MAPPING); diff --git a/extension-spring/src/main/java/io/smallrye/openapi/spring/SpringLogging.java b/extension-spring/src/main/java/io/smallrye/openapi/spring/SpringLogging.java index c33f7a6e9..83cd57993 100644 --- a/extension-spring/src/main/java/io/smallrye/openapi/spring/SpringLogging.java +++ b/extension-spring/src/main/java/io/smallrye/openapi/spring/SpringLogging.java @@ -1,5 +1,7 @@ package io.smallrye.openapi.spring; +import static java.lang.invoke.MethodHandles.lookup; + import org.jboss.logging.Logger; import org.jboss.logging.annotations.LogMessage; import org.jboss.logging.annotations.Message; @@ -7,7 +9,7 @@ @MessageLogger(projectCode = "SROAP", length = 5) interface SpringLogging { - SpringLogging log = Logger.getMessageLogger(SpringLogging.class, SpringLogging.class.getPackage().getName()); + SpringLogging log = Logger.getMessageLogger(lookup(), SpringLogging.class, SpringLogging.class.getPackage().getName()); @LogMessage(level = Logger.Level.WARN) @Message(id = 11000, value = "Ignoring %s annotation that is not on a class") diff --git a/extension-spring/src/main/java/io/smallrye/openapi/spring/SpringParameterProcessor.java b/extension-spring/src/main/java/io/smallrye/openapi/spring/SpringParameterProcessor.java index e75ee7f4e..113ca1b95 100644 --- a/extension-spring/src/main/java/io/smallrye/openapi/spring/SpringParameterProcessor.java +++ b/extension-spring/src/main/java/io/smallrye/openapi/spring/SpringParameterProcessor.java @@ -20,7 +20,6 @@ import org.jboss.jandex.Type; import io.smallrye.openapi.runtime.io.Names; -import io.smallrye.openapi.runtime.scanner.AnnotationScannerExtension; import io.smallrye.openapi.runtime.scanner.ResourceParameters; import io.smallrye.openapi.runtime.scanner.dataobject.TypeResolver; import io.smallrye.openapi.runtime.scanner.spi.AbstractParameterProcessor; @@ -45,9 +44,8 @@ public class SpringParameterProcessor extends AbstractParameterProcessor { private SpringParameterProcessor(AnnotationScannerContext scannerContext, String contextPath, - Function reader, - List extensions) { - super(scannerContext, contextPath, reader, extensions); + Function reader) { + super(scannerContext, contextPath, reader, scannerContext.getExtensions()); } /** @@ -63,7 +61,6 @@ private SpringParameterProcessor(AnnotationScannerContext scannerContext, * Spring HTTP annotations * @param reader callback method for a function producing {@link Parameter} from a * {@link org.eclipse.microprofile.openapi.annotations.parameters.Parameter} - * @param extensions scanner extensions * @return scanned parameters and modified path contained in a {@link ResourceParameters} * object */ @@ -71,10 +68,9 @@ public static ResourceParameters process(AnnotationScannerContext context, String contextPath, ClassInfo resourceClass, MethodInfo resourceMethod, - Function reader, - List extensions) { + Function reader) { - SpringParameterProcessor processor = new SpringParameterProcessor(context, contextPath, reader, extensions); + SpringParameterProcessor processor = new SpringParameterProcessor(context, contextPath, reader); return processor.process(resourceClass, resourceMethod); } @@ -99,53 +95,51 @@ protected void readAnnotatedType(AnnotationInstance annotation, AnnotationInstan FrameworkParameter frameworkParam = SpringParameter.forName(name); if (frameworkParam != null) { - AnnotationTarget target = annotation.target(); - Type targetType = getType(target); - - if (frameworkParam.style == Style.FORM) { - // Store the @FormParam for later processing - formParams.put(paramName(annotation), annotation); - readFrameworkParameter(annotation, frameworkParam, overriddenParametersOnly); - } else if (frameworkParam.style == Style.MATRIX) { - // Store the @MatrixParam for later processing - List pathSegments = beanParamAnnotation != null - ? lastPathSegmentsOf(beanParamAnnotation.target()) - : lastPathSegmentsOf(target); - - for (String pathSegment : pathSegments) { - matrixParams - .computeIfAbsent(pathSegment, k -> new HashMap<>()) - .put(paramName(annotation), annotation); - } - - // Do this in Spring ? - //}else if (frameworkParam.location == In.PATH && targetType != null - // && SpringConstants.REQUEST_MAPPING.equals(targetType.name())) { - // String pathSegment = JandexUtil.value(annotation, ParameterConstant.PROP_VALUE); - - // if (!matrixParams.containsKey(pathSegment)) { - // matrixParams.put(pathSegment, new HashMap<>()); - // } - } else if (frameworkParam.location != null) { - readFrameworkParameter(annotation, frameworkParam, overriddenParametersOnly); - } else if (target != null && annotatesHttpGET(target)) { - // This is a SpringDoc @ParameterObject - setMediaType(frameworkParam); - targetType = TypeUtil.unwrapType(targetType); - - if (targetType != null) { - ClassInfo beanParam = index.getClassByName(targetType.name()); - - /* - * Since the properties of the bean are probably not annotated (supported in Spring), - * here we process them with a generated Spring @RequestParam annotation attached. - */ - for (var entry : TypeResolver.getAllFields(scannerContext, targetType, beanParam, null).entrySet()) { - var syntheticQuery = AnnotationInstance.builder(SpringConstants.QUERY_PARAM) - .buildWithTarget(entry.getValue().getAnnotationTarget()); - readAnnotatedType(syntheticQuery, beanParamAnnotation, overriddenParametersOnly); - } - } + readSpringParameter(frameworkParam, annotation, beanParamAnnotation, overriddenParametersOnly); + } + } + } + + private void readSpringParameter(FrameworkParameter frameworkParam, + AnnotationInstance annotation, + AnnotationInstance beanParamAnnotation, + boolean overriddenParametersOnly) { + AnnotationTarget target = annotation.target(); + Type targetType = getType(target); + + if (frameworkParam.style == Style.FORM) { + // Store the @FormParam for later processing + formParams.put(paramName(annotation), annotation); + readFrameworkParameter(annotation, frameworkParam, overriddenParametersOnly); + } else if (frameworkParam.style == Style.MATRIX) { + // Store the @MatrixParam for later processing + List pathSegments = beanParamAnnotation != null + ? lastPathSegmentsOf(beanParamAnnotation.target()) + : lastPathSegmentsOf(target); + + for (String pathSegment : pathSegments) { + matrixParams + .computeIfAbsent(pathSegment, k -> new HashMap<>()) + .put(paramName(annotation), annotation); + } + } else if (frameworkParam.location != null) { + readFrameworkParameter(annotation, frameworkParam, overriddenParametersOnly); + } else if (target != null && annotatesHttpGET(target)) { + // This is a SpringDoc @ParameterObject + setMediaType(frameworkParam); + targetType = TypeUtil.unwrapType(targetType); + + if (targetType != null) { + ClassInfo beanParam = index.getClassByName(targetType.name()); + + /* + * Since the properties of the bean are probably not annotated (supported in Spring), + * here we process them with a generated Spring @RequestParam annotation attached. + */ + for (var entry : TypeResolver.getAllFields(scannerContext, targetType, beanParam, null).entrySet()) { + var syntheticQuery = AnnotationInstance.builder(SpringConstants.QUERY_PARAM) + .buildWithTarget(entry.getValue().getAnnotationTarget()); + readAnnotatedType(syntheticQuery, beanParamAnnotation, overriddenParametersOnly); } } } diff --git a/extension-spring/src/test/java/io/smallrye/openapi/runtime/scanner/DeprecatedAnnotationTest.java b/extension-spring/src/test/java/io/smallrye/openapi/runtime/scanner/DeprecatedAnnotationTest.java index b00e1f0f1..302029050 100644 --- a/extension-spring/src/test/java/io/smallrye/openapi/runtime/scanner/DeprecatedAnnotationTest.java +++ b/extension-spring/src/test/java/io/smallrye/openapi/runtime/scanner/DeprecatedAnnotationTest.java @@ -3,12 +3,8 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import java.io.IOException; - import org.eclipse.microprofile.openapi.models.OpenAPI; import org.eclipse.microprofile.openapi.models.media.Schema; -import org.jboss.jandex.Index; -import org.json.JSONException; import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; @@ -43,10 +39,8 @@ public ResponseEntity getD2() { } @Test - void testDeprecatedClassSetsOperationsDeprecated() throws IOException, JSONException { - Index index = Index.of(DeprecatedResource.class); - OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), index); - OpenAPI result = scanner.scan(); + void testDeprecatedClassSetsOperationsDeprecated() { + OpenAPI result = scan(DeprecatedResource.class); // NOSONAR assertTrue(result.getPaths().getPathItem("/deprecated/d1").getGET().getDeprecated()); assertTrue(result.getPaths().getPathItem("/deprecated/d2").getGET().getDeprecated()); } @@ -71,10 +65,8 @@ public ResponseEntity getD1() { } @Test - void testDeprecatedMethodSetsOperationsDeprecated() throws IOException, JSONException { - Index index = Index.of(MixedDeprecationResource.class); - OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), index); - OpenAPI result = scanner.scan(); + void testDeprecatedMethodSetsOperationsDeprecated() { + OpenAPI result = scan(MixedDeprecationResource.class); assertNull(result.getPaths().getPathItem("/mixed/m1").getGET().getDeprecated()); assertTrue(result.getPaths().getPathItem("/mixed/d1").getGET().getDeprecated()); } @@ -98,11 +90,8 @@ public ResponseEntity getO3(@MatrixVariable("p1") @Deprecated String p1, @Mat } @Test - void testDeprecatedParametersSetDeprecated() throws IOException, JSONException { - Index index = Index.of(DeprecatedParamResource.class); - OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), index); - OpenAPI result = scanner.scan(); - printToConsole(result); + void testDeprecatedParametersSetDeprecated() { + OpenAPI result = scan(DeprecatedParamResource.class); assertTrue(result.getPaths().getPathItem("/params/o1").getGET().getParameters().get(0).getDeprecated()); assertNull(result.getPaths().getPathItem("/params/o1").getGET().getParameters().get(1).getDeprecated()); diff --git a/extension-spring/src/test/java/io/smallrye/openapi/runtime/scanner/SpringAnnotationScannerTest.java b/extension-spring/src/test/java/io/smallrye/openapi/runtime/scanner/SpringAnnotationScannerTest.java index 8299b98ae..3890b99f1 100644 --- a/extension-spring/src/test/java/io/smallrye/openapi/runtime/scanner/SpringAnnotationScannerTest.java +++ b/extension-spring/src/test/java/io/smallrye/openapi/runtime/scanner/SpringAnnotationScannerTest.java @@ -3,7 +3,6 @@ import java.io.IOException; import org.eclipse.microprofile.openapi.models.OpenAPI; -import org.jboss.jandex.Index; import org.json.JSONException; import org.junit.jupiter.api.Test; @@ -26,7 +25,7 @@ * * @author Phillip Kruger (phillip.kruger@redhat.com) */ -class SpringAnnotationScannerTest extends SpringDataObjectScannerTestBase { +class SpringAnnotationScannerTest extends IndexScannerTestBase { /** * This test a basic, no OpenApi annotations, hello world service @@ -36,12 +35,7 @@ class SpringAnnotationScannerTest extends SpringDataObjectScannerTestBase { */ @Test void testBasicGetSpringDefinitionScanning() throws IOException, JSONException { - Index i = indexOf(GreetingGetController.class, Greeting.class, GreetingParam.class); - OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), i); - - OpenAPI result = scanner.scan(); - - printToConsole(result); + OpenAPI result = scan(GreetingGetController.class, Greeting.class, GreetingParam.class); assertJsonEquals("resource.testBasicSpringGetDefinitionScanning.json", result); } @@ -55,12 +49,7 @@ void testBasicGetSpringDefinitionScanning() throws IOException, JSONException { */ @Test void testBasicSpringDefinitionScanningAlt() throws IOException, JSONException { - Index i = indexOf(GreetingGetControllerAlt.class, Greeting.class, GreetingParam.class); - OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), i); - - OpenAPI result = scanner.scan(); - - printToConsole(result); + OpenAPI result = scan(GreetingGetControllerAlt.class, Greeting.class, GreetingParam.class); assertJsonEquals("resource.testBasicSpringGetDefinitionScanning.json", result); } @@ -74,12 +63,7 @@ void testBasicSpringDefinitionScanningAlt() throws IOException, JSONException { */ @Test void testBasicSpringDefinitionScanningAlt2() throws IOException, JSONException { - Index i = indexOf(GreetingGetControllerAlt2.class, Greeting.class, GreetingParam.class); - OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), i); - - OpenAPI result = scanner.scan(); - - printToConsole(result); + OpenAPI result = scan(GreetingGetControllerAlt2.class, Greeting.class, GreetingParam.class); assertJsonEquals("resource.testBasicSpringGetDefinitionScanning.json", result); } @@ -91,12 +75,7 @@ void testBasicSpringDefinitionScanningAlt2() throws IOException, JSONException { */ @Test void testBasicPostSpringDefinitionScanning() throws IOException, JSONException { - Index i = indexOf(GreetingPostController.class, Greeting.class, GreetingParam.class); - OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), i); - - OpenAPI result = scanner.scan(); - - printToConsole(result); + OpenAPI result = scan(GreetingPostController.class, Greeting.class, GreetingParam.class); assertJsonEquals("resource.testBasicSpringPostDefinitionScanning.json", result); } @@ -108,12 +87,7 @@ void testBasicPostSpringDefinitionScanning() throws IOException, JSONException { */ @Test void testBasicPostSpringDefinitionScanningAlt() throws IOException, JSONException { - Index i = indexOf(GreetingPostControllerAlt.class, Greeting.class, GreetingParam.class); - OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), i); - - OpenAPI result = scanner.scan(); - - printToConsole(result); + OpenAPI result = scan(GreetingPostControllerAlt.class, Greeting.class, GreetingParam.class); assertJsonEquals("resource.testBasicSpringPostDefinitionScanning.json", result); } @@ -125,12 +99,7 @@ void testBasicPostSpringDefinitionScanningAlt() throws IOException, JSONExceptio */ @Test void testMultiplePathsPostSpringDefinitionScanningAlt() throws IOException, JSONException { - Index i = indexOf(GreetingPostControllerMultiplePaths.class, Greeting.class, GreetingParam.class); - OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), i); - - OpenAPI result = scanner.scan(); - - printToConsole(result); + OpenAPI result = scan(GreetingPostControllerMultiplePaths.class, Greeting.class, GreetingParam.class); assertJsonEquals("resource.testMultiplePathsSpringPostDefinitionScanning.json", result); } @@ -142,14 +111,9 @@ void testMultiplePathsPostSpringDefinitionScanningAlt() throws IOException, JSON */ @Test void testBasicPostSpringDefinitionScanningWithServletContextJakarta() throws IOException, JSONException { - Index i = indexOf( + OpenAPI result = scan( test.io.smallrye.openapi.runtime.scanner.resources.jakarta.GreetingPostControllerWithServletContext.class, Greeting.class); - OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), i); - - OpenAPI result = scanner.scan(); - - printToConsole(result); assertJsonEquals("resource.testBasicSpringPostDefinitionScanning.json", result); } @@ -161,14 +125,9 @@ void testBasicPostSpringDefinitionScanningWithServletContextJakarta() throws IOE */ @Test void testBasicPostSpringDefinitionScanningWithServletContextJavax() throws IOException, JSONException { - Index i = indexOf( + OpenAPI result = scan( test.io.smallrye.openapi.runtime.scanner.resources.javax.GreetingPostControllerWithServletContext.class, Greeting.class); - OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), i); - - OpenAPI result = scanner.scan(); - - printToConsole(result); assertJsonEquals("resource.testBasicSpringPostDefinitionScanning.json", result); } @@ -180,12 +139,7 @@ void testBasicPostSpringDefinitionScanningWithServletContextJavax() throws IOExc */ @Test void testBasicPutSpringDefinitionScanning() throws IOException, JSONException { - Index i = indexOf(GreetingPutController.class, Greeting.class); - OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), i); - - OpenAPI result = scanner.scan(); - - printToConsole(result); + OpenAPI result = scan(GreetingPutController.class, Greeting.class); assertJsonEquals("resource.testBasicSpringPutDefinitionScanning.json", result); } @@ -197,12 +151,7 @@ void testBasicPutSpringDefinitionScanning() throws IOException, JSONException { */ @Test void testBasicPutSpringDefinitionScanningAlt() throws IOException, JSONException { - Index i = indexOf(GreetingPutControllerAlt.class, Greeting.class); - OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), i); - - OpenAPI result = scanner.scan(); - - printToConsole(result); + OpenAPI result = scan(GreetingPutControllerAlt.class, Greeting.class); assertJsonEquals("resource.testBasicSpringPutDefinitionScanning.json", result); } @@ -214,12 +163,7 @@ void testBasicPutSpringDefinitionScanningAlt() throws IOException, JSONException */ @Test void testMultiplePathsPutSpringDefinitionScanningAlt() throws IOException, JSONException { - Index i = indexOf(GreetingPutControllerMultiplePaths.class, Greeting.class, GreetingParam.class); - OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), i); - - OpenAPI result = scanner.scan(); - - printToConsole(result); + OpenAPI result = scan(GreetingPutControllerMultiplePaths.class, Greeting.class, GreetingParam.class); assertJsonEquals("resource.testMultiplePathsSpringPutDefinitionScanning.json", result); } @@ -231,14 +175,9 @@ void testMultiplePathsPutSpringDefinitionScanningAlt() throws IOException, JSONE */ @Test void testBasicPutSpringDefinitionScanningWithServletContextJakarta() throws IOException, JSONException { - Index i = indexOf( + OpenAPI result = scan( test.io.smallrye.openapi.runtime.scanner.resources.jakarta.GreetingPutControllerWithServletContext.class, Greeting.class); - OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), i); - - OpenAPI result = scanner.scan(); - - printToConsole(result); assertJsonEquals("resource.testBasicSpringPutDefinitionScanning.json", result); } @@ -250,14 +189,9 @@ void testBasicPutSpringDefinitionScanningWithServletContextJakarta() throws IOEx */ @Test void testBasicPutSpringDefinitionScanningWithServletContextJavax() throws IOException, JSONException { - Index i = indexOf( + OpenAPI result = scan( test.io.smallrye.openapi.runtime.scanner.resources.javax.GreetingPutControllerWithServletContext.class, Greeting.class); - OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), i); - - OpenAPI result = scanner.scan(); - - printToConsole(result); assertJsonEquals("resource.testBasicSpringPutDefinitionScanning.json", result); } @@ -269,12 +203,7 @@ void testBasicPutSpringDefinitionScanningWithServletContextJavax() throws IOExce */ @Test void testBasicDeleteSpringDefinitionScanning() throws IOException, JSONException { - Index i = indexOf(GreetingDeleteController.class, Greeting.class); - OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), i); - - OpenAPI result = scanner.scan(); - - printToConsole(result); + OpenAPI result = scan(GreetingDeleteController.class, Greeting.class); assertJsonEquals("resource.testBasicSpringDeleteDefinitionScanning.json", result); } @@ -286,12 +215,7 @@ void testBasicDeleteSpringDefinitionScanning() throws IOException, JSONException */ @Test void testBasicDeleteSpringDefinitionScanningAlt() throws IOException, JSONException { - Index i = indexOf(GreetingDeleteControllerAlt.class, Greeting.class); - OpenApiAnnotationScanner scanner = new OpenApiAnnotationScanner(emptyConfig(), i); - - OpenAPI result = scanner.scan(); - - printToConsole(result); + OpenAPI result = scan(GreetingDeleteControllerAlt.class, Greeting.class); assertJsonEquals("resource.testBasicSpringDeleteDefinitionScanning.json", result); } } diff --git a/extension-spring/src/test/java/io/smallrye/openapi/runtime/scanner/SpringDataObjectScannerTestBase.java b/extension-spring/src/test/java/io/smallrye/openapi/runtime/scanner/SpringDataObjectScannerTestBase.java deleted file mode 100644 index 8de895945..000000000 --- a/extension-spring/src/test/java/io/smallrye/openapi/runtime/scanner/SpringDataObjectScannerTestBase.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.smallrye.openapi.runtime.scanner; - -import org.jboss.jandex.Index; -import org.jboss.jandex.Indexer; -import org.junit.jupiter.api.BeforeAll; - -/** - * Base for Spring tests. Index the test classes - * - * @author Phillip Kruger (phillip.kruger@redhat.com) - */ -public class SpringDataObjectScannerTestBase extends IndexScannerTestBase { - - protected static Index index; - - @BeforeAll - public static void createIndex() { - Indexer indexer = new Indexer(); - - // Test samples - indexDirectory(indexer, "test/io/smallrye/openapi/runtime/scanner/entities/"); - - index = indexer.complete(); - } - -} diff --git a/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/GreetingGetController.java b/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/GreetingGetController.java index 4fae93c1c..7002f645b 100644 --- a/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/GreetingGetController.java +++ b/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/GreetingGetController.java @@ -69,7 +69,7 @@ public Greeting helloParameterObject(@ParameterObject() GreetingParam params) { @SuppressWarnings("rawtypes") @GetMapping("/helloPathVariableWithResponse/{name}") @APIResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(ref = "#/components/schemas/Greeting"))) - public ResponseEntity helloPathVariableWithResponse(@PathVariable(name = "name") String name) { + public ResponseEntity helloPathVariableWithResponse(@PathVariable(name = "name") String name) { return ResponseEntity.ok(new Greeting("Hello " + name)); } diff --git a/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/GreetingGetControllerAlt.java b/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/GreetingGetControllerAlt.java index fabbef1c5..1033b45bd 100644 --- a/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/GreetingGetControllerAlt.java +++ b/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/GreetingGetControllerAlt.java @@ -72,7 +72,7 @@ public Greeting helloParameterObject(@ParameterObject() GreetingParam params) { @SuppressWarnings("rawtypes") @RequestMapping(value = "/helloPathVariableWithResponse/{name}", method = RequestMethod.GET) @APIResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(ref = "#/components/schemas/Greeting"))) - public ResponseEntity helloPathVariableWithResponse(@PathVariable(name = "name") String name) { + public ResponseEntity helloPathVariableWithResponse(@PathVariable(name = "name") String name) { return ResponseEntity.ok(new Greeting("Hello " + name)); } diff --git a/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/GreetingGetControllerAlt2.java b/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/GreetingGetControllerAlt2.java index 37d50eebe..94148551f 100644 --- a/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/GreetingGetControllerAlt2.java +++ b/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/GreetingGetControllerAlt2.java @@ -71,7 +71,7 @@ public Greeting helloParameterObject(@ParameterObject() GreetingParam params) { @SuppressWarnings("rawtypes") @RequestMapping(path = "/helloPathVariableWithResponse/{name}", method = RequestMethod.GET) @APIResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(ref = "#/components/schemas/Greeting"))) - public ResponseEntity helloPathVariableWithResponse(@PathVariable(name = "name") String name) { + public ResponseEntity helloPathVariableWithResponse(@PathVariable(name = "name") String name) { return ResponseEntity.ok(new Greeting("Hello " + name)); } diff --git a/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/jakarta/GreetingPostControllerWithServletContext.java b/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/jakarta/GreetingPostControllerWithServletContext.java index 93e619af9..db5267637 100644 --- a/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/jakarta/GreetingPostControllerWithServletContext.java +++ b/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/jakarta/GreetingPostControllerWithServletContext.java @@ -34,6 +34,7 @@ public Greeting greet(HttpServletRequest request, HttpServletResponse response, } // 2) ResponseEntity without a type specified + @SuppressWarnings("rawtypes") @PostMapping("/greetWithResponse") @APIResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(ref = "#/components/schemas/Greeting"))) public ResponseEntity greetWithResponse(@RequestBody Greeting greeting, HttpServletRequest request, diff --git a/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/jakarta/GreetingPutControllerWithServletContext.java b/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/jakarta/GreetingPutControllerWithServletContext.java index 203f3840f..f54ce2522 100644 --- a/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/jakarta/GreetingPutControllerWithServletContext.java +++ b/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/jakarta/GreetingPutControllerWithServletContext.java @@ -36,6 +36,7 @@ public Greeting greet(HttpServletRequest request, HttpServletResponse response, } // 2) ResponseEntity without a type specified + @SuppressWarnings("rawtypes") @PutMapping("/greetWithResponse/{id}") @APIResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(ref = "#/components/schemas/Greeting"))) public ResponseEntity greetWithResponse(@RequestBody Greeting greeting, @PathVariable(name = "id") String id, diff --git a/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/javax/GreetingPostControllerWithServletContext.java b/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/javax/GreetingPostControllerWithServletContext.java index 75e245631..0acd923dd 100644 --- a/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/javax/GreetingPostControllerWithServletContext.java +++ b/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/javax/GreetingPostControllerWithServletContext.java @@ -34,6 +34,7 @@ public Greeting greet(HttpServletRequest request, HttpServletResponse response, } // 2) ResponseEntity without a type specified + @SuppressWarnings("rawtypes") @PostMapping("/greetWithResponse") @APIResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(ref = "#/components/schemas/Greeting"))) public ResponseEntity greetWithResponse(@RequestBody Greeting greeting, HttpServletRequest request, diff --git a/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/javax/GreetingPutControllerWithServletContext.java b/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/javax/GreetingPutControllerWithServletContext.java index 3a1af52ae..9ff5642d8 100644 --- a/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/javax/GreetingPutControllerWithServletContext.java +++ b/extension-spring/src/test/java/test/io/smallrye/openapi/runtime/scanner/resources/javax/GreetingPutControllerWithServletContext.java @@ -36,6 +36,7 @@ public Greeting greet(HttpServletRequest request, HttpServletResponse response, } // 2) ResponseEntity without a type specified + @SuppressWarnings("rawtypes") @PutMapping("/greetWithResponse/{id}") @APIResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(ref = "#/components/schemas/Greeting"))) public ResponseEntity greetWithResponse(@RequestBody Greeting greeting, @PathVariable(name = "id") String id, diff --git a/extension-vertx/src/main/java/io/smallrye/openapi/vertx/VertxAnnotationScanner.java b/extension-vertx/src/main/java/io/smallrye/openapi/vertx/VertxAnnotationScanner.java index 817de8b0b..756d3e83c 100644 --- a/extension-vertx/src/main/java/io/smallrye/openapi/vertx/VertxAnnotationScanner.java +++ b/extension-vertx/src/main/java/io/smallrye/openapi/vertx/VertxAnnotationScanner.java @@ -49,7 +49,6 @@ public String getName() { @Override public boolean isAsyncResponse(final MethodInfo method) { - // TODO: Implement this. return false; } diff --git a/extension-vertx/src/main/java/io/smallrye/openapi/vertx/VertxParameterProcessor.java b/extension-vertx/src/main/java/io/smallrye/openapi/vertx/VertxParameterProcessor.java index 5b30fc48a..25d7f21b6 100644 --- a/extension-vertx/src/main/java/io/smallrye/openapi/vertx/VertxParameterProcessor.java +++ b/extension-vertx/src/main/java/io/smallrye/openapi/vertx/VertxParameterProcessor.java @@ -116,35 +116,34 @@ protected void readAnnotatedType(AnnotationInstance annotation, AnnotationInstan private void readAnnotatedType(FrameworkParameter frameworkParam, AnnotationInstance annotation, AnnotationInstance beanParamAnnotation, boolean overriddenParametersOnly) { - if (frameworkParam != null) { - AnnotationTarget target = annotation.target(); - Type targetType = getType(target); - - if (frameworkParam.style == Style.FORM) { - // Store the @FormParam for later processing - formParams.put(paramName(annotation), annotation); - readFrameworkParameter(annotation, frameworkParam, overriddenParametersOnly); - } else if (frameworkParam.style == Style.MATRIX) { - // Store the @MatrixParam for later processing - List pathSegments = beanParamAnnotation != null - ? lastPathSegmentsOf(beanParamAnnotation.target()) - : lastPathSegmentsOf(target); - boolean isPathSegmentsEmpty = pathSegments == null || pathSegments.isEmpty(); - String pathSegment = !isPathSegmentsEmpty ? pathSegments.get(0) : null; - - matrixParams.computeIfAbsent(pathSegment, k -> new HashMap<>()) - .put(paramName(annotation), annotation); - } else if (frameworkParam.location != null) { - readFrameworkParameter(annotation, frameworkParam, overriddenParametersOnly); - } else if (target != null) { - // This is a @BeanParam or a RESTEasy @MultipartForm - setMediaType(frameworkParam); - targetType = TypeUtil.unwrapType(targetType); - - if (targetType != null) { - ClassInfo beanParam = index.getClassByName(targetType.name()); - readParameters(beanParam, annotation, overriddenParametersOnly); - } + + AnnotationTarget target = annotation.target(); + Type targetType = getType(target); + + if (frameworkParam.style == Style.FORM) { + // Store the @FormParam for later processing + formParams.put(paramName(annotation), annotation); + readFrameworkParameter(annotation, frameworkParam, overriddenParametersOnly); + } else if (frameworkParam.style == Style.MATRIX) { + // Store the @MatrixParam for later processing + List pathSegments = beanParamAnnotation != null + ? lastPathSegmentsOf(beanParamAnnotation.target()) + : lastPathSegmentsOf(target); + boolean isPathSegmentsEmpty = pathSegments == null || pathSegments.isEmpty(); + String pathSegment = !isPathSegmentsEmpty ? pathSegments.get(0) : null; + + matrixParams.computeIfAbsent(pathSegment, k -> new HashMap<>()) + .put(paramName(annotation), annotation); + } else if (frameworkParam.location != null) { + readFrameworkParameter(annotation, frameworkParam, overriddenParametersOnly); + } else if (target != null) { + // This is a @BeanParam or a RESTEasy @MultipartForm + setMediaType(frameworkParam); + targetType = TypeUtil.unwrapType(targetType); + + if (targetType != null) { + ClassInfo beanParam = index.getClassByName(targetType.name()); + readParameters(beanParam, annotation, overriddenParametersOnly); } } }