OpenAPITools / OpenAPITools/openapi-generator
[BUG] [JAVA] Generating wrong constructor
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
I use the openapi generator to generate code from an official tmf669 specification.
Here is the part of it that makes problems:
The generated constructor doesn't pass the "name" field to the super object and so the name field is always null after the mapping:
openapi-generator version
7.22.0
OpenAPI declaration file content or url
{
"components": {
"schemas": {
"EntitySpecification": {
"allOf": [
{
"$ref": "#/components/schemas/Entity"
},
{
"type": "object",
"description": "EntitySpecification is a class that offers characteristics to describe a type of entity. Entities are generic constructs that may be used to describe bespoke business entities that are not effectively covered by the existing SID model.\nFunctionally, the entity specification acts as a template by which entities may be instantiated and described. By sharing the same specification, these entities would therefore share the same set of characteristics.\nNote: The ‘configurable’ attribute on the specCharacteristics determines if an entity instantiated from the entity specification can override the value of the attribute. When set to false, the entity instance may not define a value that differs from the value in the specification.",
"properties": {
"name": {
"type": "string",
"description": "Name given to the specification"
},
"description": {
"type": "string",
"description": "Description of the specification"
},
"lastUpdate": {
"type": "string",
"format": "date-time",
"description": "Date and time of the last update of the specification"
},
"lifecycleStatus": {
"type": "string",
"description": "Used to indicate the current lifecycle status of this catalog item"
},
"isBundle": {
"type": "boolean",
"description": "isBundle determines whether specification represents a single specification (false), or a bundle of specifications (true)."
},
"validFor": {
"$ref": "common/common-schemas.json#/components/schemas/TimePeriod"
},
"version": {
"type": "string",
"description": "specification version"
},
"attachment": {
"type": "array",
"description": "Attachments that may be of relevance to this specification, such as picture, document, media",
"items": {
"$ref": "#/components/schemas/AttachmentRefOrValue"
}
},
"targetEntitySchema": {
"$ref": "#/components/schemas/TargetEntitySchema"
},
"specCharacteristic": {
"type": "array",
"description": "List of characteristics that the entity can take",
"items": {
"$ref": "#/components/schemas/CharacteristicSpecification"
}
},
"relatedParty": {
"type": "array",
"description": "Parties who manage or otherwise have an interest in this specification",
"items": {
"$ref": "#/components/schemas/RelatedPartyRefOrPartyRoleRef"
}
},
"constraint": {
"description": "This is a list of constraint references applied to this specification",
"type": "array",
"items": {
"$ref": "#/components/schemas/ConstraintRef"
}
},
"entitySpecRelationship": {
"type": "array",
"description": "Relationship to another specification",
"items": {
"$ref": "#/components/schemas/EntitySpecificationRelationship"
}
}
}
}
],
"discriminator": {
"propertyName": "@type",
"mapping": {
"EntitySpecification": "#/components/schemas/EntitySpecification",
"PartyRoleSpecification": "#/components/schemas/PartyRoleSpecification"
}
}
},
"PartyRoleSpecification": {
"allOf": [
{
"$ref": "#/components/schemas/EntitySpecification"
},
{
"type": "object",
"description": "Party role specification. A party role specification gives additional details on the part played by a party in a given context.",
"properties": {
"agreementSpecification": {
"type": "array",
"items": {
"$ref": "#/components/schemas/AgreementSpecificationRef"
}
},
"permissionSpecificationSet": {
"type": "array",
"items": {
"$ref": "#/components/schemas/PermissionSpecificationSetRef"
}
},
"status": {
"type": "string",
"description": "Used to track the lifecycle status of the partyRoleSpecification."
}
},
"required": [
"name"
]
}
]
}
}
}
}
The generated constructor:
/**
* Constructor with only required parameters
*/
public PartyRoleSpecificationDto(String atType, String name) {
super(atType);
}
Generation Details
xml:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator-maven-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/tardis/openapi/tmf669.json
</inputSpec>
<generatorName>spring</generatorName>
<modelNameSuffix>Dto</modelNameSuffix>
<configOptions>
<dateLibrary>legacy</dateLibrary>
<enumPropertyNaming>legacy</enumPropertyNaming>
<generatePom>false</generatePom>
<interfaceOnly>true</interfaceOnly>
<skipDefaultInterface>true</skipDefaultInterface>
<apiPackage>org.tmf669.api</apiPackage>
<modelPackage>org.tmf669.model</modelPackage>
<useSpringBoot4>true</useSpringBoot4>
<useJackson3>true</useJackson3>
<library>spring-http-interface</library>
<annotationLibrary>none</annotationLibrary>
<documentationProvider>none</documentationProvider>
<containerDefaultToNull>true</containerDefaultToNull>
</configOptions>
<generateSupportingFiles>false</generateSupportingFiles>
<generateApiTests>false</generateApiTests>
</configuration>
</execution>
</executions>
</plugin>
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 with the supplied EntitySpecification and PartyRoleSpecification schemas using the Spring generator configuration, then inspect how required inherited properties are handled in the generated PartyRoleSpecificationDto constructor. Done means the generated constructor passes both atType and name to the appropriate superclass constructor, with a regression test covering this schema inheritance case.
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
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100