Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit 6af38a1

Browse files
Add support for application/x-pem-file MIME type
This patch adds support for serializing and deserializing data with the application/x-pem-file MIME type as plain text. Fixes: #244
1 parent ec11c61 commit 6af38a1

7 files changed

Lines changed: 42 additions & 7 deletions

File tree

samples/client/3_0_3_unit_test/python/src/unit_test_api/api_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
from unit_test_api.configurations import api_configuration, schema_configuration as schema_configuration_
3232

3333

34+
__plain_txt_content_types = {'text/plain', 'application/x-pem-file'}
35+
36+
3437
class JSONEncoder(json.JSONEncoder):
3538
compact_separators = (',', ':')
3639

@@ -907,6 +910,8 @@ def deserialize(cls, response: urllib3.HTTPResponse, configuration: schema_confi
907910
elif content_type.startswith('multipart/form-data'):
908911
body_data = cls.__deserialize_multipart_form_data(response)
909912
content_type = 'multipart/form-data'
913+
elif content_type == 'application/x-pem-file':
914+
body_data = response.data.decode()
910915
else:
911916
raise NotImplementedError('Deserialization of {} has not yet been implemented'.format(content_type))
912917
body_schema = schemas.get_class(body_schema)
@@ -1379,7 +1384,7 @@ def serialize(
13791384
if isinstance(cast_in_data, (schemas.FileIO, bytes)):
13801385
raise ValueError(f"Invalid input data type. Data must be int/float/str/bool/None/tuple/immutabledict and it was type {type(cast_in_data)}")
13811386
return cls.__serialize_json(cast_in_data)
1382-
elif content_type == 'text/plain':
1387+
elif content_type in __plain_txt_content_types:
13831388
if not isinstance(cast_in_data, (int, float, str)):
13841389
raise ValueError(f"Unable to serialize type {type(cast_in_data)} to text/plain")
13851390
return cls.__serialize_text_plain(cast_in_data)

samples/client/3_1_0_json_schema/python/src/json_schema_api/api_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
from json_schema_api.configurations import api_configuration, schema_configuration as schema_configuration_
3232

3333

34+
__plain_txt_content_types = {'text/plain', 'application/x-pem-file'}
35+
36+
3437
class JSONEncoder(json.JSONEncoder):
3538
compact_separators = (',', ':')
3639

@@ -907,6 +910,8 @@ def deserialize(cls, response: urllib3.HTTPResponse, configuration: schema_confi
907910
elif content_type.startswith('multipart/form-data'):
908911
body_data = cls.__deserialize_multipart_form_data(response)
909912
content_type = 'multipart/form-data'
913+
elif content_type == 'application/x-pem-file':
914+
body_data = response.data.decode()
910915
else:
911916
raise NotImplementedError('Deserialization of {} has not yet been implemented'.format(content_type))
912917
body_schema = schemas.get_class(body_schema)
@@ -1379,7 +1384,7 @@ def serialize(
13791384
if isinstance(cast_in_data, (schemas.FileIO, bytes)):
13801385
raise ValueError(f"Invalid input data type. Data must be int/float/str/bool/None/tuple/immutabledict and it was type {type(cast_in_data)}")
13811386
return cls.__serialize_json(cast_in_data)
1382-
elif content_type == 'text/plain':
1387+
elif content_type in __plain_txt_content_types:
13831388
if not isinstance(cast_in_data, (int, float, str)):
13841389
raise ValueError(f"Unable to serialize type {type(cast_in_data)} to text/plain")
13851390
return cls.__serialize_text_plain(cast_in_data)

samples/client/3_1_0_unit_test/python/src/unit_test_api/api_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
from unit_test_api.configurations import api_configuration, schema_configuration as schema_configuration_
3232

3333

34+
__plain_txt_content_types = {'text/plain', 'application/x-pem-file'}
35+
36+
3437
class JSONEncoder(json.JSONEncoder):
3538
compact_separators = (',', ':')
3639

@@ -907,6 +910,8 @@ def deserialize(cls, response: urllib3.HTTPResponse, configuration: schema_confi
907910
elif content_type.startswith('multipart/form-data'):
908911
body_data = cls.__deserialize_multipart_form_data(response)
909912
content_type = 'multipart/form-data'
913+
elif content_type == 'application/x-pem-file':
914+
body_data = response.data.decode()
910915
else:
911916
raise NotImplementedError('Deserialization of {} has not yet been implemented'.format(content_type))
912917
body_schema = schemas.get_class(body_schema)
@@ -1379,7 +1384,7 @@ def serialize(
13791384
if isinstance(cast_in_data, (schemas.FileIO, bytes)):
13801385
raise ValueError(f"Invalid input data type. Data must be int/float/str/bool/None/tuple/immutabledict and it was type {type(cast_in_data)}")
13811386
return cls.__serialize_json(cast_in_data)
1382-
elif content_type == 'text/plain':
1387+
elif content_type in __plain_txt_content_types:
13831388
if not isinstance(cast_in_data, (int, float, str)):
13841389
raise ValueError(f"Unable to serialize type {type(cast_in_data)} to text/plain")
13851390
return cls.__serialize_text_plain(cast_in_data)

samples/client/openapi_features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/api_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
from this_package.configurations import api_configuration, schema_configuration as schema_configuration_
3232

3333

34+
__plain_txt_content_types = {'text/plain', 'application/x-pem-file'}
35+
36+
3437
class JSONEncoder(json.JSONEncoder):
3538
compact_separators = (',', ':')
3639

@@ -907,6 +910,8 @@ def deserialize(cls, response: urllib3.HTTPResponse, configuration: schema_confi
907910
elif content_type.startswith('multipart/form-data'):
908911
body_data = cls.__deserialize_multipart_form_data(response)
909912
content_type = 'multipart/form-data'
913+
elif content_type == 'application/x-pem-file':
914+
body_data = response.data.decode()
910915
else:
911916
raise NotImplementedError('Deserialization of {} has not yet been implemented'.format(content_type))
912917
body_schema = schemas.get_class(body_schema)
@@ -1379,7 +1384,7 @@ def serialize(
13791384
if isinstance(cast_in_data, (schemas.FileIO, bytes)):
13801385
raise ValueError(f"Invalid input data type. Data must be int/float/str/bool/None/tuple/immutabledict and it was type {type(cast_in_data)}")
13811386
return cls.__serialize_json(cast_in_data)
1382-
elif content_type == 'text/plain':
1387+
elif content_type in __plain_txt_content_types:
13831388
if not isinstance(cast_in_data, (int, float, str)):
13841389
raise ValueError(f"Unable to serialize type {type(cast_in_data)} to text/plain")
13851390
return cls.__serialize_text_plain(cast_in_data)

samples/client/openapi_features/security/python/src/this_package/api_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
from this_package.configurations import api_configuration, schema_configuration as schema_configuration_
3232

3333

34+
__plain_txt_content_types = {'text/plain', 'application/x-pem-file'}
35+
36+
3437
class JSONEncoder(json.JSONEncoder):
3538
compact_separators = (',', ':')
3639

@@ -907,6 +910,8 @@ def deserialize(cls, response: urllib3.HTTPResponse, configuration: schema_confi
907910
elif content_type.startswith('multipart/form-data'):
908911
body_data = cls.__deserialize_multipart_form_data(response)
909912
content_type = 'multipart/form-data'
913+
elif content_type == 'application/x-pem-file':
914+
body_data = response.data.decode()
910915
else:
911916
raise NotImplementedError('Deserialization of {} has not yet been implemented'.format(content_type))
912917
body_schema = schemas.get_class(body_schema)
@@ -1402,7 +1407,7 @@ def serialize(
14021407
if isinstance(cast_in_data, (schemas.FileIO, bytes)):
14031408
raise ValueError(f"Invalid input data type. Data must be int/float/str/bool/None/tuple/immutabledict and it was type {type(cast_in_data)}")
14041409
return cls.__serialize_json(cast_in_data)
1405-
elif content_type == 'text/plain':
1410+
elif content_type in __plain_txt_content_types:
14061411
if not isinstance(cast_in_data, (int, float, str)):
14071412
raise ValueError(f"Unable to serialize type {type(cast_in_data)} to text/plain")
14081413
return cls.__serialize_text_plain(cast_in_data)

samples/client/petstore/python/src/petstore_api/api_client.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
from petstore_api.configurations import api_configuration, schema_configuration as schema_configuration_
3232

3333

34+
__plain_txt_content_types = {'text/plain', 'application/x-pem-file'}
35+
36+
3437
class JSONEncoder(json.JSONEncoder):
3538
compact_separators = (',', ':')
3639

@@ -907,6 +910,8 @@ def deserialize(cls, response: urllib3.HTTPResponse, configuration: schema_confi
907910
elif content_type.startswith('multipart/form-data'):
908911
body_data = cls.__deserialize_multipart_form_data(response)
909912
content_type = 'multipart/form-data'
913+
elif content_type == 'application/x-pem-file':
914+
body_data = response.data.decode()
910915
else:
911916
raise NotImplementedError('Deserialization of {} has not yet been implemented'.format(content_type))
912917
body_schema = schemas.get_class(body_schema)
@@ -1406,7 +1411,7 @@ def serialize(
14061411
if isinstance(cast_in_data, (schemas.FileIO, bytes)):
14071412
raise ValueError(f"Invalid input data type. Data must be int/float/str/bool/None/tuple/immutabledict and it was type {type(cast_in_data)}")
14081413
return cls.__serialize_json(cast_in_data)
1409-
elif content_type == 'text/plain':
1414+
elif content_type in __plain_txt_content_types:
14101415
if not isinstance(cast_in_data, (int, float, str)):
14111416
raise ValueError(f"Unable to serialize type {type(cast_in_data)} to text/plain")
14121417
return cls.__serialize_text_plain(cast_in_data)

src/main/resources/python/api_client.hbs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ from {{packageName}} import exceptions, rest, schemas, security_schemes, api_res
2929
from {{packageName}}.configurations import api_configuration, schema_configuration as schema_configuration_
3030

3131

32+
__plain_txt_content_types = {'text/plain', 'application/x-pem-file'}
33+
34+
3235
class JSONEncoder(json.JSONEncoder):
3336
compact_separators = (',', ':')
3437

@@ -905,6 +908,8 @@ class OpenApiResponse(typing.Generic[T], JSONDetector, abc.ABC):
905908
elif content_type.startswith('multipart/form-data'):
906909
body_data = cls.__deserialize_multipart_form_data(response)
907910
content_type = 'multipart/form-data'
911+
elif content_type == 'application/x-pem-file':
912+
body_data = response.data.decode()
908913
else:
909914
raise NotImplementedError('Deserialization of {} has not yet been implemented'.format(content_type))
910915
body_schema = schemas.get_class(body_schema)
@@ -1404,7 +1409,7 @@ class RequestBody(StyleFormSerializer, JSONDetector):
14041409
if isinstance(cast_in_data, (schemas.FileIO, bytes)):
14051410
raise ValueError(f"Invalid input data type. Data must be int/float/str/bool/None/tuple/immutabledict and it was type {type(cast_in_data)}")
14061411
return cls.__serialize_json(cast_in_data)
1407-
elif content_type == 'text/plain':
1412+
elif content_type in __plain_txt_content_types:
14081413
if not isinstance(cast_in_data, (int, float, str)):
14091414
raise ValueError(f"Unable to serialize type {type(cast_in_data)} to text/plain")
14101415
return cls.__serialize_text_plain(cast_in_data)

0 commit comments

Comments
 (0)