Skip to content

[BUG][typescript-fetch] OneOf models missing closing parentheses in ToJSONTyped method in some cases #21639

@btpnlsl

Description

@btpnlsl

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

PR #21464 provided some changes to add serialization & deserialization logic for primitive and enum types used by the ToJSONTypes & FromJSONTyped methods of 'oneOf' models.

There are a couple of cases where the if-statements used in the ToJSONTyped methods generated by the template are missing closing parentheses, such as when serializing an Array<number>, Array<string>.

This can be seen in the example provided with the PR:

    if (Array.isArray(value)) {
        // the following line is missing a closing parenthesis
        if (value.every(item => typeof item === 'number') {
            return value;
        }
    }

    if (Array.isArray(value)) {
        // the following line is missing a closing parenthesis
        if (value.every(item => typeof item === 'string') {
            return value;
        }
    }
openapi-generator version

current version of master branch (as of commit ef22749)

OpenAPI declaration file content or url

issue_21259.yaml

Generation Details

Generate code using the unit test in TypeScriptFetchClientCodegenTest.givenSchemaIsOneOfAndComposedSchemasArePrimitiveThenReturnStatementsAreCorrect

Steps to reproduce

See above

Related issues/PRs

#21259 - @DavidGrath

Suggest a fix

modelOneOf.mustache in the typescript generator needs to be fixed to add closing parenthesis for these cases.
The unit test needs to be modified to check for the correct number of close parenthesis or an integration test needs to be created that exercises the code.

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