payara / Payara

Payara Server is an open source middleware platform that supports reliable and secure deployments of Java EE (Jakarta EE) and MicroProfile applications in any environment: on premise, in the cloud or hybrid.
http://www.payara.fish
Other
884 stars 307 forks source link

Bug Report: OpenAPI @Parameter(... explode = Explode.???) gives stacktrace/FISH-5798 #5436

Open mb-dbc-dk opened 3 years ago

mb-dbc-dk commented 3 years ago

When writing OpenAPI documentation and a repeated query-parameter is wanted OpenAPI generation fails.

Using

@Parameter(name = "name", description = "The name(s)", required = false,
                   schema = @Schema(type = SchemaType.ARRAY, implementation = String.class),
                   explode = Explode.TRUE)

to describe a repeated parameter (ie. ?name=a&name=b&name=c). A valid openapi yaml is expected on /openapi

Expected Outcome

Status 200 from /openapi

Current Outcome

Status 500 from /openapi and this stacktrace:

StandardWrapperValve[microprofile-openapi-servlet]: Servlet.service() for servlet microprofile-openapi-servlet threw exception
java.lang.ClassCastException: class org.glassfish.hk2.classmodel.reflect.impl.EnumModelImpl cannot be cast to class java.lang.Boolean (org.glassfish.hk2.classmodel.reflect.impl.EnumModelImpl is in unnamed module of loader fish.payara.micro.boot.loader.ExplodedURLClassloader @7699a589; java.lang.Boolean is in module java.base of loader 'bootstrap')
    at fish.payara.microprofile.openapi.impl.model.parameters.ParameterImpl.createInstance(ParameterImpl.java:102)
    at fish.payara.microprofile.openapi.impl.processor.ApplicationProcessor.visitParameters(ApplicationProcessor.java:949)
    at fish.payara.microprofile.openapi.impl.visitor.OpenApiWalker.processAnnotation(OpenApiWalker.java:172)
    at fish.payara.microprofile.openapi.impl.visitor.OpenApiWalker.processAnnotation(OpenApiWalker.java:136)
    at fish.payara.microprofile.openapi.impl.visitor.OpenApiWalker.accept(OpenApiWalker.java:124)
...

Steps to reproduce

Environment

Culprit?

https://github.com/payara/Payara/blob/95e95b5714575484c1b8fa6dea665b029450ac5c/appserver/payara-appserver-modules/microprofile/openapi/src/main/java/fish/payara/microprofile/openapi/impl/model/parameters/ParameterImpl.java#L102

But annotation is from:

@Target({ ElementType.PARAMETER, ElementType.METHOD, ElementType.FIELD })
@Retention(RetentionPolicy.RUNTIME)
@Repeatable(Parameters.class)
@Inherited
public @interface Parameter {
...
     * @return whether or not to expand individual array members
     **/
    Explode explode() default Explode.DEFAULT;

...

So I would expect something about EnumModel.class like the parameter "in", instead of Boolean.class.

shub8968 commented 3 years ago

Hi, @mb-dbc-dk. I am able to reproduce this issue. I have raised an internal issue with JIRA FISH-5978. Thanks. It may take a while to fix the issue. You are free to submit a PR to fix this issue if you feel confident to do so.