[BUG][java] oneOf in "anonymous" schemas: model not generated.
Created by: jfeltesse-mdsol
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: cc09118f
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.java
featuresimport org.openapitools.client.model.GetState200; import org.openapitools.client.model.ObjAOrObjB;
GetState200
model is not present insrc/main/java/org/openapitools/client/model
whileObjAOrObjB
is.
@bbdouglas @sreeshas @jfiala @lukoyanov @cbornet @jeff9finger @karismann @Zomzog @lwlee2608 @bkabrda