OpenAPITools / OpenAPITools/openapi-generator
[BUG][SPRINGBOOT] The class is generated without extends parent
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
I want to generate a class inheritated from imported external class.
In gradle task im using importMappings to import generated class from another yaml file.
In yaml file im using allOf and $ref to that class.
Class will be generated with import to that class but without of extends keyword.
openapi-generator version
7.11.0
OpenAPI declaration file content or url
https://gist.github.com/p-migda/c32e0e2623024a00cd068343cc6c25d2
https://gist.github.com/p-migda/f9c211cfb5849cd3cc32841b3d0f63b4
Generation Details
using openapi-generator-gradle-plugin:
tasks.register('generateParent', GenerateTask) {
skipOperationExample = true
generatorName = 'spring'
inputSpec = "$projectDir/exampleParent.yaml"
outputDir = "$projectDir"
apiPackage = 'org.example.document.generated.api'
modelPackage = 'org.example.document.generated.model'
configOptions = [
'useSpringBoot3' : 'true',
'interfaceOnly' : 'true',
'serializationLibrary' : 'jackson',
'dateLibrary' : 'java8',
'library' : 'spring-boot',
'sourceFolder' : targetFolder,
'bigDecimalAsString' : 'false',
'additionalModelTypeAnnotations': ';@com.fasterxml.jackson.annotation.JsonInclude(' +
'com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL);' +
'@com.fasterxml.jackson.annotation.JsonIgnoreProperties(ignoreUnknown = true);' +
'@lombok.NoArgsConstructor;',
]
additionalProperties = [
generatedConstructorWithRequiredArgs: 'false'
]
}
tasks.register('generateChild', GenerateTask) {
dependsOn generateParent
skipOperationExample = true
generatorName = 'spring'
inputSpec = "$projectDir/example.yaml"
outputDir = "$projectDir"
apiPackage = 'org.example.document.generated.api'
modelPackage = 'org.example.document.generated.model'
configOptions = [
'useSpringBoot3' : 'true',
'interfaceOnly' : 'true',
'serializationLibrary' : 'jackson',
'dateLibrary' : 'java8',
'library' : 'spring-boot',
'sourceFolder' : targetFolder,
'bigDecimalAsString' : 'false',
'additionalModelTypeAnnotations': ';@com.fasterxml.jackson.annotation.JsonInclude(' +
'com.fasterxml.jackson.annotation.JsonInclude.Include.NON_NULL);' +
'@com.fasterxml.jackson.annotation.JsonIgnoreProperties(ignoreUnknown = true);' +
'@lombok.NoArgsConstructor;',
]
additionalProperties = [
generatedConstructorWithRequiredArgs: 'false'
]
importMappings = [
'ParentClass': 'org.example.document.generated.model.ParentClass'
]
}
Steps to reproduce
Just run a gradleTask
Suggest a fix
Maybe something wrong is with setting a parent marker when parent class is imported from outside of file.
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
Run the generateParent and generateChild Gradle tasks with the linked exampleParent.yaml and example.yaml specifications. Trace the Spring generator's handling of allOf, $ref, and importMappings when generating the child model. Done means the generated child class imports ParentClass and also extends it when the parent comes from the separately generated specification.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring-boot
- Domain
- backend-api-design, build-system, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100