swagger-api / swagger-codegen

swagger-codegen contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing your OpenAPI / Swagger definition.
http://swagger.io
Apache License 2.0
17.03k stars 6.03k forks source link

[typescript-angular2] Generated model attributes always start with lowercase char #4558

Closed pspeter closed 7 years ago

pspeter commented 7 years ago
Description

The models generated by the cli always have attributes whose first character is lowercase. My properties all start with an uppercase character though, and they are also written like that in the API and the swagger doc.

Swagger-codegen version

2.2.1

Swagger declaration file content or url
{ ...
"definitions":{ ... 
    "Rating":{"type":"object","properties":{
        "RatingId":{"format":"int32","type":"integer"},
        "Player":{"$ref":"#/definitions/Player"},
        "Datetime":{"format":"date-time","type":"string"},
        "Value":{"format":"int32","type":"integer"}
    }}
}}

generates:

export interface Rating {
    ratingId?: number;
    player?: models.Player;
    datetime?: Date;
    value?: number;
}
Command line used for generation

CMD:

java -jar swagger-codegen-cli-2.2.1.jar generate -o [...]\src\app \
-i http:\\localhost:4649/swagger/docs/v1 -l typescript-angular2
wing328 commented 7 years ago

@bloody-orange there's an option change the variable naming:

    modelPropertyNaming
        Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name (Default: camelCase)

Ref: java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar config-help -l typescript-angular2

wing328 commented 7 years ago

@bloody-orange there's also another PR to use an ObjectSerializer to handle mapping of the JSON key name: https://github.com/swagger-api/swagger-codegen/pull/4264

Please kindly it test out by runnning:

git checkout -b TiFu-typescriptPropertyNamingFix 2.3.0
git pull https://github.com/TiFu/swagger-codegen.git typescriptPropertyNamingFix
pspeter commented 7 years ago

@wing328 thanks for the quick response The config works perfectly, thanks again.

wing328 commented 7 years ago

@bloody-orange no problem. Let us know if you've further feedback.

(we've just added Swagger Codegen to ProductHunt: https://www.producthunt.com/posts/swagger-codegen, pleae upvote found Swagger Codegen useful)