Closed
Description
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
- My OpenAPI schema passes the Redocly validator (
npx @redocly/cli@latest lint
) - I’m willing to open a PR (see CONTRIBUTING.md)