swagger-api / swagger-api/swagger-codegen
[JAVA] Bug array of oneOf uses concrete type instead of interface
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
reference to oneOf uses concrete type instead of interface
Swagger-codegen version
3.0.14 (can't get master to work due to jackson/yaml parsing issues)
Swagger declaration file content or url
TypeA:
properties:
nameA:
type: string
TypeB:
properties:
nameB:
type: string
WrapperType:
oneOf:
- $ref: '#/components/schemas/TypeA'
- $ref: '#/components/schemas/TypeB'
RootType:
properties:
reference:
type: array
items:
$ref: '#/components/schemas/WrapperType'
Command line used for generation
java -jar swagger-codegen-cli-3.0.14.jar generate -l spring -i test_swagger.yaml -o project
Steps to reproduce
- Include the above in an OpenAPI contract such as https://gist.github.com/andrewbasterfield/774fa272d4de8da2e239acd1799bf5b5
- generate as java/spring
- Observe that java classes
TypeA,TypeBandWrapperTypeall implementOneOfWrapperTypebutRootType.referenceisList<WrapperType>notList<OneOfWrapperType>. TypeA or TypeB cannot be injected into a relationship withRootType.
if one eliminates intermediate WrapperType entirely as
TypeA:
properties:
nameA:
type: string
TypeB:
properties:
nameB:
type: string
RootType:
properties:
reference:
type: array
items:
oneOf:
- $ref: '#/components/schemas/TypeA'
- $ref: '#/components/schemas/TypeB'
Then RootType.reference degrades further to List<Object> however this is the only way we can have a relationship of TypeA or TypeB to RootType in this loosest possible sense
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with the provided OpenAPI YAML and the swagger-codegen-cli 3.0.14 command using the spring generator. Trace Java/Spring model type resolution for array items containing oneOf, then verify that RootType.reference is generated as List and that inline oneOf handling is not reduced to List.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100