swagger-api / swagger-api/swagger-codegen

Special character is removed from property name in generated Typescript interface

Open
#12,055 4 comments 1 reaction 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

When using the following schema:

"schemas": {
      "fooDto": {
        "required": ["$type"],
        "type": "object",
        "properties": {
          "$type": {
            "type": "string"
          }
        },
        "discriminator": {
          "propertyName": "$type",
          "mapping": {
            "SomeDto": "#/components/schemas/someDto",
            "OtherDto": "#/components/schemas/otherDto",
          }
        }
      },

The interface that gets created is:

export interface ContentDto { 
    type: string;
}

In this interface the dollar sign is removed.

Is there a way to prevent this from happening?

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 with the supplied OpenAPI schema and the TypeScript interface-generation entry point; compare the $type property in the input with the emitted type property. Confirm the expected preserved property name and add or run a focused regression case for this schema, then verify that generated output keeps $type.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.