Skip to content

Invocation Target Exception during code generation #1086

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

Open
dcheng1248 opened this issue Apr 2, 2025 · 11 comments
Open

Invocation Target Exception during code generation #1086

dcheng1248 opened this issue Apr 2, 2025 · 11 comments
Assignees
Labels
area:client This item is related to the client extension

Comments

@dcheng1248
Copy link

dcheng1248 commented Apr 2, 2025

Tell us the extension you're using

Client

I tried this:

I'm not sure if this is really a bug or if I'm doing something wrong. I was using Quarkus v 3.19.4 or later and Quarkus OpenApi Generator v 2.9.0 (I am not sure at which exact versions did the error appear).

This happened:

I got this error during the maven code generation phase:

Quarkus code generation phase has failed: InvocationTargetException: org.openapitools.codegen.CodegenConfig: org.openapitools.codegen.languages.AdaCodegen Unable to get public no-arg constructor: io/swagger/v3/oas/models/media/Schema: io.swagger.v3.oas.models.media.Schema

I expected this:

No response

Is there a workaround?

I had to add the following dependency to get the code generation to work:

 <dependency>
      <groupId>io.swagger.core.v3</groupId>
      <artifactId>swagger-core-jakarta</artifactId>
      <version>${swagger.core.version}</version>
  </dependency>

How can we try to reproduce the issue?

No response

Anything else?

No response

Output of uname -a or ver

Darwin Kernel Version 23.5.0

Output of java -version

openjdk version "21.0.2" 2024-01-16

Quarkus OpenApi version or git rev

2.9.0

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

Apache Maven 3.9.9

Additional information

No response

Community Notes

  • Please vote by adding a 👍 reaction to the issue to help us prioritize.
  • If you are interested to work on this issue, please leave a comment.name: Bug Report 🐞
@ricardozanini
Copy link
Member

OpenAPI 2.9.0 should be used with Quarkus 3.21.

Can you try the 2.9.1-lts version we support on Quarksu 3.20?

@dcheng1248
Copy link
Author

I'm seeing the same error with 2.9.0+3.21 and 2.9.1-tls with 3.20.

I wonder if there may be interfering dependencies. I searched for swagger in the dependency tree of the project and this is the only instance I found. Does smallrye-openapi interfere with the openapi generator?

[INFO] +- io.quarkus:quarkus-smallrye-openapi:jar:3.20.0:compile
[INFO] |  +- io.smallrye:smallrye-open-api-core:jar:4.0.8:compile
[INFO] |  |  +- org.eclipse.microprofile.openapi:microprofile-openapi-api:jar:4.0.2:compile
[INFO] |  |  +- org.eclipse.microprofile.config:microprofile-config-api:jar:3.1:compile
[INFO] |  |  +- io.smallrye:smallrye-open-api-model:jar:4.0.8:compile
[INFO] |  |  +- com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:jar:2.18.2:compile
[INFO] |  |  \- io.smallrye.common:smallrye-common-classloader:jar:2.10.0:compile
[INFO] |  \- io.quarkus:quarkus-swagger-ui:jar:3.20.0:compile

@ricardozanini
Copy link
Member

@dcheng1248, it does! The swagger-open-api-core is a library that translates the specification model used by the generator. So, if you have both, chances are one clashes with the other.

Can you investigate if this library appears in different versions in your classpath? I think we will have to include it in the exclusions section and inherit from Quarkus BOM, as you did in your workaround.

@ricardozanini ricardozanini added the area:client This item is related to the client extension label Apr 3, 2025
@dcheng1248
Copy link
Author

@dcheng1248, it does! The swagger-open-api-core is a library that translates the specification model used by the generator. So, if you have both, chances are one clashes with the other.

Can you investigate if this library appears in different versions in your classpath? I think we will have to include it in the exclusions section and inherit from Quarkus BOM, as you did in your workaround.

Sorry, would you be able to elaborate on this? I'm a bit confused about the explanation and how to look for the information asked. I only see the smallrye-open-api-core under smallrye-openapi in the tree, it seems.

@ricardozanini
Copy link
Member

hmm I took a second look and we have:

➜  deployment git:(issue-1035) mvn dependency:tree | grep swagger-core
[INFO] |  |  +- io.swagger:swagger-core:jar:1.6.15:compile
[INFO] |  |  +- io.swagger.core.v3:swagger-core:jar:2.2.29:compile

