Swagger-codegen: [php] property of number type incorrectly typed as BigDecimal instead of float

Created on 6 Apr 2019  路  4Comments  路  Source: swagger-api/swagger-codegen

Description

When a schema as some properties of number type, they are typed as BigDecimal instead of number in the exported model. In php it must be float.

Swagger-codegen version

v3.0.7

Swagger declaration file content or url

The schema can be taken from a similar issue https://github.com/swagger-api/swagger-codegen/issues/8855

here is a part of my schema:
image

Command line used for generation
java -jar swagger-codegen-cli.jar generate \
   -i http://127.0.0.1:8980/swagger.json \
   -l php \
   -o .
Steps to reproduce

the result will be

class Price {
    protected static $swaggerTypes = [
        'currency' => 'string',
        'value' => 'BigDecimal'  
    ];

And it will throw an error Class 'BigDecimal' not found
image

Related issues/PRs

https://github.com/swagger-api/swagger-codegen/issues/8855

Suggest a fix/enhancement

float must be used instead of BigDecimal

Most helpful comment

It can be correct by use of --type-mappings BigDecimal=float

java -jar swagger-codegen-cli.jar generate \
   -i http://127.0.0.1:8980/swagger.json \
   -l php \
   --type-mappings BigDecimal=float \
   -o .

All 4 comments

Any estimate when this will be available on swaggerhub.com CodeGen? Currently the PHP output is generated by Swagger Codegen version: 3.0.9 and this issue still exists, so we need to fix the generated client by hand every time we export it.

@bkonetzny this can be automated though

sed -i -- 's/BigDecimal/float/g' lib/Model/*.php
sed -i -- 's/BigDecimal/float/g' lib/Api/*.php

It can be correct by use of --type-mappings BigDecimal=float

java -jar swagger-codegen-cli.jar generate \
   -i http://127.0.0.1:8980/swagger.json \
   -l php \
   --type-mappings BigDecimal=float \
   -o .
Was this page helpful?
0 / 5 - 0 ratings