Skip to content

[BUG] [JAVA] Generating wrong constructor #23918

@PaKu5

Description

@PaKu5
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>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions