swagger-typescript-api
swagger-typescript-api copied to clipboard
Broken/unexpected behavior for enum values with numbers in them
When generating enums (without --union-enums
), there are two things that can happen when there are numbers in the enum values:
-
An enum value prefixed with underscore and a number will result in invalid code being generated. For example
_123_ENUM_VALUE
in the swagger enum will generate the name123ENUMVALUE
which is invalid typescript because it starts with a number. Expected name would probably be to keep_123_ENUM_VALUE
on the typescript side as well. -
An enum value with numbers anywhere in it is has underscores stripped from the generated name (reminiscent of #108). For example
ENUM_123_VALUE
in the swagger enum will generate the nameENUM123VALUE
. Expected typescript name would beENUM_123_VALUE
with underscores intact because it's valid typescript as-is.
Hello @rudism can you share part of swagger schema with this problematic enums?
I have the issue. Here is my swagger:
{ "openapi": "3.0.1", "info": { "title": "Test", "description": "Test", "contact": { "url": "https://www.google.com", "email": "[email protected]" }, "license": { "name": "End-User License Agreement", "url": "https://www.google.com" }, "version": "v1" }, "paths": { "/test/{testId}": { "get": { "tags": ["Test tag"], "summary": "Test summary", "description": "Test description\n", "parameters": [ { "name": "testId", "in": "path", "description": "Test identifier.", "required": true, "schema": { "type": "integer", "description": "Test Id", "format": "int64" } } ], "responses": { "200": { "description": "Success", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/TestSchema" } } } }, "404": { "description": "Not Found" }, "401": { "description": "Unauthorized" }, "403": { "description": "Forbidden" } }, "security": [ { "Bearer": [null] } ] } } }, "components": { "schemas": { "TestSchema": { "type": "object", "properties": { "name": { "type": "string", "nullable": true }, "description": { "type": "string", "nullable": true }, "standardItemNumber": { "$ref": "#/components/schemas/StandardItemNumber" }, "playSound": { "type": "boolean" }, "updatedAt": { "type": "string", "format": "date-time" } }, "additionalProperties": false }, "StandardItemNumber": { "enum": ["ID", "_ONE", "_100TH", "JUST_WITH_UNDERSCORES"], "type": "string" } } }, "tags": [ { "name": "Test tag", "description": "Test tagt" } ] }
Error log:
I have this error too: