swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

[typescript] Properties that are named "_" are renamed to "_u"

Open guillaumehottin opened this issue 2 years ago • 0 comments

Description

When an OpenAPI model has a property with the name "_", the property in the generated model is renamed to "_u" when "modelPropertyNaming" is set to "original" and "u" when "modelPropertyNaming" is set to "camelCase". This causes problems when deserializing a response.

This is due to the following condition :

https://github.com/swagger-api/swagger-codegen/blob/420e9517b6f61ae1fbc918412278fb48ac25d296/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractTypeScriptClientCodegen.java#L168

This turns "_" to "_u". When "modelPropertyNaming" is set to "camelCase", it strips the leading underscore.

I don't understand why this property should be renamed, as there is no Typescript guideline forbidding the use of a property named this way (or a any guideline that would allow for "u" but not "").

Swagger-codegen version

3.0.41

Swagger declaration file content or url
{
  "openapi": "3.1.0",
  "info": {
    "title": "FastAPI",
    "version": "0.1.0"
  },
  "paths": {
    "/item": {
      "get": {
        "summary": "Get Item",
        "operationId": "get_item_item_get",
        "responses": {
          "200": {
            "description": "Successful Response",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Item"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Item": {
        "properties": {
          "_": {
            "type": "string",
            "title": " "
          }
        },
        "type": "object",
        "required": [
          "_"
        ],
        "title": "Item"
      }
    }
  }
}
Command line used for generation

swagger-codegen-cli generate -l typescript-angular -o angular -i .\openapi.json --additional-properties modelPropertyNaming=original

guillaumehottin avatar Oct 24 '23 14:10 guillaumehottin