swagger-api / swagger-api/swagger-codegen
[typescript-node] Bug generating models with property name `in`
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
When I run swagger-codegen with a model that has a property name in using mustache {{name}} variable it returns the name _in.
Swagger-codegen version
2.3.1 (and also tried with head of master).
It worked with 2.2.1, so a regression.
Swagger declaration file content or url
Given the following model:
swagger: '2.0'
host: 'localhost'
schemes:
- http
- https
consumes:
- application/json
produces:
- application/json
paths:
/screenSize:
get:
operationId: get_screenSize
responses:
200:
description: OK
schema:
$ref: '#/definitions/ScreenSize'
definitions:
ScreenSize:
description: physical screen size
properties:
cm:
type: string
in:
type: string
Using the following api.mustache
{{#models}}
{{#model}}
export class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{
{{#vars}}
{{#description}}
/**
* {{{description}}}
*/
{{/description}}
public '{{name}}': {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{datatype}}}{{/isEnum}};
{{/vars}}
}
{{/model}}
{{/models}}
I expect the following output:
export class ScreenSize {
public 'cm': string;
public 'in': string;
}
But I get the following:
export class ScreenSize {
public 'cm': string;
public '_in': string;
}
Command line used for generation
swagger-codegen generate -i swagger.yaml -l typescript-node -t ./ -o ./ -DmodelPropertyNaming=camelCase
Steps to reproduce
- Create swagger.yaml with above content in current directory.
- Create api.mustache with above content in current directory.
- Run
swagger-codegen generate -i swagger.yaml -l typescript-node -t ./ -o ./ -DmodelPropertyNaming=camelCase
See that api.ts yields:
export class ScreenSize {
public 'cm': string;
public '_in': string;
}
Related issues/PRs
I haven't been able to find a related issue.
Suggest a fix/enhancement
I've tried to look into the code, but I haven't been able to find where the bug is introduced.
But I believe it comes from the DmodelPropertyNaming, since the api.mustache {{baseName}} returns in and {{name}} returns _in. But I'm just guessing here.
If someone can point me in the right direction, I'll be glad to fix it!
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, api.mustache, and typescript-node command, comparing {{name}} with {{baseName}} under modelPropertyNaming=camelCase. Trace where the model property name is transformed, then verify that the generated api.ts preserves the property name in and add regression coverage if the project’s existing tests support it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100