swagger-api / swagger-api/swagger-codegen

[typescript-angular] Incorrect serialization/deserialization for reserved words

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

Description

If your Swagger model has a reserved word, the typescript-angular generator will prefix it with an underscore. However, it appears that the client will not map the escaped version to the over-the-wire version when a service call is made.

In our specific example, we have a field in the JSON called class. The generated class has a property called _class, which is always undefined, because the class JSON property is not used to populate it.

Swagger-codegen version

2.3.0

Swagger declaration file content or url
Test:
  type: object
  properties:
    class:
      type: string
  required:
    - class

Produces:

export default class Test {
  _class: string;
}
Command line used for generation
java -jar /opt/swagger-codegen-cli/swagger-codegen-cli.jar generate -i ./swagger.yaml -l typescript-angular -o ./test-package --additional-properties ngVersion=5.0.0,npmName=test-package
Related issues/PRs

It is very similar to this Scala issue:
https://github.com/swagger-api/swagger-codegen/issues/6393

Suggest a fix/enhancement

I think we need to track what JSON property corresponds to what class property. When the client receives the JSON, it needs to populate the object correctly based on that map.

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

Reproduce the issue with the provided Swagger YAML and the typescript-angular generation command, then inspect the generated client's serialization and deserialization behavior. Trace how the JSON property class should correspond to the generated _class property; done means requests and responses preserve that mapping.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.