Just like the following YAML and typescript-fetch-client generated code, the property name in YALM is of Snake case,
but the property name in generated typescript code is of camel case;
the name in YALM isn't same with the name in generated code,
so the value in message can not be resolved with the property name in the generated code.
after change the name in the generated code to snake case format, the value in message can be gotten correctly.
Is there any workaround to this issue?
This is the declaration of the response message in YAML
`CardBatchGetResp:
type: object
properties:
errcode:
type: integer
errmsg:
type: string
card_id_list:
type: string
total_num:
type: integer`
`
This is the typescript-fetch-client generated code from the declaration in YAML
`
export interface CardBatchGetResp {
"errcode"?: number;
"errmsg"?: string;
"cardIdList"?: string;
"totalNum"?: number;
}`
I don't konw which version am I using,
I use "http://editor.swagger.io/#/" to generate code, I know that Swagger Editor version is 2.10.3
You can set the modelPropertyNaming to original:
swagger-codegen|master⚡ ⇒ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar config-help -l typescript-fetch
CONFIG OPTIONS
sortParamsByRequiredFlag
Sort method arguments to place required parameters before optional parameters. (Default: true)
ensureUniqueParams
Whether to ensure parameter names are unique in an operation (rename parameters that are not). (Default: true)
modelPropertyNaming
Naming convention for the property: 'camelCase', 'PascalCase', 'snake_case' and 'original', which keeps the original name (Default: camelCase)
supportsES6
Generate code that conforms to ES6. (Default: false)
npmName
The name under which you want to publish generated npm package
npmVersion
The version of your npm package
Ref: https://github.com/swagger-api/swagger-codegen#online-generators
i have the same problem, but i (and i assume the OP) actually want camel case on the client. is the proposal to fix this or to use snake case as a workaround?
@adamduffy have you tried setting modelPropertyNaming to camelCase?
just tried that and got the same results.
the problem is with the rest response. if the values are in snake case and the typescript interface is in camel case, the two do not work together.
the method signature is getX(): T where T has camel case props, but then simply does return response.json(); where response.json() props are snake. there is no attempt to convert it. the conversion is quite a bit of work to get right.
https://github.com/swagger-api/swagger-codegen/issues/3105 could also be solved at the same time
we are doing this snake to camel logic in the rest client we have manually written, along with inheritance, asserting required props, child nesting, date formatting, etc. it got quite complex so i was hoping to automate it.
I have the same problem as @fish2016 and @adamduffy had.
I use a REST api where the json response is configured to be snake_case. And I use swagger-codegen to generate a typescript-fetch client where the interfaces are camelCase (I set
modelPropertyNaming to camelCase)
I want to keep this configuration but I don't know how to map the snake_case response with the camelCase attributes at serialization time. Am I missing something ?
Thank you
@MohamedHamouGisaia Did you ever figure out a solution to this problem? I'm running into the exact same problem right now.
Most helpful comment
just tried that and got the same results.
the problem is with the rest response. if the values are in snake case and the typescript interface is in camel case, the two do not work together.
the method signature is
getX(): Twhere T has camel case props, but then simply doesreturn response.json();where response.json() props are snake. there is no attempt to convert it. the conversion is quite a bit of work to get right.https://github.com/swagger-api/swagger-codegen/issues/3105 could also be solved at the same time
we are doing this snake to camel logic in the rest client we have manually written, along with inheritance, asserting required props, child nesting, date formatting, etc. it got quite complex so i was hoping to automate it.