Bug Report Checklist
Description
I'm working with a third-party OpenAPI specification, which defines all floating values as number, and python generator generates Pydantic models with Union[StrictFloat, StrictInt] types for these values.
However, i'd like those values to be Decimal instead.
openapi-generator version
7.22.0
OpenAPI declaration file content or url
https://universal-api.1-ofd.ru/api/swagger-ui/v3/api-docs
Generation Details
I tried a few approaches:
With this, floating point values have type Union[StrictFloat, StrictInt]:
java.exe -jar .\openapi-generator-cli-7.22.0.jar generate `
>> -g python `
>> -i https://universal-api.1-ofd.ru/api/swagger-ui/v3/api-docs `
>> -o api `
>> --type-mappings "number=Decimal" `
>> --import-mappings "Decimal=decimal.Decimal"
With this, floating point values have type float (mapNumberTo doesnt allow arbitrary types):
java.exe -jar .\openapi-generator-cli-7.22.0.jar generate `
>> -g python `
>> -i https://universal-api.1-ofd.ru/api/swagger-ui/v3/api-docs `
>> -o api`
>> --type-mappings "float=Decimal" `
>> --import-mappings "Decimal=decimal.Decimal" `
>> --additional-properties=mapNumberTo=float
Steps to reproduce
- Execute one of the commands above;
- Check file "api\openapi_client\models\item_dto.py", and see that field
price of model ItemDto does not have type Optional[Decimal].
Related issues/PRs
#2534 #13324 #19198
These issues cover converting specific types into Decimal (number formatted as decimal, string formatted as decimal or just decimal), but i'm talking about coercing chosen type(s) into it.
Suggest a fix
It looks like --type-mappings "number=Decimal" is not respected (unless i misunderstand the usage of it), but i'm not getting any warning about that.
If it's not supposed to work, then, perhaps, allowing passing arbitrary types to mapNumberTo property could be an alternative solution.
Finally, making unformatted numbers be parsed into Decimal fields would work for me, although underlying problem will remain.
Bug Report Checklist
Description
I'm working with a third-party OpenAPI specification, which defines all floating values as
number, andpythongenerator generates Pydantic models withUnion[StrictFloat, StrictInt]types for these values.However, i'd like those values to be
Decimalinstead.openapi-generator version
7.22.0
OpenAPI declaration file content or url
https://universal-api.1-ofd.ru/api/swagger-ui/v3/api-docs
Generation Details
I tried a few approaches:
With this, floating point values have type
Union[StrictFloat, StrictInt]:With this, floating point values have type
float(mapNumberTodoesnt allow arbitrary types):Steps to reproduce
priceof modelItemDtodoes not have typeOptional[Decimal].Related issues/PRs
#2534 #13324 #19198
These issues cover converting specific types into
Decimal(numberformatted asdecimal,stringformatted asdecimalor justdecimal), but i'm talking about coercing chosen type(s) into it.Suggest a fix
It looks like
--type-mappings "number=Decimal"is not respected (unless i misunderstand the usage of it), but i'm not getting any warning about that.If it's not supposed to work, then, perhaps, allowing passing arbitrary types to
mapNumberToproperty could be an alternative solution.Finally, making unformatted
numbers be parsed intoDecimalfields would work for me, although underlying problem will remain.