openapi-generator: [BUG][java] oneOf in "anonymous" schemas: model not generated.
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- What’s the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- What’s the actual output vs expected output?
- [Optional] Bounty to sponsor the fix (example)
Description
As mentioned in #5706, if the openapi spec file defines a oneOf schema in responses “as is”, the generator references a model in the DefaultApi but the model doesn’t get generated. See examples below. edit: the same issue happens to all the places where oneOf is used without being directly under a named schema (e.g. responses, array items etc.). See the comments.
openapi-generator version
latest master: cc09118ffc2f13ca5d251049dc3d7552f08b670a
OpenAPI declaration file content or url
OpenApi spec file:
openapi: 3.0.3
info:
title: oneOf test
version: '1.0'
paths:
/state:
get:
operationId: getState
responses:
'200':
description: get states
content:
application/json:
schema: # doesn't work
oneOf:
- $ref: '#/components/schemas/ObjA'
- $ref: '#/components/schemas/ObjB'
discriminator:
propertyName: realtype
/state_ref:
get:
operationId: getStateRef
responses:
'200':
description: 'get states using $ref'
content:
application/json:
schema: # logically same as above but works
$ref: '#/components/schemas/ObjAOrObjB'
components:
schemas:
ObjA:
type: object
properties:
realtype:
type: string
message:
type: string
ObjB:
type: object
properties:
realtype:
type: string
code:
type: integer
ObjAOrObjB:
oneOf:
- $ref: '#/components/schemas/ObjA'
- $ref: '#/components/schemas/ObjB'
discriminator:
propertyName: realtype
Command line used for generation
openapi-generator generate -i spec.yaml -g java --library native -o ./out/java_oneof
Steps to reproduce
- use spec file above
- run command above
- notice how
src/main/java/org/openapitools/client/api/DefaultApi.javafeatures
but theimport org.openapitools.client.model.GetState200; import org.openapitools.client.model.ObjAOrObjB;GetState200model is not present insrc/main/java/org/openapitools/client/modelwhileObjAOrObjBis.
@bbdouglas @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger @karismann @Zomzog @lwlee2608 @bkabrda
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 6
- Comments: 16 (13 by maintainers)
@wing328 @spacether should this issue also be labelled “inline schema handling”?
@jfeltesse-mdsol I think it’s a limitation in the inline model/schema resolver when handling oneOf that’s defined inline.
For our projects we decided to go through the jersey2 library path. Multiple PRs were raised and merged, not all of them related to oneOf, but you could take a look at some of them to see how the work was done for jersey2 and propose something similar for the native library.
#7115 #6956 #6954 #6933 #6925 #6784 #6606 #6632 #6633 #6634 #6637 #6636 #6646 #6647 #6695 #6551 #6518 #6508 #6463 #6476 #6495