swagger-api / swagger-api/swagger-codegen

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

Open
#12,255 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractTypeScriptClientCodegen.java around line 168, using the provided OpenAPI declaration and typescript-angular generation command to reproduce the naming change. Confirm that a property named "" remains "" for both modelPropertyNaming=original and camelCase, and that the generated model can deserialize the response.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, typescript
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.