OpenAPITools / OpenAPITools/openapi-generator
[BUG] DefaultCodegen.java does not implement legacyDiscriminatorBehavior as documented.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
NOTE! Please scroll down to after the renaming of this issue!
Given the following snippet:
{
"BaseComponent": {
"required": [
"typeAlias"
],
"type": "object",
"properties": {
"typeAlias": {
"minLength": 1,
"type": "string",
"readOnly": true
},
"fieldAlias": {
"type": "string",
"nullable": true
}
},
"additionalProperties": false,
"discriminator": {
"propertyName": "typeAlias",
"mapping": {
"header": "#/components/schemas/HeaderComponent",
"rte": "#/components/schemas/RichTextComponent",
"image": "#/components/schemas/ImageComponent"
}
}
},
"HeaderComponent": {
"required": [
"typeAlias"
],
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/BaseComponent"
}
],
"properties": {
"typeAlias": {
"minLength": 1,
"type": "string",
"readOnly": true
},
"text": {
"type": "string",
"nullable": true
}
},
"additionalProperties": false
}
}
opentools-generator v6.5.0 will generate something like this:

However, I did not intend to have the "HeaderComponent", "ImageComponent" and "RichTextComponent" to be part of the alias-mapping.
My feeling is the $ref back to the BaseComponent throws the generator off. Not sure if it's an issue with the typescript-fetch templates or the generator logic itself.
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 DefaultCodegen.java and compare its legacyDiscriminatorBehavior handling with the generated output from the supplied schema. Then inspect the typescript-fetch templates to determine whether the alias mapping is produced by generator logic or templates. Done means the referenced child schemas are no longer included in the alias mapping under the documented behavior, with a regression case for this schema.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 32/100