Skip to content

[BUG][typescript-fetch] Default case for oneOf serialization method returning undefined variable. #21668

@cgual206

Description

@cgual206

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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

@ThorinEk reported a problem the discussion on Issue 21587 that relates to the default case in the switch statement generated for a oneOf model when the model has a discriminator.

export function ExecuteCommandPostRequestToJSONTyped(value?: ExecuteCommandPostRequest | null, ignoreDiscriminator: boolean = false): any {
    if (value == null) {
        return value;
    }
    switch (value['command']) {
        ...  // removed
        default:
            // this should be return value since the variable json is undefined.
            return json;
    }
}

It looks like this bug was introduced in the PR for #20983

openapi-generator version

Latest master version

OpenAPI declaration file content or url

See OAS spec in this comment

Generation Details

Using typescript-fetch generator

Steps to reproduce

java -jar openapi-generator-cli.jar generate -g typescript-fetch -o output -i openapi-spec.json

Related issues/PRs

#21587 - bug mentioned here
#20983 - bug introduced

Suggest a fix

This should be a one line fix to change return json; to return value;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions