Skip to content

str:str dictionary generates str:str|undefined dictionary in v7.0.0 #1732

Closed
@WarpedPixel

Description

@WarpedPixel

Description

A dictionary of string -> string defined in the openapi.json spec, generates a string -> string | undefined dictionary in Typescript. This worked as expected with 6.7.7.

src/routes/profile-page.vue:84:51 - error TS2322: Type 'string | undefined' is not assignable to type 'string'.
  Type 'undefined' is not assignable to type 'string'.

             state.languageArray.push({value: key, title: data.languages[key]})
Name Version
openapi-typescript 7.0.0
Node.js v20.14.0
OS + version macOS 14.5

Reproduction

Excerpts from openapi.json

"/api/languages": {
    "get": {
        "tags": [
            "root"
        ],
        "summary": "Get Languages",
        "description": "Returns the list of supported languages and their display names in each native language.\nLanguages are IANA language tags with optional territory codes (e.g. 'en', 'en_US', 'pt', 'pt_BR', etc.).\nLanguage names are in each native language or in a specific language if passed in the `lang` parameter).",
        "operationId": "get_languages_api_languages_get",
        "parameters": [
            {
                "name": "lang",
                "in": "query",
                "required": false,
                "schema": {
                    "anyOf": [
                        {
                            "type": "string"
                        },
                        {
                            "type": "null"
                        }
                    ],
                    "title": "Lang"
                }
            }
        ],
        "responses": {
            "200": {
                "description": "Successful Response",
                "content": {
                    "application/json": {
                        "schema": {
                            "$ref": "#/components/schemas/SupportedLanguages"
                        }
                    }
                }
            },
            "422": {
                "description": "Validation Error",
                "content": {
                    "application/json": {
                        "schema": {
                            "$ref": "#/components/schemas/HTTPValidationError"
                        }
                    }
                }
            }
        }
    }
}

"SupportedLanguages": {
    "properties": {
        "languages": {
            "additionalProperties": {
                "type": "string"
            },
            "type": "object",
            "title": "Languages"
        }
    },
    "type": "object",
    "required": [
        "languages"
    ],
    "title": "SupportedLanguages"
}

Expected result

Output from 6.7.7:

    /** SupportedLanguages */
    SupportedLanguages: {
      /** Languages */
      languages: {
        [key: string]: string;
      };
    };

Actual result

Output from 7.0.0:

        /** SupportedLanguages */
        SupportedLanguages: {
            /** Languages */
            languages: {
                [key: string]: string | undefined;
            };
        };

Checklist

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingopenapi-tsRelevant to the openapi-typescript library

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions