OpenAPITools / OpenAPITools/openapi-generator

[BUG] DefaultCodegen.java does not implement legacyDiscriminatorBehavior as documented.

Open
#15,246 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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:
image

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.