quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.82k stars 2.69k forks source link

Swagger API requests default constructor for Jax-RS Resource #23482

Closed Denistr closed 2 years ago

Denistr commented 2 years ago

Describe the bug

Quarkus 2.7.0 Final (On 2.4.0.Final it is also reproducable)

Project for reproduce: https://github.com/Denistr/openapi-quarkusFruits

I have constructor for JAX-RS Resource

 @Inject
    public FruitResource(First first, Second second) {
        this.first=first;
        this.second=second;
    }

And there is no default constructor, while I have swagger's annotation - @Api(value = "/fruits") At starting of application, I'm getting

2022-02-07 16:53:15,019 ERROR [io.qua.dep.dev.IsolatedDevModeMain] (main) Failed to start quarkus: java.lang.RuntimeException: java.lang.RuntimeException: RESTEASY003190: Could not find constructor for class: org.acme.openapi.swagge
rui.FruitResource
        at io.quarkus.dev.appstate.ApplicationStateNotification.waitForApplicationStart(ApplicationStateNotification.java:51)
        at io.quarkus.runner.bootstrap.StartupActionImpl.runMainClass(StartupActionImpl.java:122)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.firstStart(IsolatedDevModeMain.java:145)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:456)
        at io.quarkus.deployment.dev.IsolatedDevModeMain.accept(IsolatedDevModeMain.java:67)
        at io.quarkus.bootstrap.app.CuratedApplication.runInCl(CuratedApplication.java:150)
        at io.quarkus.bootstrap.app.CuratedApplication.runInAugmentClassLoader(CuratedApplication.java:106)
        at io.quarkus.deployment.dev.DevModeMain.start(DevModeMain.java:132)
        at io.quarkus.deployment.dev.DevModeMain.main(DevModeMain.java:62)
Caused by: java.lang.RuntimeException: RESTEASY003190: Could not find constructor for class: org.acme.openapi.swaggerui.FruitResource

Expected behavior

JAX-RS resources will be initialized without default mandatory constructor

Actual behavior

2022-02-07 16:53:15,019 ERROR [io.qua.dep.dev.IsolatedDevModeMain] (main) Failed to start quarkus: java.lang.RuntimeException: java.lang.RuntimeException: RESTEASY003190: Could not find constructor for class: org.acme.openapi.swagge rui.FruitResource

How to Reproduce?

No response

Output of uname -a or ver

Microsoft Windows [Version 10.0.19044.1466]

Output of java -version

openjdk version "11" 2018-09-25 OpenJDK Runtime Environment 18.9 (build 11+28) OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.7.0. Final

Build tool (ie. output of mvnw --version or gradlew --version)

Maven home: C:\Tools\apache-maven-3.8.3 Java version: 11, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-11 Default locale: en_US, platform encoding: Cp1252 OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

Additional information

No response

quarkus-bot[bot] commented 2 years ago

/cc @MikeEdgar, @phillip-kruger

phillip-kruger commented 2 years ago

Have you tried with OpenAPI rather than Swagger ? So use the annotation from MicroProfile Open API by including the smallrye-openapi extension and remove:

<dependency>
      <groupId>io.swagger</groupId>
      <artifactId>swagger-annotations</artifactId>
      <version>1.5.16</version>
    </dependency>
Denistr commented 2 years ago

It's demo app, which I built similar to my work app. Work app is a bit complex and consists of a lot 3rd party libs. I can not introduce quarkus' specific things there, only pure CDI, swagger etc.

phillip-kruger commented 2 years ago

It's not Quarkus specific, it's MicroProfile. But in the case you need swagger you might need to add reflection config for swagger lib classes.

Denistr commented 2 years ago

It works with

<dependency>
      <groupId>org.eclipse.microprofile.openapi</groupId>
      <artifactId>microprofile-openapi-api</artifactId>
      <version>3.0</version>
    </dependency>

Does it mean swagger won't be fully supported in Quarkus OOB?

phillip-kruger commented 2 years ago

We might add support for the swagger api/annotations in SmallRye OpenAPI (https://github.com/smallrye/smallrye-open-api/issues/752) , but it's a duplicate, OpenAPI supports all things in Swagger. Also, you do not need to add the MicroProfile api as it will be pulled in by the quarkus openapi extension (that you already have)

phillip-kruger commented 2 years ago

Closing. Please reopen if needed

pindaroli commented 1 year ago

config

An example please?