Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect OpenAPI annotation in Quickstart MP sample #4144

Closed
spericas opened this issue Apr 19, 2022 · 3 comments
Closed

Incorrect OpenAPI annotation in Quickstart MP sample #4144

spericas opened this issue Apr 19, 2022 · 3 comments
Assignees
Labels
bug Something isn't working examples open-api open-api-tools Tracking issues in OpenAPITools generator project P2
Milestone

Comments

@spericas
Copy link
Member

This was uncovered while running a scanning tool. The RequestBody annotation in updateGreeting should be SchemaType.OBJECT instead of SchemaType.STRING. However, updating that results in an OpenAPI generator failure without Jackson in the classpath.

    @Path("/greeting")
    @PUT
    @Consumes(MediaType.APPLICATION_JSON)
    @Produces(MediaType.APPLICATION_JSON)
    @RequestBody(name = "greeting",
            required = true,
            content = @Content(mediaType = "application/json",
                    schema = @Schema(type = SchemaType.STRING, example = "{\"greeting\" : \"Hola\"}")))
    @APIResponses({
            @APIResponse(name = "normal", responseCode = "204", description = "Greeting updated"),
            @APIResponse(name = "missing 'greeting'", responseCode = "400",
                    description = "JSON did not contain setting for 'greeting'")})
    public Response updateGreeting(JsonObject jsonObject) {

This issue is to both fix the sample and also the OpenAPI generator problem.

@spericas spericas added examples open-api open-api-tools Tracking issues in OpenAPITools generator project labels Apr 19, 2022
@spericas spericas added this to the 2.5.1 milestone Apr 19, 2022
@spericas spericas added this to Needs triage in open-api-tools via automation Apr 19, 2022
@spericas spericas added this to Triage in Backlog via automation Apr 19, 2022
@spericas
Copy link
Member Author

spericas commented Apr 20, 2022

Without this dependency (which we shouldn't include all the time, naturally):

 <dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-databind</artifactId>
 </dependency>

we get the following exception:

Exception in thread "main" javax.enterprise.event.ObserverException
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
        at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:128)
        at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:347)
        at java.base/java.lang.Class.newInstance(Class.java:645)
        at org.jboss.weld.security.NewInstanceAction.run(NewInstanceAction.java:33)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
        at org.jboss.weld.injection.Exceptions.rethrowException(Exceptions.java:40)
        at org.jboss.weld.injection.Exceptions.rethrowException(Exceptions.java:78)
        at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:103)
        at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:85)
        at org.jboss.weld.injection.MethodInvocationStrategy$SimpleMethodInvocationStrategy.invoke(MethodInvocationStrategy.java:168)
        at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:330)
        at org.jboss.weld.event.ExtensionObserverMethodImpl.sendEvent(ExtensionObserverMethodImpl.java:123)
        at org.jboss.weld.event.ObserverMethodImpl.sendEvent(ObserverMethodImpl.java:308)
        at org.jboss.weld.event.ObserverMethodImpl.notify(ObserverMethodImpl.java:286)
        at javax.enterprise.inject.spi.ObserverMethod.notify(ObserverMethod.java:124)
        at org.jboss.weld.util.Observers.notify(Observers.java:166)
        at org.jboss.weld.event.ObserverNotifier.notifySyncObservers(ObserverNotifier.java:285)
        at org.jboss.weld.event.ObserverNotifier.notify(ObserverNotifier.java:273)
        at org.jboss.weld.event.EventImpl.fire(EventImpl.java:96)
        at io.helidon.microprofile.cdi.HelidonContainerImpl.doStart(HelidonContainerImpl.java:341)
        at io.helidon.common.context.Contexts.runInContext(Contexts.java:137)
        at io.helidon.microprofile.cdi.HelidonContainerImpl.start(HelidonContainerImpl.java:251)
        at io.helidon.microprofile.cdi.Main.main(Main.java:80)
Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/JsonNode
        at io.smallrye.openapi.runtime.io.schema.SchemaFactory.lambda$parseSchemaAttr$5(SchemaFactory.java:299)
        at io.smallrye.openapi.runtime.io.schema.SchemaFactory.readAttr(SchemaFactory.java:327)
        at io.smallrye.openapi.runtime.io.schema.SchemaFactory.parseSchemaAttr(SchemaFactory.java:293)
        at io.smallrye.openapi.runtime.io.schema.SchemaFactory.readSchema(SchemaFactory.java:180)
        at io.smallrye.openapi.runtime.io.schema.SchemaFactory.readSchema(SchemaFactory.java:80)
        at io.smallrye.openapi.runtime.io.schema.SchemaFactory.readSchema(SchemaFactory.java:65)
        at io.smallrye.openapi.runtime.io.mediatype.MediaTypeReader.readMediaType(MediaTypeReader.java:49)
        at io.smallrye.openapi.runtime.io.content.ContentReader.readContent(ContentReader.java:53)
        at io.smallrye.openapi.runtime.io.requestbody.RequestBodyReader.readRequestBody(RequestBodyReader.java:124)
        at io.smallrye.openapi.runtime.scanner.spi.AnnotationScanner.processRequestBody(AnnotationScanner.java:739)
        at io.smallrye.openapi.jaxrs.JaxRsAnnotationScanner.processResourceMethod(JaxRsAnnotationScanner.java:412)
        at io.smallrye.openapi.jaxrs.JaxRsAnnotationScanner.lambda$processResourceMethods$0(JaxRsAnnotationScanner.java:259)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
        at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
        at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
        at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
        at java.base/java.util.HashMap$KeySpliterator.forEachRemaining(HashMap.java:1689)
        at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
        at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
        at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
        at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
        at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
        at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
        at io.smallrye.openapi.jaxrs.JaxRsAnnotationScanner.processResourceMethods(JaxRsAnnotationScanner.java:257)
        at io.smallrye.openapi.jaxrs.JaxRsAnnotationScanner.processResourceClass(JaxRsAnnotationScanner.java:227)
        at io.smallrye.openapi.jaxrs.JaxRsAnnotationScanner.processResourceClasses(JaxRsAnnotationScanner.java:202)
        at io.smallrye.openapi.jaxrs.JaxRsAnnotationScanner.scan(JaxRsAnnotationScanner.java:136)
        at io.smallrye.openapi.runtime.scanner.OpenApiAnnotationScanner.scan(OpenApiAnnotationScanner.java:127)
        at io.helidon.openapi.OpenAPISupport.lambda$expandModelUsingAnnotations$1(OpenAPISupport.java:333)
        at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
        at io.helidon.openapi.OpenAPISupport.expandModelUsingAnnotations(OpenAPISupport.java:330)
        at io.helidon.openapi.OpenAPISupport.prepareModel(OpenAPISupport.java:298)
        at io.helidon.openapi.OpenAPISupport.model(OpenAPISupport.java:181)
        at io.helidon.openapi.OpenAPISupport.prepareModel(OpenAPISupport.java:176)
        at io.helidon.microprofile.openapi.MPOpenAPISupport.prepareModel(MPOpenAPISupport.java:33)
        at io.helidon.microprofile.openapi.OpenApiCdiExtension.buildModel(OpenApiCdiExtension.java:120)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.jboss.weld.injection.StaticMethodInjectionPoint.invoke(StaticMethodInjectionPoint.java:95)
        ... 15 more
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.JsonNode
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
        ... 56 more

@m0mus m0mus added bug Something isn't working P2 labels Apr 20, 2022
@m0mus m0mus moved this from Needs triage to High priority in open-api-tools Apr 20, 2022
@spericas
Copy link
Member Author

spericas commented Apr 20, 2022

After further digging, it turns out the presence of Jackson is only required when parsing the example attribute and setting the type to OBJECT (there maybe other cases). For our purposes, we can switch to OBJECT and use requiredProperties.

@spericas spericas self-assigned this Apr 21, 2022
@spericas
Copy link
Member Author

Improvement to quickstart MP #4149

@m0mus m0mus removed this from Triage in Backlog Apr 21, 2022
open-api-tools automation moved this from High priority to Closed Apr 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working examples open-api open-api-tools Tracking issues in OpenAPITools generator project P2
Projects
Development

No branches or pull requests

2 participants