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

Commit c684fd2

Browse files
committed
Shortens operation + response files, improves request body serialize typing (#195)
* Generates separate file for pathparameters * Adds x_parameters files * Fixes typo * Passes body_info into _get_fields_and_body * Adds RequestBodyInfo ref linking * Fixes body types in BodyInfoForX * Fixes one python test * Fixes one test * Fixes another test * Fixes test_body_with_query_params * Fixes test_composed_one_of_different_types * Fixes test_inline_composition * Fixes test_json_patch * Fixes test_json_with_charset * Fixes test_mammal, test_missing_or_unset_required_body * Fixes two tests * Fixes two tests * Fixes two tests * Fixes two tests * Fixes last python test * Allows body_info to be None * Adds request_body imports for endpoint code sample * Adds body_info to endpoint docs * Stops generating requestbodyinfo schemas for refed schemas * Dereferences request body schemas * Improves refModuleAlias values, prevents collisions based on usages * Samples regenerated * Samples actually regenerated * Fixes test for the nonCOmpliantDiscriminator sample * Fixes unit tests * Runs ensure up to date * Adds content type back in * Adds content type overload condition branch * Adds per content type operation overloads * Removes unused getContentTypeToOperation, adds requestBodySchema * Adds and sets requestBodySchema in CodegenOperation * Uses a linkedhashmap to store properties before making requestBodySchema * Uses requestBodySchema.properties to define type hints for operation fn implementation signature * Adds request body schema imports at the top of the operation file * Adds body type hints for operation * Switches code back to using body + content_type * FIxes two tests * Runs black on file, fixes three tests * Fixes 3 tests * Fixes 3 more tests * Updates operation variable names * Fixes body schema input type to use refModuleAlias, samples regen * FIxes unitt est specs * Updates templates to remove RequestBodyInfo * Samples regenerated * Updates operation to directly import query cookie header path param schema classes * Sets skip_validation to True in _get_used_path * FIxes mypy type errors, improves request body typing * Samples regen * Fixes typo * Removes unused doc import
1 parent 47860da commit c684fd2

File tree

525 files changed

+5829
-13974
lines changed
  • samples/client/3_0_3_unit_test/python
    • src/unit_test_api
      • paths
        • request_body_post_additionalproperties_allows_a_schema_which_should_validate_request_body/post
        • request_body_post_additionalproperties_are_allowed_by_default_request_body/post
        • request_body_post_additionalproperties_can_exist_by_itself_request_body/post
        • request_body_post_additionalproperties_should_not_look_in_applicators_request_body/post
        • request_body_post_allof_combined_with_anyof_oneof_request_body/post
        • request_body_post_allof_request_body/post
        • request_body_post_allof_simple_types_request_body/post
        • request_body_post_allof_with_base_schema_request_body/post
        • request_body_post_allof_with_one_empty_schema_request_body/post
        • request_body_post_allof_with_the_first_empty_schema_request_body/post
        • request_body_post_allof_with_the_last_empty_schema_request_body/post
        • request_body_post_allof_with_two_empty_schemas_request_body/post
        • request_body_post_anyof_complex_types_request_body/post
        • request_body_post_anyof_request_body/post
        • request_body_post_anyof_with_base_schema_request_body/post
        • request_body_post_anyof_with_one_empty_schema_request_body/post
        • request_body_post_array_type_matches_arrays_request_body/post
        • request_body_post_boolean_type_matches_booleans_request_body/post
        • request_body_post_by_int_request_body/post
        • request_body_post_by_number_request_body/post
        • request_body_post_by_small_number_request_body/post
        • request_body_post_date_time_format_request_body/post
        • request_body_post_email_format_request_body/post
        • request_body_post_enum_with0_does_not_match_false_request_body/post
        • request_body_post_enum_with1_does_not_match_true_request_body/post
        • request_body_post_enum_with_escaped_characters_request_body/post
        • request_body_post_enum_with_false_does_not_match0_request_body/post
        • request_body_post_enum_with_true_does_not_match1_request_body/post
        • request_body_post_enums_in_properties_request_body/post
        • request_body_post_forbidden_property_request_body/post
        • request_body_post_hostname_format_request_body/post
        • request_body_post_integer_type_matches_integers_request_body/post
        • request_body_post_invalid_instance_should_not_raise_error_when_float_division_inf_request_body/post
        • request_body_post_invalid_string_value_for_default_request_body/post
        • request_body_post_ipv4_format_request_body/post
        • request_body_post_ipv6_format_request_body/post
        • request_body_post_json_pointer_format_request_body/post
        • request_body_post_maximum_validation_request_body/post
        • request_body_post_maximum_validation_with_unsigned_integer_request_body/post
        • request_body_post_maxitems_validation_request_body/post
        • request_body_post_maxlength_validation_request_body/post
        • request_body_post_maxproperties0_means_the_object_is_empty_request_body/post
        • request_body_post_maxproperties_validation_request_body/post
        • request_body_post_minimum_validation_request_body/post
        • request_body_post_minimum_validation_with_signed_integer_request_body/post
        • request_body_post_minitems_validation_request_body/post
        • request_body_post_minlength_validation_request_body/post
        • request_body_post_minproperties_validation_request_body/post
        • request_body_post_nested_allof_to_check_validation_semantics_request_body/post
        • request_body_post_nested_anyof_to_check_validation_semantics_request_body/post
        • request_body_post_nested_items_request_body/post
        • request_body_post_nested_oneof_to_check_validation_semantics_request_body/post
        • request_body_post_not_more_complex_schema_request_body/post
        • request_body_post_not_request_body/post
        • request_body_post_nul_characters_in_strings_request_body/post
        • request_body_post_null_type_matches_only_the_null_object_request_body/post
        • request_body_post_number_type_matches_numbers_request_body/post
        • request_body_post_object_properties_validation_request_body/post
        • request_body_post_object_type_matches_objects_request_body/post
        • request_body_post_oneof_complex_types_request_body/post
        • request_body_post_oneof_request_body/post
        • request_body_post_oneof_with_base_schema_request_body/post
        • request_body_post_oneof_with_empty_schema_request_body/post
        • request_body_post_oneof_with_required_request_body/post
        • request_body_post_pattern_is_not_anchored_request_body/post
        • request_body_post_pattern_validation_request_body/post
        • request_body_post_properties_with_escaped_characters_request_body/post
        • request_body_post_property_named_ref_that_is_not_a_reference_request_body/post
        • request_body_post_ref_in_additionalproperties_request_body/post
        • request_body_post_ref_in_allof_request_body/post
        • request_body_post_ref_in_anyof_request_body/post
        • request_body_post_ref_in_items_request_body/post
        • request_body_post_ref_in_not_request_body/post
        • request_body_post_ref_in_oneof_request_body/post
        • request_body_post_ref_in_property_request_body/post
        • request_body_post_required_default_validation_request_body/post
        • request_body_post_required_validation_request_body/post
        • request_body_post_required_with_empty_array_request_body/post
        • request_body_post_required_with_escaped_characters_request_body/post
        • request_body_post_simple_enum_validation_request_body/post
        • request_body_post_string_type_matches_strings_request_body/post
        • request_body_post_the_default_keyword_does_not_do_anything_if_the_property_is_missing_request_body/post
        • request_body_post_uniqueitems_false_validation_request_body/post
        • request_body_post_uniqueitems_validation_request_body/post
        • request_body_post_uri_format_request_body/post
        • request_body_post_uri_reference_format_request_body/post
        • request_body_post_uri_template_format_request_body/post
        • response_body_post_additionalproperties_allows_a_schema_which_should_validate_response_body_for_content_types/post
        • response_body_post_additionalproperties_are_allowed_by_default_response_body_for_content_types/post
        • response_body_post_additionalproperties_can_exist_by_itself_response_body_for_content_types/post
        • response_body_post_additionalproperties_should_not_look_in_applicators_response_body_for_content_types/post
        • response_body_post_allof_combined_with_anyof_oneof_response_body_for_content_types/post
        • response_body_post_allof_response_body_for_content_types/post
        • response_body_post_allof_simple_types_response_body_for_content_types/post
        • response_body_post_allof_with_base_schema_response_body_for_content_types/post
        • response_body_post_allof_with_one_empty_schema_response_body_for_content_types/post
        • response_body_post_allof_with_the_first_empty_schema_response_body_for_content_types/post
        • response_body_post_allof_with_the_last_empty_schema_response_body_for_content_types/post
        • response_body_post_allof_with_two_empty_schemas_response_body_for_content_types/post
        • response_body_post_anyof_complex_types_response_body_for_content_types/post
        • response_body_post_anyof_response_body_for_content_types/post
        • response_body_post_anyof_with_base_schema_response_body_for_content_types/post
        • response_body_post_anyof_with_one_empty_schema_response_body_for_content_types/post
        • response_body_post_array_type_matches_arrays_response_body_for_content_types/post
        • response_body_post_boolean_type_matches_booleans_response_body_for_content_types/post
        • response_body_post_by_int_response_body_for_content_types/post
        • response_body_post_by_number_response_body_for_content_types/post
        • response_body_post_by_small_number_response_body_for_content_types/post
        • response_body_post_date_time_format_response_body_for_content_types/post
        • response_body_post_email_format_response_body_for_content_types/post
        • response_body_post_enum_with0_does_not_match_false_response_body_for_content_types/post
        • response_body_post_enum_with1_does_not_match_true_response_body_for_content_types/post
        • response_body_post_enum_with_escaped_characters_response_body_for_content_types/post
        • response_body_post_enum_with_false_does_not_match0_response_body_for_content_types/post
        • response_body_post_enum_with_true_does_not_match1_response_body_for_content_types/post
        • response_body_post_enums_in_properties_response_body_for_content_types/post
        • response_body_post_forbidden_property_response_body_for_content_types/post
        • response_body_post_hostname_format_response_body_for_content_types/post
        • response_body_post_integer_type_matches_integers_response_body_for_content_types/post
        • response_body_post_invalid_instance_should_not_raise_error_when_float_division_inf_response_body_for_content_types/post
        • response_body_post_invalid_string_value_for_default_response_body_for_content_types/post
        • response_body_post_ipv4_format_response_body_for_content_types/post
        • response_body_post_ipv6_format_response_body_for_content_types/post
        • response_body_post_json_pointer_format_response_body_for_content_types/post
        • response_body_post_maximum_validation_response_body_for_content_types/post
        • response_body_post_maximum_validation_with_unsigned_integer_response_body_for_content_types/post
        • response_body_post_maxitems_validation_response_body_for_content_types/post
        • response_body_post_maxlength_validation_response_body_for_content_types/post
        • response_body_post_maxproperties0_means_the_object_is_empty_response_body_for_content_types/post
        • response_body_post_maxproperties_validation_response_body_for_content_types/post
        • response_body_post_minimum_validation_response_body_for_content_types/post
        • response_body_post_minimum_validation_with_signed_integer_response_body_for_content_types/post
        • response_body_post_minitems_validation_response_body_for_content_types/post
        • response_body_post_minlength_validation_response_body_for_content_types/post
        • response_body_post_minproperties_validation_response_body_for_content_types/post
        • response_body_post_nested_allof_to_check_validation_semantics_response_body_for_content_types/post
        • response_body_post_nested_anyof_to_check_validation_semantics_response_body_for_content_types/post
        • response_body_post_nested_items_response_body_for_content_types/post
        • response_body_post_nested_oneof_to_check_validation_semantics_response_body_for_content_types/post
        • response_body_post_not_more_complex_schema_response_body_for_content_types/post
        • response_body_post_not_response_body_for_content_types/post
        • response_body_post_nul_characters_in_strings_response_body_for_content_types/post
        • response_body_post_null_type_matches_only_the_null_object_response_body_for_content_types/post
        • response_body_post_number_type_matches_numbers_response_body_for_content_types/post
        • response_body_post_object_properties_validation_response_body_for_content_types/post
        • response_body_post_object_type_matches_objects_response_body_for_content_types/post
        • response_body_post_oneof_complex_types_response_body_for_content_types/post
        • response_body_post_oneof_response_body_for_content_types/post
        • response_body_post_oneof_with_base_schema_response_body_for_content_types/post
        • response_body_post_oneof_with_empty_schema_response_body_for_content_types/post
        • response_body_post_oneof_with_required_response_body_for_content_types/post
        • response_body_post_pattern_is_not_anchored_response_body_for_content_types/post
        • response_body_post_pattern_validation_response_body_for_content_types/post
        • response_body_post_properties_with_escaped_characters_response_body_for_content_types/post
        • response_body_post_property_named_ref_that_is_not_a_reference_response_body_for_content_types/post
        • response_body_post_ref_in_additionalproperties_response_body_for_content_types/post
        • response_body_post_ref_in_allof_response_body_for_content_types/post
        • response_body_post_ref_in_anyof_response_body_for_content_types/post
        • response_body_post_ref_in_items_response_body_for_content_types/post
        • response_body_post_ref_in_not_response_body_for_content_types/post
        • response_body_post_ref_in_oneof_response_body_for_content_types/post
        • response_body_post_ref_in_property_response_body_for_content_types/post
        • response_body_post_required_default_validation_response_body_for_content_types/post
        • response_body_post_required_validation_response_body_for_content_types/post
        • response_body_post_required_with_empty_array_response_body_for_content_types/post
        • response_body_post_required_with_escaped_characters_response_body_for_content_types/post
        • response_body_post_simple_enum_validation_response_body_for_content_types/post
        • response_body_post_string_type_matches_strings_response_body_for_content_types/post
        • response_body_post_the_default_keyword_does_not_do_anything_if_the_property_is_missing_response_body_for_content_types/post
        • response_body_post_uniqueitems_false_validation_response_body_for_content_types/post
        • response_body_post_uniqueitems_validation_response_body_for_content_types/post
        • response_body_post_uri_format_response_body_for_content_types/post
        • response_body_post_uri_reference_format_response_body_for_content_types/post
        • response_body_post_uri_template_format_response_body_for_content_types/post
      • schemas
      • shared_imports
    • test/test_paths
      • test_request_body_post_additionalproperties_allows_a_schema_which_should_validate_request_body
      • test_request_body_post_additionalproperties_are_allowed_by_default_request_body
      • test_request_body_post_additionalproperties_can_exist_by_itself_request_body
      • test_request_body_post_additionalproperties_should_not_look_in_applicators_request_body
      • test_request_body_post_allof_combined_with_anyof_oneof_request_body
      • test_request_body_post_allof_request_body
      • test_request_body_post_allof_simple_types_request_body
      • test_request_body_post_allof_with_base_schema_request_body
      • test_request_body_post_allof_with_one_empty_schema_request_body
      • test_request_body_post_allof_with_the_first_empty_schema_request_body
      • test_request_body_post_allof_with_the_last_empty_schema_request_body
      • test_request_body_post_allof_with_two_empty_schemas_request_body
      • test_request_body_post_anyof_complex_types_request_body
      • test_request_body_post_anyof_request_body
      • test_request_body_post_anyof_with_base_schema_request_body
      • test_request_body_post_anyof_with_one_empty_schema_request_body
      • test_request_body_post_array_type_matches_arrays_request_body
      • test_request_body_post_boolean_type_matches_booleans_request_body
      • test_request_body_post_by_int_request_body
      • test_request_body_post_by_number_request_body
      • test_request_body_post_by_small_number_request_body
      • test_request_body_post_date_time_format_request_body
      • test_request_body_post_email_format_request_body
      • test_request_body_post_enum_with0_does_not_match_false_request_body
      • test_request_body_post_enum_with1_does_not_match_true_request_body
      • test_request_body_post_enum_with_escaped_characters_request_body
      • test_request_body_post_enum_with_false_does_not_match0_request_body
      • test_request_body_post_enum_with_true_does_not_match1_request_body
      • test_request_body_post_enums_in_properties_request_body
      • test_request_body_post_forbidden_property_request_body
      • test_request_body_post_hostname_format_request_body
      • test_request_body_post_integer_type_matches_integers_request_body
      • test_request_body_post_invalid_instance_should_not_raise_error_when_float_division_inf_request_body
      • test_request_body_post_invalid_string_value_for_default_request_body
      • test_request_body_post_ipv4_format_request_body

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

525 files changed

+5829
-13974
lines changed

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

+45-37
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,16 @@ def _serialize_json(
385385
schemas.immutabledict
386386
]
387387

388+
_JSON_TYPES = typing.Union[
389+
int,
390+
float,
391+
str,
392+
None,
393+
bool,
394+
typing.Tuple['_JSON_TYPES'],
395+
schemas.immutabledict[str, '_JSON_TYPES'],
396+
]
397+
388398
@dataclasses.dataclass
389399
class PathParameter(ParameterBase, StyleSimpleSerializer):
390400
name: str
@@ -1206,24 +1216,26 @@ def _get_headers(
12061216
@staticmethod
12071217
def _get_fields_and_body(
12081218
request_body: typing.Type[RequestBody],
1209-
body: typing.Any,
1210-
headers: _collections.HTTPHeaderDict,
1211-
content_type: str
1219+
body: typing.Union[schemas.INPUT_TYPES_ALL, schemas.Unset],
1220+
content_type: str,
1221+
headers: _collections.HTTPHeaderDict
12121222
):
12131223
if request_body.required and body is schemas.unset:
12141224
raise exceptions.ApiValueError(
12151225
'The required body parameter has an invalid value of: unset. Set a valid value instead')
1216-
_fields = None
1217-
_body = None
1218-
1219-
if request_body.required or ((not request_body.required) and body is not schemas.unset):
1220-
serialized_data = request_body.serialize(body, content_type)
1221-
headers.add('Content-Type', content_type)
1222-
if 'fields' in serialized_data:
1223-
_fields = serialized_data['fields']
1224-
elif 'body' in serialized_data:
1225-
_body = serialized_data['body']
1226-
return _fields, _body
1226+
1227+
if isinstance(body, schemas.Unset):
1228+
return None, None
1229+
1230+
serialized_fields = None
1231+
serialized_body = None
1232+
serialized_data = request_body.serialize(body, content_type)
1233+
headers.add('Content-Type', content_type)
1234+
if 'fields' in serialized_data:
1235+
serialized_fields = serialized_data['fields']
1236+
elif 'body' in serialized_data:
1237+
serialized_body = serialized_data['body']
1238+
return serialized_fields, serialized_body
12271239

12281240
@staticmethod
12291241
def _verify_response_status(response: api_response.ApiResponse):
@@ -1252,7 +1264,7 @@ class RequestBody(StyleFormSerializer, JSONDetector):
12521264
@classmethod
12531265
def __serialize_json(
12541266
cls,
1255-
in_data: typing.Any
1267+
in_data: _JSON_TYPES
12561268
) -> SerializedRequestBody:
12571269
in_data = cls.__json_encoder.default(in_data)
12581270
json_str = json.dumps(in_data, separators=(",", ":"), ensure_ascii=False).encode(
@@ -1261,26 +1273,18 @@ def __serialize_json(
12611273
return {'body': json_str}
12621274

12631275
@staticmethod
1264-
def __serialize_text_plain(in_data: typing.Any) -> SerializedRequestBody:
1265-
if in_data is None:
1266-
raise ValueError('Unable to serialize type None to text/plain')
1267-
elif isinstance(in_data, schemas.immutabledict):
1268-
raise ValueError('Unable to serialize type schemas.immutabledict to text/plain')
1269-
elif isinstance(in_data, tuple):
1270-
raise ValueError('Unable to serialize type tuple to text/plain')
1271-
elif isinstance(in_data, bool):
1272-
raise ValueError('Unable to serialize type bool to text/plain')
1276+
def __serialize_text_plain(in_data: typing.Union[int, float, str]) -> SerializedRequestBody:
12731277
return {'body': str(in_data)}
12741278

12751279
@classmethod
1276-
def __multipart_json_item(cls, key: str, value: schemas.Schema) -> rest.RequestField:
1280+
def __multipart_json_item(cls, key: str, value: _JSON_TYPES) -> rest.RequestField:
12771281
json_value = cls.__json_encoder.default(value)
12781282
request_field = rest.RequestField(name=key, data=json.dumps(json_value))
12791283
request_field.make_multipart(content_type='application/json')
12801284
return request_field
12811285

12821286
@classmethod
1283-
def __multipart_form_item(cls, key: str, value: schemas.Schema) -> rest.RequestField:
1287+
def __multipart_form_item(cls, key: str, value: typing.Union[_JSON_TYPES, bytes, schemas.FileIO]) -> rest.RequestField:
12841288
if isinstance(value, str):
12851289
request_field = rest.RequestField(name=key, data=str(value))
12861290
request_field.make_multipart(content_type='text/plain')
@@ -1289,19 +1293,17 @@ def __multipart_form_item(cls, key: str, value: schemas.Schema) -> rest.RequestF
12891293
request_field.make_multipart(content_type='application/octet-stream')
12901294
elif isinstance(value, schemas.FileIO):
12911295
# TODO use content.encoding to limit allowed content types if they are present
1292-
request_field = rest.RequestField.from_tuples(key, (os.path.basename(str(value.name)), value.read()))
1293-
request_field = typing.cast(rest.RequestField, request_field)
1296+
urllib3_request_field = rest.RequestField.from_tuples(key, (os.path.basename(str(value.name)), value.read()))
1297+
request_field = typing.cast(rest.RequestField, urllib3_request_field)
12941298
value.close()
12951299
else:
12961300
request_field = cls.__multipart_json_item(key=key, value=value)
12971301
return request_field
12981302

12991303
@classmethod
13001304
def __serialize_multipart_form_data(
1301-
cls, in_data: schemas.Schema
1305+
cls, in_data: schemas.immutabledict[str, typing.Union[_JSON_TYPES, bytes, schemas.FileIO]]
13021306
) -> SerializedRequestBody:
1303-
if not isinstance(in_data, schemas.immutabledict):
1304-
raise ValueError(f'Unable to serialize {in_data} to multipart/form-data because it is not a dict of data')
13051307
"""
13061308
In a multipart/form-data request body, each schema property, or each element of a schema array property,
13071309
takes a section in the payload with an internal header as defined by RFC7578. The serialization strategy
@@ -1344,21 +1346,18 @@ def __serialize_application_octet_stream(in_data: typing.Union[schemas.FileIO, b
13441346

13451347
@classmethod
13461348
def __serialize_application_x_www_form_data(
1347-
cls, in_data: typing.Any
1349+
cls, in_data: schemas.immutabledict[str, _JSON_TYPES]
13481350
) -> SerializedRequestBody:
13491351
"""
13501352
POST submission of form data in body
13511353
"""
1352-
if not isinstance(in_data, schemas.immutabledict):
1353-
raise ValueError(
1354-
f'Unable to serialize {in_data} to application/x-www-form-urlencoded because it is not a dict of data')
13551354
cast_in_data = cls.__json_encoder.default(in_data)
13561355
value = cls._serialize_form(cast_in_data, name='', explode=True, percent_encode=True)
13571356
return {'body': value}
13581357

13591358
@classmethod
13601359
def serialize(
1361-
cls, in_data: typing.Any, content_type: str
1360+
cls, in_data: schemas.INPUT_TYPES_ALL, content_type: str
13621361
) -> SerializedRequestBody:
13631362
"""
13641363
If a str is returned then the result will be assigned to data when making the request
@@ -1376,15 +1375,24 @@ def serialize(
13761375
# TODO check for and use encoding if it exists
13771376
# and content_type is multipart or application/x-www-form-urlencoded
13781377
if cls._content_type_is_json(content_type):
1378+
if isinstance(cast_in_data, (schemas.FileIO, bytes)):
1379+
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)}")
13791380
return cls.__serialize_json(cast_in_data)
13801381
elif content_type == 'text/plain':
1382+
if not isinstance(cast_in_data, (int, float, str)):
1383+
raise ValueError(f"Unable to serialize type {type(cast_in_data)} to text/plain")
13811384
return cls.__serialize_text_plain(cast_in_data)
13821385
elif content_type == 'multipart/form-data':
1386+
if not isinstance(cast_in_data, schemas.immutabledict):
1387+
raise ValueError(f"Unable to serialize {cast_in_data} to multipart/form-data because it is not a dict of data")
13831388
return cls.__serialize_multipart_form_data(cast_in_data)
13841389
elif content_type == 'application/x-www-form-urlencoded':
1390+
if not isinstance(cast_in_data, schemas.immutabledict):
1391+
raise ValueError(
1392+
f"Unable to serialize {cast_in_data} to application/x-www-form-urlencoded because it is not a dict of data")
13851393
return cls.__serialize_application_x_www_form_data(cast_in_data)
13861394
elif content_type == 'application/octet-stream':
13871395
if not isinstance(cast_in_data, (schemas.FileIO, bytes)):
1388-
raise ValueError(f'Invalid input data type. Data must be bytes or File for content_type={content_type}')
1396+
raise ValueError(f"Invalid input data type. Data must be bytes or File for content_type={content_type}")
13891397
return cls.__serialize_application_octet_stream(cast_in_data)
13901398
raise NotImplementedError('Serialization has not yet been implemented for {}'.format(content_type))

samples/client/3_0_3_unit_test/python/src/unit_test_api/paths/request_body_post_additionalproperties_allows_a_schema_which_should_validate_request_body/post/operation.py

+14-17
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@
44
Generated by: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator
55
"""
66

7-
from __future__ import annotations
8-
from unit_test_api.shared_imports.schema_imports import * # pyright: ignore [reportWildcardImportFromLibrary]
97
from unit_test_api import api_client
108
from unit_test_api.shared_imports.operation_imports import * # pyright: ignore [reportWildcardImportFromLibrary]
9+
from unit_test_api.components.schema import additionalproperties_allows_a_schema_which_should_validate
1110

1211
from .. import path
1312
from .responses import response_200
1413
from . import request_body
15-
from unit_test_api.components.schema import additionalproperties_allows_a_schema_which_should_validate as request_body_application_json_schema
16-
1714

1815

1916
__StatusCodeToResponse = typing_extensions.TypedDict(
@@ -35,8 +32,8 @@ class BaseApi(api_client.Api):
3532
def _post_additionalproperties_allows_a_schema_which_should_validate_request_body(
3633
self,
3734
body: typing.Union[
38-
request_body_application_json_schema.AdditionalpropertiesAllowsASchemaWhichShouldValidateDictInput,
39-
request_body_application_json_schema.AdditionalpropertiesAllowsASchemaWhichShouldValidateDict,
35+
additionalproperties_allows_a_schema_which_should_validate.AdditionalpropertiesAllowsASchemaWhichShouldValidateDictInput,
36+
additionalproperties_allows_a_schema_which_should_validate.AdditionalpropertiesAllowsASchemaWhichShouldValidateDict,
4037
],
4138
*,
4239
skip_deserialization: typing_extensions.Literal[False] = False,
@@ -50,8 +47,8 @@ def _post_additionalproperties_allows_a_schema_which_should_validate_request_bod
5047
def _post_additionalproperties_allows_a_schema_which_should_validate_request_body(
5148
self,
5249
body: typing.Union[
53-
request_body_application_json_schema.AdditionalpropertiesAllowsASchemaWhichShouldValidateDictInput,
54-
request_body_application_json_schema.AdditionalpropertiesAllowsASchemaWhichShouldValidateDict,
50+
additionalproperties_allows_a_schema_which_should_validate.AdditionalpropertiesAllowsASchemaWhichShouldValidateDictInput,
51+
additionalproperties_allows_a_schema_which_should_validate.AdditionalpropertiesAllowsASchemaWhichShouldValidateDict,
5552
],
5653
*,
5754
skip_deserialization: typing_extensions.Literal[True],
@@ -64,8 +61,8 @@ def _post_additionalproperties_allows_a_schema_which_should_validate_request_bod
6461
def _post_additionalproperties_allows_a_schema_which_should_validate_request_body(
6562
self,
6663
body: typing.Union[
67-
request_body_application_json_schema.AdditionalpropertiesAllowsASchemaWhichShouldValidateDictInput,
68-
request_body_application_json_schema.AdditionalpropertiesAllowsASchemaWhichShouldValidateDict,
64+
additionalproperties_allows_a_schema_which_should_validate.AdditionalpropertiesAllowsASchemaWhichShouldValidateDictInput,
65+
additionalproperties_allows_a_schema_which_should_validate.AdditionalpropertiesAllowsASchemaWhichShouldValidateDict,
6966
],
7067
*,
7168
skip_deserialization: bool = False,
@@ -80,14 +77,14 @@ def _post_additionalproperties_allows_a_schema_which_should_validate_request_bod
8077
class instances
8178
"""
8279
used_path = path
83-
_headers = self._get_headers()
80+
headers = self._get_headers()
8481
# TODO add cookie handling
8582

86-
_fields, _body = self._get_fields_and_body(
83+
fields, serialized_body = self._get_fields_and_body(
8784
request_body=request_body.RequestBody,
8885
body=body,
89-
headers=_headers,
90-
content_type=content_type
86+
content_type=content_type,
87+
headers=headers
9188
)
9289
host = self.api_client.configuration.get_server_url(
9390
"servers", server_index
@@ -97,9 +94,9 @@ class instances
9794
resource_path=used_path,
9895
method='post',
9996
host=host,
100-
headers=_headers,
101-
fields=_fields,
102-
body=_body,
97+
headers=headers,
98+
fields=fields,
99+
body=serialized_body,
103100
stream=stream,
104101
timeout=timeout,
105102
)

samples/client/3_0_3_unit_test/python/src/unit_test_api/paths/request_body_post_additionalproperties_allows_a_schema_which_should_validate_request_body/post/request_body/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from .content.application_json import schema as application_json_schema
1010

11+
1112
class RequestBody(api_client.RequestBody):
1213

1314

samples/client/3_0_3_unit_test/python/src/unit_test_api/paths/request_body_post_additionalproperties_are_allowed_by_default_request_body/post/operation.py

+8-11
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@
44
Generated by: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator
55
"""
66

7-
from __future__ import annotations
8-
from unit_test_api.shared_imports.schema_imports import * # pyright: ignore [reportWildcardImportFromLibrary]
97
from unit_test_api import api_client
108
from unit_test_api.shared_imports.operation_imports import * # pyright: ignore [reportWildcardImportFromLibrary]
9+
from unit_test_api.components.schema import additionalproperties_are_allowed_by_default
1110

1211
from .. import path
1312
from .responses import response_200
1413
from . import request_body
15-
from unit_test_api.components.schema import additionalproperties_are_allowed_by_default as request_body_application_json_schema
16-
1714

1815

1916
__StatusCodeToResponse = typing_extensions.TypedDict(
@@ -80,14 +77,14 @@ def _post_additionalproperties_are_allowed_by_default_request_body(
8077
class instances
8178
"""
8279
used_path = path
83-
_headers = self._get_headers()
80+
headers = self._get_headers()
8481
# TODO add cookie handling
8582

86-
_fields, _body = self._get_fields_and_body(
83+
fields, serialized_body = self._get_fields_and_body(
8784
request_body=request_body.RequestBody,
8885
body=body,
89-
headers=_headers,
90-
content_type=content_type
86+
content_type=content_type,
87+
headers=headers
9188
)
9289
host = self.api_client.configuration.get_server_url(
9390
"servers", server_index
@@ -97,9 +94,9 @@ class instances
9794
resource_path=used_path,
9895
method='post',
9996
host=host,
100-
headers=_headers,
101-
fields=_fields,
102-
body=_body,
97+
headers=headers,
98+
fields=fields,
99+
body=serialized_body,
103100
stream=stream,
104101
timeout=timeout,
105102
)

samples/client/3_0_3_unit_test/python/src/unit_test_api/paths/request_body_post_additionalproperties_are_allowed_by_default_request_body/post/request_body/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from .content.application_json import schema as application_json_schema
1010

11+
1112
class RequestBody(api_client.RequestBody):
1213

1314

0 commit comments

Comments
 (0)