swagger-api / swagger-api/swagger-codegen
Using a Javascript reserved keyword (default) as property name in an interface
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
The following snippet is a part from a swagger.json file:
"SomeDateRanges": {
"type": "object",
"properties": {
"default": {
"allOf": [
{
"$ref": "#/components/schemas/DateRange"
}
]
},
},
"additionalProperties": false
},
The property 'default' is used in our c# code and is perfectly valid there.
However, in Javascript, the word default is a reserved keyword (source).
So swagger-codegen-cli (3.0.34.jar) adds a preceding underscore:
export interface SomeDateRanges {
_default?: DateRange;
}
But the back-end is still returning a JSON containing the property 'default', and not '_default' causing it to not work in our application.
What we're doing now is manually changing the property to 'default'. But that is quite cumbersome having to do that each time.
What we could do is rename the property. But that would be a breaking change for our API. But in general, is this a desired situation that the property is renamed to something that does not exist?
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
Use the supplied SomeDateRanges schema and its default property as the reproduction case for swagger-codegen-cli 3.0.34. Trace how the generated TypeScript interface maps reserved property names, then verify that the client can access the JSON field named default without requiring a manual rename.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100