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-angular] property of number type incorrectly typed as BigDecimal #8855

Closed
Fredx87 opened this issue Oct 25, 2018 · 4 comments
Closed

Comments

@Fredx87
Copy link

Fredx87 commented Oct 25, 2018

Description

When a schema as some properties of number type, they are typed as BigDecimal instead of number in the exported model

Swagger-codegen version

3.0.2

Swagger declaration file content or url
openapi: 3.0.0
info:
  title: TestApi
  version: 1.0.0
paths:
  /test:
    get:
      summary: Test
      operationId: testApi
      responses:
        "200":
          description: Ok
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Response"
components:
  schemas:
    Response:
      type: object
      properties:
        propA:
          type: number
        propB:
          type: number
Command line used for generation

docker run --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli-v3:3.0.2 generate -i /local/swagger.yaml -l typescript-angular -o /local/ts-angular

Suggest a fix/enhancement

The generated model is

import { BigDecimal } from './bigDecimal';

export interface Response { 
    propA?: BigDecimal;
    propB?: BigDecimal;
}

And it is invalid (bigDecimal is not defined). The generated model should be:

export interface Response { 
    propA?: number;
    propB?: number;
}
@yoisel
Copy link

yoisel commented Nov 23, 2018

I have not tested it yet, but I believe the fix for this would be to add
typeMapping.put("BigDecimal", "number");

in the file

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractTypeScriptClientCodegen.java

where it says:

        typeMapping = new HashMap<String, String>();
        typeMapping.put("Array", "Array");
        typeMapping.put("array", "Array");
        typeMapping.put("List", "Array");
        typeMapping.put("boolean", "boolean");
        typeMapping.put("string", "string");

@sertal70
Copy link

sertal70 commented Dec 6, 2018

Until a fix is officially released, a quick workaround could be to create a bigDecimal.ts file containing the type definition as alias of number:

export type BigDecimal = number;

Obviously you have to add the file each time you generate the code... annoying but working.

frantuma added a commit to swagger-api/swagger-codegen-generators that referenced this issue Aug 23, 2019
…en#8855 - fix BigDecimal typeMapping in typescript and python
frantuma added a commit to swagger-api/swagger-codegen-generators that referenced this issue Aug 23, 2019
@frantuma
Copy link
Member

fixed in swagger-api/swagger-codegen-generators/pull/446

@Altenrion
Copy link

Same happened for golang server generation

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

No branches or pull requests

5 participants