Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[typescript-fetch-client] can not get the property value from the response msg #3818

Open
fish2016 opened this issue Sep 18, 2016 · 7 comments

Comments

@fish2016
Copy link

fish2016 commented Sep 18, 2016

Description

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;

}`

Swagger-codegen version

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

@fish2016 fish2016 changed the title [typescript-fetch-client] can not get the value in the response msg [typescript-fetch-client] can not get the value from the response msg Sep 18, 2016
@fish2016 fish2016 changed the title [typescript-fetch-client] can not get the value from the response msg [typescript-fetch-client] can not get the property value from the response msg Sep 18, 2016
@fish2016 fish2016 changed the title [typescript-fetch-client] can not get the property value from the response msg [typescript-fetch-client] can not get the property value from the response msg Sep 18, 2016
@wing328
Copy link
Contributor

wing328 commented Sep 19, 2016

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

@adamduffy
Copy link

adamduffy commented Sep 27, 2016

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?

@wing328
Copy link
Contributor

wing328 commented Sep 28, 2016

@adamduffy have you tried setting modelPropertyNaming to camelCase?

@adamduffy
Copy link

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.

#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.

@MohamedHamouGisaia
Copy link

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

@calvinwyoung
Copy link

@MohamedHamouGisaia Did you ever figure out a solution to this problem? I'm running into the exact same problem right now.

@onegreyonewhite
Copy link

Any progress here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants