swagger-api / swagger-api/swagger-codegen
[typescript-angular] Incorrect serialization/deserialization for reserved words
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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