Skip to content

[BUG][TYPESCRIPT-FETCH] Bug generating Typescript when array has both "items" and "properties" attributes #21680

@galamome

Description

@galamome

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

Code generated with typescript-fetch generator is faulty when the OpenAPI specification contains an array type that has both properties and items attributes.

openapi-generator version

7.14.0

OpenAPI declaration file content or url
<script src="https://gist.github.com/galamome/e8a64d748f442bd23ed17841480a7b20.js"></script>
Generation Details
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-g typescript-fetch \
--additional-properties=supportES6=true,npmVersion=6.9.0,typescriptThreePlus=true \
-i ~/buildDev/bug_openapi/interface/openapi.json \
-o ~/buildDev/bug_openapi/typescript-client-test
Steps to reproduce

The file typescript-client-test/models/Errors.ts generated is faulty: Array&lt;ModelError&gt;FromJSON

export function ErrorsFromJSONTyped(json: any, ignoreDiscriminator: boolean): Errors {
    if (json == null) {
        return json;
    }
    return {        
        'errors': json['errors'] == null ? undefined : Array&lt;ModelError&gt;FromJSON(json['errors']),
    };
}

and

export function ErrorsToJSONTyped(value?: Errors | null, ignoreDiscriminator: boolean = false): any {
    if (value == null) {
        return value;
    }

    return {
        
        'errors': Array&lt;ModelError&gt;ToJSON(value['errors']),
    };
}
Related issues/PRs

No related issue found.

Suggest a fix

It seems that having both properties and items in an array type is valid, but the properties should be ignored.

If so, the code generated should be the same as the one generated by the OpenAPI Specification that does not have the properties attribute:

<script src="https://gist.github.com/galamome/ad0a885dd45d3833139a79354e214dd6.js"></script>

The desired generated code:

<script src="https://gist.github.com/galamome/c21c0e5c6145bf7103932020c2d97671.js"></script>

REMARK: I have tried to generate for both specifications (with and without properties attribute) with other generators. For C# language (csharp-functions generator) the models generated are exactly the same. For Java however the generated classes are not the same.

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