Based on (client/deployment/pom.xml):

    <!-- Forces swagger-parser version to avoid conflict with Quarkus.
    This is needed while org.openapitools:openapi-generator doesn't use swagger-parser 2.1.13 or greater -->
    <dependency>
      <groupId>io.swagger.parser.v3</groupId>
      <artifactId>swagger-parser</artifactId>
      <version>${version.io.swagger.parser}</version>
    </dependency>
    ....
        <dependency>
      <groupId>org.openapitools</groupId>
      <artifactId>openapi-generator</artifactId>
      <version>${version.org.openapitools}</version>
      <exclusions>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-simple</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-api</artifactId>
        </exclusion>
        <exclusion>
          <groupId>commons-cli</groupId>
          <artifactId>commons-cli</artifactId>
        </exclusion>
        <exclusion>
          <groupId>commons-logging</groupId>
          <artifactId>commons-logging</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.checkerframework</groupId>
          <artifactId>checker-qual</artifactId>
        </exclusion>
        <exclusion>
          <groupId>jakarta.validation</groupId>
          <artifactId>validation-api</artifactId>
        </exclusion>
        <exclusion>
          <groupId>jakarta.xml.bind</groupId>
          <artifactId>jakarta.xml.bind-api</artifactId>
        </exclusion>
        <exclusion>
          <groupId>joda-time</groupId>
          <artifactId>joda-time</artifactId>
        </exclusion>
        <exclusion>
          <groupId>org.slf4j</groupId>
          <artifactId>slf4j-ext</artifactId>
        </exclusion>
        <!-- Forces swagger-parser version to avoid conflict with Quarkus.
        This is needed while org.openapitools:openapi-generator doesn't use swagger-parser 2.1.13 or greater -->
        <exclusion>
          <groupId>io.swagger.parser.v3</groupId>
          <artifactId>swagger-parser</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

We are removing io.swagger.parser.v3 from the underlying generator and using a version that SHOULD be compatible with Quarkus: 2.1.26.

But I think this version is outdated, and we might have to upgrade it to align with io.quarkus:quarkus-smallrye-openapi

@dcheng1248
Copy link
Author

I did mvn dependency-tree and mvn quarkus:dependency-tree and found swagger core in neither (that is, after I commented out the swagger dependency). I did find swagger-parser 2.1.25 in the latter.

On that note, I also ran into another dependency issue. Reported to quarkus at first but it seems the missing dependency also originates from openapi-generator: quarkusio/quarkus#47147.

I'm not sure if they are related and if there are just some strange dependency clashes somewhere. Please let me know if I can do anything to provide more information. I should be able to respond over this weekend, but won't be available until the next weekend after that.

@ricardozanini
Copy link
Member

@dcheng1248, what is the value for the version in this workaround?

 <dependency>
      <groupId>io.swagger.core.v3</groupId>
      <artifactId>swagger-core-jakarta</artifactId>
      <version>${swagger.core.version}</version>
  </dependency>

@ricardozanini
Copy link
Member

@dcheng1248 can you provide your project as a simpler reproducer?

@ricardozanini ricardozanini self-assigned this Apr 4, 2025
@dcheng1248
Copy link
Author

@dcheng1248, what is the value for the version in this workaround?

io.swagger.core.v3 swagger-core-jakarta ${swagger.core.version}

It's 2.2.28. I'll try to see if I can get a reproducer in this weekend, if not next weekend. Thanks for looking into this.

@dcheng1248
Copy link
Author

@dcheng1248 can you provide your project as a simpler reproducer?

Here it is: https://github.com/dcheng1248/openapi-generator-1086-reproducer

It seems to be a dependency clash within the quarkus-camel-bom. It was fine (also with smallrye-openapi) without this bom, but once I added it the error appeared. I tried quickly looking into the bom source but could not easily locate the swagger core version they are using.

Since it is not actually clashing with quarkus core it probably isn't exactly a bug, although anything that could enhance developer experience (a note in documentation about the clash?) could be helpful. I will leave this issue open for your judgement. Thanks for the help again!

@ricardozanini
Copy link
Member

Thanks for your help, @dcheng1248. I'll try to figure out something about it - maybe a doc like you mentioned or an actual fix. We can leave it open so others can find it in search.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:client This item is related to the client extension
Projects
None yet
Development

No branches or pull requests

2 participants