Skip to content

[BUG] [typescript] [axios, fetch, nestjs] additionalProperties array of enums references invalid enum name 'inner' #20877

@shaun-jacks

Description

@shaun-jacks

Bug Report Checklist

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

For typescript models generated,

an array of inline enums within additionalProperties references an enum name that does not exist in the code "Inner".

This can be reproduced with typescript clients such as typescript-nestjs given a model that looks like

"TestResponse": {
        "type": "object",
        "properties": {
          "test": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "string",
                "enum": ["TEST"]
              }
            }
          }
      }
}
openapi-generator version

7.13.0-SNAPSHOT

OpenAPI declaration file content or url

https://gist.githubusercontent.com/shaun-jacks/7867ddaa45841edfc37ce4079c7693a4/raw/36a3484905383fa5f98c5032349e6f488a535314/gistfile1.txt

Essentially with any model like:

"components": {
    "schemas": {
      "TestResponse": {
        "type": "object",
        "properties": {
          "test": {
            "type": "object",
            "additionalProperties": {
              "type": "array",
              "items": {
                "type": "string",
                "enum": ["TEST"]
              }
            }
          }
        }
      }
    }
  }
Generation Details
Typescript NestJs
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
   -i https://gist.githubusercontent.com/shaun-jacks/7867ddaa45841edfc37ce4079c7693a4/raw/36a3484905383fa5f98c5032349e6f488a535314/gistfile1.txt \
   -g typescript-nestjs \
   -o ./typescript-nestjs
Typescript Axios
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
   -i https://gist.githubusercontent.com/shaun-jacks/7867ddaa45841edfc37ce4079c7693a4/raw/36a3484905383fa5f98c5032349e6f488a535314/gistfile1.txt \
   -g typescript-axios \
   -o ./typescript-axios
Typescript fetch
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
   -i https://gist.githubusercontent.com/shaun-jacks/7867ddaa45841edfc37ce4079c7693a4/raw/36a3484905383fa5f98c5032349e6f488a535314/gistfile1.txt \
   -g typescript-fetch \
   -o ./typescript-fetch
Steps to reproduce

Given the generation details, observe the models, for instance

Typescript NestJs
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
   -i https://gist.githubusercontent.com/shaun-jacks/7867ddaa45841edfc37ce4079c7693a4/raw/36a3484905383fa5f98c5032349e6f488a535314/gistfile1.txt \
   -g typescript-nestjs \
   -o ./typescript-nestjs
Actual Output
/**
 * Test title
 * Test description
 *
 * The version of the OpenAPI document: version
 * 
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


export interface TestResponse { 
    test?: { [key: string]: Array<InnerEnum>; };
}
export namespace TestResponse {
    export type TestEnum = 'TEST';
    export const TestEnum = {
        Test: 'TEST' as TestEnum
    };
}

Notice how the TestResponse has Array<InnerEnum> and InnerEnum is not imported and does not exist anywhere.

Expected Output
/**
 * Test title
 * Test description
 *
 * The version of the OpenAPI document: version
 * 
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 */


export interface TestResponse { 
    test?: { [key: string]: Array<TestResponse.TestEnum>; };
}
export namespace TestResponse {
    export type TestEnum = 'TEST';
    export const TestEnum = {
        Test: 'TEST' as TestEnum
    };
}
Typescript Axios
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
   -i https://gist.githubusercontent.com/shaun-jacks/7867ddaa45841edfc37ce4079c7693a4/raw/36a3484905383fa5f98c5032349e6f488a535314/gistfile1.txt \
   -g typescript-axios \
   -o ./typescript-axios
/**
 * 
 * @export
 * @interface TestResponse
 */
export interface TestResponse {
    /**
     * 
     * @type {{ [key: string]: Array<string>; }}
     * @memberof TestResponse
     */
    'test'?: { [key: string]: Array<InnerEnum>; };
}

Same observation for other typescript clients!

Notice how the TestResponse has Array<InnerEnum> and InnerEnum is not imported and does not exist anywhere.

Related issues/PRs

#20790

Suggest a fix

When running with debugModels, here is some example output for typescript-nestjs

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
   -i https://gist.githubusercontent.com/shaun-jacks/7867ddaa45841edfc37ce4079c7693a4/raw/36a3484905383fa5f98c5032349e6f488a535314/gistfile1.txt \
   -g typescript-nestjs \
   -o ./typescript-nestjs --global-property debugModels
"mostInnerItems" : {
        "openApiType" : "string",
        "baseName" : "inner",
        "getter" : "getInner",
        "setter" : "setInner",
        "dataType" : "string",
        "datatypeWithEnum" : "InnerEnum",
        "name" : "inner",
        "defaultValue" : "undefined",
        "defaultValueWithParam" : " = data.inner;",
        "baseType" : "string",
        "example" : "null",
        "jsonSchema" : "{\n  \"enum\" : [ \"TEST\" ],\n  \"type\" : \"string\"\n}",
        "exclusiveMinimum" : false,
        "exclusiveMaximum" : false,
        "required" : false,

Notice how the baseName is inner, and datatypeWithEnum is InnerEnum

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