openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG][JAXRS-spec] useOneOfInterfaces option causes compilation error

Open jerui1 opened this issue 2 years ago • 11 comments

Description

When using the useOneOfInterfaces option, the generated code does not compile.

Children classes are OK, but the generated parent is a class instead of an interface.

openapi-generator version

I've reproduces the issue with openapi-generator-maven-plugin : 7.0.1, 7.1.0 6.6.0

The option does not seem supported on previous releases.

OpenAPI declaration file content or url

OpenAPI spec :

https://gist.github.com/jerui1/da605832f67667e32a96f5c4d346640e

Sample maven project to reproduce :

openapigen-oneofbug.zip

Generation Details

mvn clean install

(I've tried using Java 17 or Java 21)

jerui1 avatar Dec 18 '23 13:12 jerui1

Reproduced on openapi-generator v7.2.0

mikeys avatar Jan 23 '24 08:01 mikeys

The issue still occurs with openapi-generator v7.3.0

wanderdev0 avatar Feb 20 '24 12:02 wanderdev0

The same issue also occurs with jaxrs-resteasy generator (--additional-properties=useOneOfInterfaces=true). The expected interface for the oneOf schema is not generated and a class with the same name is generated in its place. However, the classes generated for the subschemas correctly implement the intended interface.

lucadirocco avatar Mar 05 '24 22:03 lucadirocco

This has been open for 6 months without any resolution, is anyone maintaining this?

jamfor999 avatar Jun 11 '24 09:06 jamfor999

This is still an issue in v7.8.0

magiusdarrigo avatar Sep 24 '24 02:09 magiusdarrigo

Likely root cause issue - https://github.com/OpenAPITools/openapi-generator/issues/14166

magiusdarrigo avatar Sep 24 '24 13:09 magiusdarrigo

#14166 doesn't look like the reason for this issue. The useOneOfInterface option works for Spring Server gen as well as for the java clients: feign, google-api-client, resteasy, resttemplate, webclient, restclient, rest-assured, retrofit2, vertx, apache-httpclient Currently it doesn't work for the java clients: microprofile, jersey2, jersey3, native and okhttp-gson.

The issue is coming from the model.mustache file. The clients working don't override it or have the correct part. The clients not working are missing these part:

{{#vendorExtensions.x-is-one-of-interface}}{{>oneof_interface}}{{/vendorExtensions.x-is-one-of-interface}}

I'll provide a pr to fix this soon.

Nicklas2751 avatar Mar 08 '25 00:03 Nicklas2751

@Nicklas2751 , any chances to get this fix in the next release (7.13.0)?

agaidaichuk avatar Apr 25 '25 15:04 agaidaichuk

@agaidaichuk I can't tell you if and when my PR (#20832) gets merged.

Nicklas2751 avatar Apr 25 '25 16:04 Nicklas2751

This issue is still present in v7.21.0 with jaxrs-spec.

I see recent activity in the related PR #20832. Any updates or ETA on when this might be addressed?

senerh avatar Apr 15 '26 07:04 senerh

Luckily I found out that the issue has been fixed in the latest release 7.24.0, hooray! 😄

It's in the release notes (section "Java"): https://github.com/OpenAPITools/openapi-generator/releases/tag/v7.24.0

I also managed to make the code example compile. All you have to do is to use the latest version of openapi-generator-maven-plugin (7.24.0 or higher) and add a dependency to the pom.xml which has become required sometime ago:

        <dependency>
            <groupId>org.openapitools</groupId>
            <artifactId>jackson-databind-nullable</artifactId>
            <version>0.2.6</version>
        </dependency>

RobinKlement avatar Jul 29 '26 12:07 RobinKlement