swagger-codegen icon indicating copy to clipboard operation
swagger-codegen copied to clipboard

[typescript-angular2] API Call Returns Model with "undefined" Member Value

Open darius-iko opened this issue 10 years ago • 7 comments

Description

When calling API by using TypeScript-Angular2 codegen, it returns data with "undefined" member value. When I inspect the returned data, the issue relies on different letter case (the return data has Pascal-case property name, but the model declaration has Camel-case property name).

image

Swagger-codegen version

2.2.1

Steps to reproduce
  1. Create an API service with return model which has Pascal-case property name (e.g. AuthenticationToken).
  2. Generate code with typescript-angular2 language.
  3. Write a dummy TypeScript code to call the API and compare the return data with the model declaration. Both has different capitalization style.
Suggest a Fix

Please add mapping for the returned data from any-case to camel-case, or change the property name to follow the letter case of the returned data.

darius-iko avatar Aug 13 '16 15:08 darius-iko

@darius-iko I think the issue you reported is similar to this one: https://github.com/swagger-api/swagger-codegen/issues/2766

Have you tried the modelPropertyNaming option to see if that addresses the issue for you?

swagger-codegen|master⚡ ⇒ java -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar config-help -l typescript-angular2

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

    npmRepository
        Use this property to set an url your private npmRepo in the package.json

    snapshot
        When setting this property to true the version will be suffixed with -SNAPSHOT.yyyyMMddHHmm (Default: false)

wing328 avatar Aug 15 '16 07:08 wing328

cc @Vrolijkx

wing328 avatar Aug 15 '16 07:08 wing328

Thank you. It works.

darius-iko avatar Aug 15 '16 08:08 darius-iko

Hi, how to inject parameter in HTTP Headers by using generated code? Can I set it by using the Api.defaultHeaders before calling the API? e.g: this.api.defaultHeaders.set('Content-Type', 'application/json');

Btw, there is another issue that the Api calls set Content-Type to text/plain by default. Meanwhile, it suppose to be application/json because it sends JSON data type. It causes the server to respond error message, unless I set it manually by using above approach.

darius-iko avatar Aug 15 '16 08:08 darius-iko

@darius-iko could you please try and see if #3603 fixes your issues?

sebastianhaas avatar Aug 22 '16 12:08 sebastianhaas

@darius-iko #3603 has been merged into master. Please pull the latest to give it a try.

If the issue still occurs, we'll reopen this issue.

wing328 avatar Aug 28 '16 13:08 wing328

Thank you.

darius-iko avatar Apr 07 '17 08:04 darius-iko