-
-
Notifications
You must be signed in to change notification settings - Fork 6.6k
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
[BUG] [JAVA] oneOf generates incorrect model for primitive types #10450
Comments
I see the same with any OneOf, for example: components:
schemas:
IntervalDateRange:
type: object
properties:
foo:
type: string
DurationDateRange:
type: object
properties:
foo:
type: string
Response:
properties:
result:
type: string
Request:
properties:
result:
type: string
client_ip:
oneOf:
- $ref: "#/components/schemas/IntervalDateRange"
- $ref: "#/components/schemas/DurationDateRange" The compilation error is at If there's a dirty workaround for this I'd love to know! |
Can you please try the jersey2 or native library ? e.g. add |
@wing328 I see issues with every library I've tried. More generally I'm not sure how I appreciate that it's somewhat bizarre, but the API I have (from Bloomberg no less!) likes to do things like this:
So perhaps the generator could special-case the scenario where anyOf / allOf has a single item? [More generally what's the prognosis on getting something like this fixed? I'm happy to chip in, and I could even bounty it a little, but I can see you have thousands of open issues so I fear you guys are somewhat swamped!] |
Simplest workaround I found was to preprocess the yaml to zap out / simplify these cases 😢 |
@wing328 I've just researched and known that it's happened for libraries: With |
ive tried both native and jersey2 and the oneof class is not generated. Is there a workaround? Using something like so :
|
Hi @msmerc, are you still willing to bounty a solution here? |
Bug Report Checklist
Description
Using
oneOf
will generate a model with incorrect wrong types.Actual output:
I have three files of models: ClientIp.java, Request,java, Response.java. Request.java has field
private ClientIp clientIp = null;
with type ClientIpExpected output:
I have only two files of models: Request,java, Response.java. Request.java has field
private String clientIp;
with string typeopenapi-generator version
openapi-generator-cli 5.2.1
commit : 8403e59
built : 2021-08-16T12:52:51Z
source : https://github.com/openapitools/openapi-generator
docs : https://openapi-generator.tech/
openapi-generator-cli 5.3.0-SNAPSHOT
commit : de95e2a
built : 2021-09-22T15:38:29+04:00
source : https://github.com/openapitools/openapi-generator
docs : https://openapi-generator.tech/
OpenAPI declaration file content or url
Generation Details
java -jar openapi-generator-cli.jar generate -g java -i oneOfbug.yaml -o .\gen\
Steps to reproduce
Generate a java client using the above yaml.
Related issues/PRs
it little bit similar to #4130
Suggest a fix
The text was updated successfully, but these errors were encountered: