Skip to content

Commit

Permalink
Merge branch 'feature/CBR-python-pydantic-v1-secret-str' of https://g…
Browse files Browse the repository at this point in the history
…ithub.com/webertim/openapi-generator into webertim-feature/CBR-python-pydantic-v1-secret-str
  • Loading branch information
wing328 committed Nov 16, 2024
2 parents 7087104 + 8629c7f commit a1c371e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import re
import tempfile

from urllib.parse import quote
from pydantic import SecretStr
{{#tornado}}
import tornado.gen
{{/tornado}}
Expand Down Expand Up @@ -285,6 +286,7 @@ class ApiClient:
"""Builds a JSON POST object.

If obj is None, return None.
If obj is SecretStr, return obj.get_secret_value()
If obj is str, int, long, float, bool, return directly.
If obj is datetime.datetime, datetime.date
convert to string in iso8601 format.
Expand All @@ -297,6 +299,8 @@ class ApiClient:
"""
if obj is None:
return None
elif isinstance(obj, SecretStr):
return obj.get_secret_value()
elif isinstance(obj, self.PRIMITIVE_TYPES):
return obj
elif isinstance(obj, list):
Expand All @@ -316,7 +320,10 @@ class ApiClient:
# and attributes which value is not None.
# Convert attribute name to json key in
# model definition for request.
obj_dict = obj.to_dict()
if hasattr(obj, 'to_dict') and callable(getattr(obj, 'to_dict')):
obj_dict = obj.to_dict()
else:
obj_dict = obj.__dict__

return {key: self.sanitize_for_serialization(val)
for key, val in obj_dict.items()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import tempfile

from urllib.parse import quote
from pydantic import SecretStr

from openapi_client.configuration import Configuration
from openapi_client.api_response import ApiResponse
Expand Down Expand Up @@ -261,6 +262,7 @@ def sanitize_for_serialization(self, obj):
"""Builds a JSON POST object.
If obj is None, return None.
If obj is SecretStr, return obj.get_secret_value()
If obj is str, int, long, float, bool, return directly.
If obj is datetime.datetime, datetime.date
convert to string in iso8601 format.
Expand All @@ -273,6 +275,8 @@ def sanitize_for_serialization(self, obj):
"""
if obj is None:
return None
elif isinstance(obj, SecretStr):
return obj.get_secret_value()
elif isinstance(obj, self.PRIMITIVE_TYPES):
return obj
elif isinstance(obj, list):
Expand All @@ -292,7 +296,10 @@ def sanitize_for_serialization(self, obj):
# and attributes which value is not None.
# Convert attribute name to json key in
# model definition for request.
obj_dict = obj.to_dict()
if hasattr(obj, 'to_dict') and callable(getattr(obj, 'to_dict')):
obj_dict = obj.to_dict()
else:
obj_dict = obj.__dict__

return {key: self.sanitize_for_serialization(val)
for key, val in obj_dict.items()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import tempfile

from urllib.parse import quote
from pydantic import SecretStr

from petstore_api.configuration import Configuration
from petstore_api.api_response import ApiResponse
Expand Down Expand Up @@ -241,6 +242,7 @@ def sanitize_for_serialization(self, obj):
"""Builds a JSON POST object.
If obj is None, return None.
If obj is SecretStr, return obj.get_secret_value()
If obj is str, int, long, float, bool, return directly.
If obj is datetime.datetime, datetime.date
convert to string in iso8601 format.
Expand All @@ -253,6 +255,8 @@ def sanitize_for_serialization(self, obj):
"""
if obj is None:
return None
elif isinstance(obj, SecretStr):
return obj.get_secret_value()
elif isinstance(obj, self.PRIMITIVE_TYPES):
return obj
elif isinstance(obj, list):
Expand All @@ -272,7 +276,10 @@ def sanitize_for_serialization(self, obj):
# and attributes which value is not None.
# Convert attribute name to json key in
# model definition for request.
obj_dict = obj.to_dict()
if hasattr(obj, 'to_dict') and callable(getattr(obj, 'to_dict')):
obj_dict = obj.to_dict()
else:
obj_dict = obj.__dict__

return {key: self.sanitize_for_serialization(val)
for key, val in obj_dict.items()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import tempfile

from urllib.parse import quote
from pydantic import SecretStr

from petstore_api.configuration import Configuration
from petstore_api.api_response import ApiResponse
Expand Down Expand Up @@ -260,6 +261,7 @@ def sanitize_for_serialization(self, obj):
"""Builds a JSON POST object.
If obj is None, return None.
If obj is SecretStr, return obj.get_secret_value()
If obj is str, int, long, float, bool, return directly.
If obj is datetime.datetime, datetime.date
convert to string in iso8601 format.
Expand All @@ -272,6 +274,8 @@ def sanitize_for_serialization(self, obj):
"""
if obj is None:
return None
elif isinstance(obj, SecretStr):
return obj.get_secret_value()
elif isinstance(obj, self.PRIMITIVE_TYPES):
return obj
elif isinstance(obj, list):
Expand All @@ -291,7 +295,10 @@ def sanitize_for_serialization(self, obj):
# and attributes which value is not None.
# Convert attribute name to json key in
# model definition for request.
obj_dict = obj.to_dict()
if hasattr(obj, 'to_dict') and callable(getattr(obj, 'to_dict')):
obj_dict = obj.to_dict()
else:
obj_dict = obj.__dict__

return {key: self.sanitize_for_serialization(val)
for key, val in obj_dict.items()}
Expand Down

0 comments on commit a1c371e

Please sign in to comment.