forked from loafle/openapi-generator-original
Adding decimal support for python client generation (#19203)
* Adding decimal to template for Python generator * Rerunning the build steps * Add tests for decimal serialization and deserialization. * Move test to python not legacy pydantic sample * readd old imports --------- Co-authored-by: Adam <abolfik@pollyex.com>
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
import datetime
|
||||
from dateutil.parser import parse
|
||||
from enum import Enum
|
||||
import decimal
|
||||
import json
|
||||
import mimetypes
|
||||
import os
|
||||
@@ -67,6 +68,7 @@ class ApiClient:
|
||||
'bool': bool,
|
||||
'date': datetime.date,
|
||||
'datetime': datetime.datetime,
|
||||
'decimal': decimal.Decimal,
|
||||
'object': object,
|
||||
}
|
||||
_pool = None
|
||||
@@ -339,6 +341,7 @@ class ApiClient:
|
||||
If obj is str, int, long, float, bool, return directly.
|
||||
If obj is datetime.datetime, datetime.date
|
||||
convert to string in iso8601 format.
|
||||
If obj is decimal.Decimal return string representation.
|
||||
If obj is list, sanitize each element in the list.
|
||||
If obj is dict, return the dict.
|
||||
If obj is OpenAPI model, return the properties dict.
|
||||
@@ -364,6 +367,8 @@ class ApiClient:
|
||||
)
|
||||
elif isinstance(obj, (datetime.datetime, datetime.date)):
|
||||
return obj.isoformat()
|
||||
elif isinstance(obj, decimal.Decimal):
|
||||
return str(obj)
|
||||
|
||||
elif isinstance(obj, dict):
|
||||
obj_dict = obj
|
||||
@@ -455,6 +460,8 @@ class ApiClient:
|
||||
return self.__deserialize_date(data)
|
||||
elif klass == datetime.datetime:
|
||||
return self.__deserialize_datetime(data)
|
||||
elif klass == decimal.Decimal:
|
||||
return decimal.Decimal(data)
|
||||
elif issubclass(klass, Enum):
|
||||
return self.__deserialize_enum(data, klass)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user