swagger-typescript-api icon indicating copy to clipboard operation
swagger-typescript-api copied to clipboard

Broken/unexpected behavior for enum values with numbers in them

Open rudism opened this issue 3 years ago • 4 comments

When generating enums (without --union-enums), there are two things that can happen when there are numbers in the enum values:

  1. 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 name 123ENUMVALUE 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.

  2. 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 name ENUM123VALUE. Expected typescript name would be ENUM_123_VALUE with underscores intact because it's valid typescript as-is.

rudism avatar Jun 23 '21 21:06 rudism

Hello @rudism can you share part of swagger schema with this problematic enums?

js2me avatar Oct 04 '21 15:10 js2me

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: image

vitalii-bilous-epa avatar Sep 13 '23 09:09 vitalii-bilous-epa

I have this error too:

image

martijnimhoff avatar Dec 14 '23 12:12 martijnimhoff