When a schema as some properties of number type, they are typed as BigDecimal instead of number in the exported model
3.0.2
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
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
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;
}
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");
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.
fixed in swagger-api/swagger-codegen-generators/pull/446
Same happened for golang server generation
Most helpful comment
fixed in swagger-api/swagger-codegen-generators/pull/446