swagger-api / swagger-api/swagger-codegen

[typescript/angular2]JSON.NET's $type property generated with upper-case

Open
#5,811 2 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

With an ASP.NET/ASP.NET Core Api Schema generated from C# models and using JSON.NET, the property "$type" is added to the swagger definition (so far so good, and working as intended).

But when the TypeScript/Angular2 Client is generated from this swagger definition, a model/interface with an uppercase T is created ($Type instead of $type). When sending such a model back to the REST service, the serialization fails on inherited classes, since $Type is not recognized. Manually renaming the property in the model to $type and it works again

Swagger-codegen version

Version: 2.2.2

Swagger declaration file content or url
  "definitions": {
    "ProcessingConfigViewModel": {
      "required": [
        "$type"
      ],
      "type": "object",
      "properties": {
        "id": {
          "format": "int32",
          "type": "integer"
        },
        "type": {
          "enum": [
            "Unknown",
            "Xslt",
            "Module"
          ],
          "type": "string"
        },
        "kind": {
          "enum": [
            "Pre",
            "Post",
            "PostMonitor"
          ],
          "type": "string"
        },
        "executionOrder": {
          "format": "int32",
          "type": "integer"
        },
        "$type": {
          "type": "string"
        }
      },
      "discriminator": "$type"
    },
    ...
}
export interface ProcessingConfigViewModel {
    id?: number;

    type?: ProcessingConfigViewModel.TypeEnum;

    kind?: ProcessingConfigViewModel.KindEnum;

    executionOrder?: number;

    $Type: string; // << Error. Should be $type

}
Command line used for generation

set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M
java %JAVA_OPTS% -jar .\swagger-codegen-cli.jar generate -i standardwf\standardwf.json -l typescript-angular2 -o standardwf\output\rest-client

Suggest a Fix

Keep the same casing defined in the swagger definition.

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 typescript-angular2 generation command and the generated ProcessingConfigViewModel interface, comparing its property names with the Swagger definition's $type property and discriminator. Reproduce the output using the supplied JSON declaration and verify that the generated model preserves the original casing so serialization recognizes $type.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.