OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA|SPRING] Properties duplicated in inheritance chain
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug 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
Properties are duplicated instead of inherited, if inheritance is redeclared.
openapi-generator version
7.7.0
OpenAPI declaration file content
openapi: 3.0.1
info:
title: "BugSample"
version: SNAPSHOT-1
paths: {}
components:
schemas:
Extensible:
type: object
properties:
'@type':
type: string
'baseType':
type: string
ErrorMessage:
allOf:
- $ref: "#/components/schemas/Extensible"
- type: object
properties:
chuck:
type: string
discriminator:
propertyName: '@type'
mapping:
ErrorMessage: '#/components/schemas/ErrorMessage'
ProductOrderErrorMessage: '#/components/schemas/SpecialErrorMessage'
SpecialErrorMessage:
allOf:
- $ref: "#/components/schemas/Extensible"
- $ref: "#/components/schemas/ErrorMessage"
- type: object
properties:
norris:
type: string
Generation Details
docker run --rm -v $PWD:/local openapitools/openapi-generator-cli generate -i /local/bugSample.yaml -g spring -o /local/out
Steps to reproduce
- Create a sample with at least 3 levels of inheritance A > B > C
- Declare B as inheritance root via discriminator mapping
- Declare C as allOf A and B explicitly
- Generate Java or Spring sources. (I assume this is similar for other typed languages,. not tested)
Expectation
For my example, I expect SpecialErrorMessage to only declare property norris.
Actual
SpecialErrorMessage redeclares atType, atBaseType
Workaround
Don't duplicate composition in allOf. Patch the specs.
On the downside, this is sometimes not obvious in more complicated specs and not ideal, if you're not the owner of the spec. I work with an external party that applies the Design guideline to require re-declaration of Extensible Schema explicitly, because they use it to communicate all Schemas that support further extension.
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/issues/6117 is similar, but only covers flat, simple inheritance.
Suggest a fix
If you point me in the right direction, I'd try to create a PR
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
Start with the bugSample.yaml declaration shown in the issue and run the provided Docker Spring generator command. Inspect the generated SpecialErrorMessage and its inheritance-related model generation; the work is done when it declares only norris rather than duplicating inherited properties such as @type and baseType.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100