[BUG][Java] OneOf-Class not generated
See original GitHub issueBug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What’s the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The OpenAPI Generator v5.3.1 & 5.3.0 does not generate a OneOf-Model-Class which results in the code not being able to be built. I found the exact same issue in Java jersey2, Java native (and Rust reqwest). This confuses me as the Java generators are supposed to support OneOf (https://github.com/OpenAPITools/openapi-generator/pull/10463#discussion_r717187400 and https://github.com/OpenAPITools/openapi-generator/pull/7263). I expected the Generator to support OneOf in Java as these two links say.
openapi-generator version
5.3.1 & 5.3.0
OpenAPI declaration file content or url
https://raw.githubusercontent.com/jdegre/5GC_APIs/master/TS29510_Nnrf_NFManagement.yaml
Generation Details
(Jersey2) java -jar openapi-generator-cli-5.3.1-20211116.151401-16.jar generate -i Desktop/5GC_APIs/TS29510_Nnrf_NFManagement.yaml -g java -o Desktop/NRFManagement_java_jersey2 --library jersey2 --additional-properties=packageName=nfmanagement
OR
(Native) java -jar openapi-generator-cli-5.3.1-20211116.151401-16.jar generate -i Desktop/5GC_APIs/TS29510_Nnrf_NFManagement.yaml -g java -o Desktop/NRFManagement_java_native --library native --additional-properties=packageName=nfmanagement
Steps to reproduce
- Generate Code of NFManagement with OpenAPI Generator (with Generation Details above)
- Try to build it
- Search for Error “Cannot resolve symbol ‘OneOfNfInstanceIdCondNfInstanceIdListCondNfTypeCondServiceNameCondAmfCondGuamiListCondNetworkSliceCondNfGroupCondNfSetCondNfServiceSetCondUpfCondScpDomainCondNwdafCondNefCondDccfCond’”
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/issues/9791 https://github.com/OpenAPITools/openapi-generator/issues/10514 https://github.com/OpenAPITools/openapi-generator/issues/9981
Suggest a fix
The error is caused by “TS29510_Nnrf_NFManagement.yaml” line 1449-1465. Might be worth looking into.
subscrCond:
oneOf:
- $ref: '#/components/schemas/NfInstanceIdCond'
- $ref: '#/components/schemas/NfInstanceIdListCond'
- $ref: '#/components/schemas/NfTypeCond'
- $ref: '#/components/schemas/ServiceNameCond'
- $ref: '#/components/schemas/AmfCond'
- $ref: '#/components/schemas/GuamiListCond'
- $ref: '#/components/schemas/NetworkSliceCond'
- $ref: '#/components/schemas/NfGroupCond'
- $ref: '#/components/schemas/NfSetCond'
- $ref: '#/components/schemas/NfServiceSetCond'
- $ref: '#/components/schemas/UpfCond'
- $ref: '#/components/schemas/ScpDomainCond'
- $ref: '#/components/schemas/NwdafCond'
- $ref: '#/components/schemas/NefCond'
- $ref: '#/components/schemas/DccfCond'
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:6 (2 by maintainers)
Top GitHub Comments
It looks as if there’s a problem with
oneOf
support for properties; as the summary indicates, the generator fails to generate the appropriate wrapper class to wrap the individual data classes.A workaround seems to be to rewrite the spec file to introduce an explicit wrapper class. The class can use
oneOf
successfully.For example, we had:
This caused code to be generated with a missing class with an extremely long name starting
OneOf
. I added an explicit wrapper:…and the generated code (with
--library jersey2
) then includes an implementation of CredentialFields which tries deserializing to the alternatives in turn. Everything compiles.OneOf-Model-Classes are generating without any issue with openapi-generator-cli-6.2.1. It seems this issue has been resolved now.