From d6b360d47f2039c5a917ca86017c57eb91497c16 Mon Sep 17 00:00:00 2001 From: Justin Black Date: Sat, 9 Jul 2022 18:06:09 -0400 Subject: [PATCH] [python-experimental] Allow schema instances to be passed in and pass additional schema validations (#12758) * Converts all schema instances back into primitives in cast_to_allowed_types, fixes test test_deserialize_oneof_reference * Updates type hint * Adds validated_path_to_schemas input * Adds debugging, storess validated schemas in validated_path_to_schemas * Adds __process_schema_classes * Simplifies class creation for enums, True/False/None * Removes unused methods * Fixes two tests * Removes unneeded method _enum_by_value * Adds and uses validation_ran_earlier * Skips running validation if already ran, base_classes changed to seen_classes * Adds and uses validation_ran_earlier * Simplifies __get_simple_class * Casts None/True/False into NoneClass and BoolClass instances to make tpye checking and unique items checking simpler * Always cast file input to FileIO, removes __get_simple_class * Moves type checking to separate class * Moves validation checking into a _validate method * Moves enum value checking into SchemaEnumMaker's _validate method * Fixes test_dict_validate_direct_instantiation_cast_item * Removes spy_decorator * Fixed test_dict_validate_direct_instantiation * Fixes test_list_validate_direct_instantiation_cast_item * Fixes test_list_validate_direct_instantiation * Fixes test_list_validate_from_openai_data_instantiation * Fixes test_dict_validate_from_openapi_data_instantiation * Fixes test_upload_files * Samples regenerated * Reverts version file --- .../PythonExperimentalClientCodegen.java | 5 +- .../enum_value_to_name.handlebars | 2 +- .../model_templates/enums.handlebars | 2 +- .../imports_schema_types.handlebars | 2 + .../schema_composed_or_anytype.handlebars | 2 +- .../python-experimental/schemas.handlebars | 746 ++++++++---------- .../docs/EnumWithFalseDoesNotMatch0.md | 2 +- .../docs/EnumWithTrueDoesNotMatch1.md | 2 +- ...s_allows_a_schema_which_should_validate.py | 2 + ...tionalproperties_are_allowed_by_default.py | 2 + ...dditionalproperties_can_exist_by_itself.py | 2 + ...operties_should_not_look_in_applicators.py | 2 + .../model/array_type_matches_arrays.py | 2 + .../model/boolean_type_matches_booleans.py | 2 + .../unit_test_api/model/by_int.py | 2 + .../unit_test_api/model/by_number.py | 2 + .../unit_test_api/model/by_small_number.py | 2 + .../unit_test_api/model/date_time_format.py | 2 + .../unit_test_api/model/email_format.py | 2 + .../model/enum_with0_does_not_match_false.py | 2 + .../model/enum_with1_does_not_match_true.py | 2 + .../model/enum_with_escaped_characters.py | 2 + .../model/enum_with_false_does_not_match0.py | 6 +- .../model/enum_with_true_does_not_match1.py | 6 +- .../model/enums_in_properties.py | 2 + .../unit_test_api/model/forbidden_property.py | 2 + .../unit_test_api/model/hostname_format.py | 2 + .../model/integer_type_matches_integers.py | 2 + ...not_raise_error_when_float_division_inf.py | 2 + .../model/invalid_string_value_for_default.py | 2 + .../unit_test_api/model/ipv4_format.py | 2 + .../unit_test_api/model/ipv6_format.py | 2 + .../model/json_pointer_format.py | 2 + .../unit_test_api/model/maximum_validation.py | 2 + ...aximum_validation_with_unsigned_integer.py | 2 + .../model/maxitems_validation.py | 2 + .../model/maxlength_validation.py | 2 + ...axproperties0_means_the_object_is_empty.py | 2 + .../model/maxproperties_validation.py | 2 + .../unit_test_api/model/minimum_validation.py | 2 + .../minimum_validation_with_signed_integer.py | 2 + .../model/minitems_validation.py | 2 + .../model/minlength_validation.py | 2 + .../model/minproperties_validation.py | 2 + .../unit_test_api/model/model_not.py | 2 + .../unit_test_api/model/nested_items.py | 2 + .../model/not_more_complex_schema.py | 2 + .../model/nul_characters_in_strings.py | 2 + .../null_type_matches_only_the_null_object.py | 2 + .../model/number_type_matches_numbers.py | 2 + .../model/object_properties_validation.py | 2 + .../model/pattern_is_not_anchored.py | 2 + .../unit_test_api/model/pattern_validation.py | 2 + .../properties_with_escaped_characters.py | 2 + ...perty_named_ref_that_is_not_a_reference.py | 2 + .../model/ref_in_additionalproperties.py | 2 + .../unit_test_api/model/ref_in_allof.py | 2 + .../unit_test_api/model/ref_in_anyof.py | 2 + .../unit_test_api/model/ref_in_items.py | 2 + .../unit_test_api/model/ref_in_oneof.py | 2 + .../unit_test_api/model/ref_in_property.py | 2 + .../model/required_default_validation.py | 2 + .../model/required_validation.py | 2 + .../model/required_with_empty_array.py | 2 + .../model/simple_enum_validation.py | 2 + .../model/string_type_matches_strings.py | 2 + ..._do_anything_if_the_property_is_missing.py | 2 + .../model/uniqueitems_false_validation.py | 2 + .../model/uniqueitems_validation.py | 2 + .../unit_test_api/model/uri_format.py | 2 + .../model/uri_reference_format.py | 2 + .../model/uri_template_format.py | 2 + .../unit_test_api/schemas.py | 746 ++++++++---------- .../python-experimental/docs/BooleanEnum.md | 2 +- .../call_123_test_special_tags.py | 2 + .../api/default_api_endpoints/foo_get.py | 2 + ...ditional_properties_with_array_of_enums.py | 2 + .../api/fake_api_endpoints/array_model.py | 2 + .../api/fake_api_endpoints/array_of_enums.py | 2 + .../body_with_file_schema.py | 2 + .../body_with_query_params.py | 2 + .../api/fake_api_endpoints/boolean.py | 2 + .../case_sensitive_params.py | 2 + .../api/fake_api_endpoints/client_model.py | 2 + .../composed_one_of_different_types.py | 2 + .../api/fake_api_endpoints/delete_coffee.py | 2 + .../fake_api_endpoints/endpoint_parameters.py | 2 + .../api/fake_api_endpoints/enum_parameters.py | 2 + .../api/fake_api_endpoints/fake_health_get.py | 2 + .../fake_api_endpoints/group_parameters.py | 2 + .../inline_additional_properties.py | 2 + .../fake_api_endpoints/inline_composition.py | 2 + .../api/fake_api_endpoints/json_form_data.py | 2 + .../fake_api_endpoints/json_with_charset.py | 2 + .../api/fake_api_endpoints/mammal.py | 2 + .../number_with_validations.py | 2 + .../api/fake_api_endpoints/object_in_query.py | 2 + .../object_model_with_ref_props.py | 2 + .../parameter_collisions.py | 2 + .../query_parameter_collection_format.py | 2 + .../fake_api_endpoints/ref_object_in_query.py | 2 + .../response_without_schema.py | 2 + .../api/fake_api_endpoints/string.py | 2 + .../api/fake_api_endpoints/string_enum.py | 2 + .../upload_download_file.py | 2 + .../api/fake_api_endpoints/upload_file.py | 2 + .../api/fake_api_endpoints/upload_files.py | 2 + .../classname.py | 2 + .../api/pet_api_endpoints/add_pet.py | 2 + .../api/pet_api_endpoints/delete_pet.py | 2 + .../pet_api_endpoints/find_pets_by_status.py | 2 + .../pet_api_endpoints/find_pets_by_tags.py | 2 + .../api/pet_api_endpoints/get_pet_by_id.py | 2 + .../api/pet_api_endpoints/update_pet.py | 2 + .../pet_api_endpoints/update_pet_with_form.py | 2 + .../upload_file_with_required_file.py | 2 + .../api/pet_api_endpoints/upload_image.py | 2 + .../api/store_api_endpoints/delete_order.py | 2 + .../api/store_api_endpoints/get_inventory.py | 2 + .../store_api_endpoints/get_order_by_id.py | 2 + .../api/store_api_endpoints/place_order.py | 2 + .../api/user_api_endpoints/create_user.py | 2 + .../create_users_with_array_input.py | 2 + .../create_users_with_list_input.py | 2 + .../api/user_api_endpoints/delete_user.py | 2 + .../user_api_endpoints/get_user_by_name.py | 2 + .../api/user_api_endpoints/login_user.py | 2 + .../api/user_api_endpoints/logout_user.py | 2 + .../api/user_api_endpoints/update_user.py | 2 + .../model/additional_properties_class.py | 2 + ...ditional_properties_with_array_of_enums.py | 2 + .../petstore_api/model/address.py | 2 + .../petstore_api/model/animal.py | 2 + .../petstore_api/model/animal_farm.py | 2 + .../petstore_api/model/any_type_not_string.py | 2 + .../petstore_api/model/api_response.py | 2 + .../petstore_api/model/apple.py | 4 +- .../petstore_api/model/apple_req.py | 2 + .../model/array_holding_any_type.py | 2 + .../model/array_of_array_of_number_only.py | 2 + .../petstore_api/model/array_of_enums.py | 2 + .../model/array_of_number_only.py | 2 + .../petstore_api/model/array_test.py | 2 + .../model/array_with_validations_in_items.py | 2 + .../petstore_api/model/banana.py | 2 + .../petstore_api/model/banana_req.py | 2 + .../petstore_api/model/bar.py | 2 + .../petstore_api/model/basque_pig.py | 2 + .../petstore_api/model/boolean.py | 2 + .../petstore_api/model/boolean_enum.py | 6 +- .../petstore_api/model/capitalization.py | 2 + .../petstore_api/model/cat.py | 2 + .../petstore_api/model/category.py | 2 + .../petstore_api/model/child_cat.py | 2 + .../petstore_api/model/class_model.py | 2 + .../petstore_api/model/client.py | 2 + .../model/complex_quadrilateral.py | 2 + ...d_any_of_different_types_no_validations.py | 2 + .../petstore_api/model/composed_array.py | 2 + .../petstore_api/model/composed_bool.py | 2 + .../petstore_api/model/composed_none.py | 2 + .../petstore_api/model/composed_number.py | 2 + .../petstore_api/model/composed_object.py | 2 + .../model/composed_one_of_different_types.py | 2 + .../petstore_api/model/composed_string.py | 2 + .../petstore_api/model/currency.py | 2 + .../petstore_api/model/danish_pig.py | 2 + .../petstore_api/model/date_time_test.py | 2 + .../model/date_time_with_validations.py | 2 + .../model/date_with_validations.py | 2 + .../petstore_api/model/decimal_payload.py | 2 + .../petstore_api/model/dog.py | 2 + .../petstore_api/model/drawing.py | 2 + .../petstore_api/model/enum_arrays.py | 2 + .../petstore_api/model/enum_class.py | 2 + .../petstore_api/model/enum_test.py | 2 + .../model/equilateral_triangle.py | 2 + .../petstore_api/model/file.py | 2 + .../model/file_schema_test_class.py | 2 + .../petstore_api/model/foo.py | 2 + .../petstore_api/model/format_test.py | 2 + .../petstore_api/model/fruit.py | 2 + .../petstore_api/model/fruit_req.py | 2 + .../petstore_api/model/gm_fruit.py | 2 + .../petstore_api/model/grandparent_animal.py | 2 + .../petstore_api/model/has_only_read_only.py | 2 + .../petstore_api/model/health_check_result.py | 4 +- .../petstore_api/model/integer_enum.py | 2 + .../petstore_api/model/integer_enum_big.py | 2 + .../model/integer_enum_one_value.py | 2 + .../model/integer_enum_with_default_value.py | 2 + .../petstore_api/model/integer_max10.py | 2 + .../petstore_api/model/integer_min15.py | 2 + .../petstore_api/model/isosceles_triangle.py | 2 + .../petstore_api/model/mammal.py | 2 + .../petstore_api/model/map_test.py | 2 + ...perties_and_additional_properties_class.py | 2 + .../petstore_api/model/model200_response.py | 2 + .../petstore_api/model/model_return.py | 2 + .../petstore_api/model/money.py | 2 + .../petstore_api/model/name.py | 2 + .../model/no_additional_properties.py | 2 + .../petstore_api/model/nullable_class.py | 30 +- .../petstore_api/model/nullable_shape.py | 2 + .../petstore_api/model/nullable_string.py | 4 +- .../petstore_api/model/number.py | 2 + .../petstore_api/model/number_only.py | 2 + .../model/number_with_validations.py | 2 + .../petstore_api/model/object_interface.py | 2 + .../model/object_model_with_ref_props.py | 2 + .../model/object_with_decimal_properties.py | 2 + .../object_with_difficultly_named_props.py | 2 + ...object_with_inline_composition_property.py | 2 + .../model/object_with_validations.py | 2 + .../petstore_api/model/order.py | 2 + .../petstore_api/model/parent_pet.py | 2 + .../petstore_api/model/pet.py | 2 + .../petstore_api/model/pig.py | 2 + .../petstore_api/model/player.py | 2 + .../petstore_api/model/quadrilateral.py | 2 + .../model/quadrilateral_interface.py | 2 + .../petstore_api/model/read_only_first.py | 2 + .../petstore_api/model/scalene_triangle.py | 2 + .../petstore_api/model/shape.py | 2 + .../petstore_api/model/shape_or_null.py | 2 + .../model/simple_quadrilateral.py | 2 + .../petstore_api/model/some_object.py | 2 + .../petstore_api/model/special_model_name.py | 2 + .../petstore_api/model/string.py | 2 + .../petstore_api/model/string_boolean_map.py | 2 + .../petstore_api/model/string_enum.py | 8 +- .../model/string_enum_with_default_value.py | 2 + .../model/string_with_validation.py | 2 + .../petstore_api/model/tag.py | 2 + .../petstore_api/model/triangle.py | 2 + .../petstore_api/model/triangle_interface.py | 2 + .../petstore_api/model/user.py | 4 +- .../petstore_api/model/uuid_string.py | 2 + .../petstore_api/model/whale.py | 2 + .../petstore_api/model/zebra.py | 2 + .../petstore_api/schemas.py | 746 ++++++++---------- .../tests_manual/test_boolean_enum.py | 2 +- .../tests_manual/test_combine_schemas.py | 32 +- .../test_date_time_with_validations.py | 2 +- .../test_date_with_validations.py | 4 +- .../tests_manual/test_drawing.py | 39 +- .../tests_manual/test_fake_api.py | 4 +- .../tests_manual/test_nullable_string.py | 4 +- .../tests_manual/test_string_enum.py | 4 +- .../tests_manual/test_validate.py | 321 +++----- 250 files changed, 1661 insertions(+), 1522 deletions(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonExperimentalClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonExperimentalClientCodegen.java index 3be88480dd1..ed144bc5813 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonExperimentalClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/PythonExperimentalClientCodegen.java @@ -1127,7 +1127,10 @@ public class PythonExperimentalClientCodegen extends AbstractPythonCodegen { if ("int".equals(datatype) || "float".equals(datatype) || datatype.equals("int, float")) { return value; } else if ("bool".equals(datatype)) { - return value.substring(0, 1).toUpperCase(Locale.ROOT) + value.substring(1); + if (value.equals("true")) { + return "BoolClass.TRUE"; + } + return "BoolClass.FALSE"; } else { String fixedValue = (String) processTestExampleData(value); return ensureQuotes(fixedValue); diff --git a/modules/openapi-generator/src/main/resources/python-experimental/model_templates/enum_value_to_name.handlebars b/modules/openapi-generator/src/main/resources/python-experimental/model_templates/enum_value_to_name.handlebars index ea2cb759fbe..511dc75597c 100644 --- a/modules/openapi-generator/src/main/resources/python-experimental/model_templates/enum_value_to_name.handlebars +++ b/modules/openapi-generator/src/main/resources/python-experimental/model_templates/enum_value_to_name.handlebars @@ -1,7 +1,7 @@ _SchemaEnumMaker( enum_value_to_name={ {{#if isNull}} - None: "NONE", + NoneClass.NONE: "NONE", {{/if}} {{#with allowableValues}} {{#each enumVars}} diff --git a/modules/openapi-generator/src/main/resources/python-experimental/model_templates/enums.handlebars b/modules/openapi-generator/src/main/resources/python-experimental/model_templates/enums.handlebars index 923fac7f6f5..68dd1f03db0 100644 --- a/modules/openapi-generator/src/main/resources/python-experimental/model_templates/enums.handlebars +++ b/modules/openapi-generator/src/main/resources/python-experimental/model_templates/enums.handlebars @@ -3,7 +3,7 @@ @classmethod @property def NONE(cls): - return cls._enum_by_value[None](None) + return cls(None) {{/if}} {{#with allowableValues}} {{#each enumVars}} diff --git a/modules/openapi-generator/src/main/resources/python-experimental/model_templates/imports_schema_types.handlebars b/modules/openapi-generator/src/main/resources/python-experimental/model_templates/imports_schema_types.handlebars index f44c8ff5b40..48b47a7e341 100644 --- a/modules/openapi-generator/src/main/resources/python-experimental/model_templates/imports_schema_types.handlebars +++ b/modules/openapi-generator/src/main/resources/python-experimental/model_templates/imports_schema_types.handlebars @@ -42,6 +42,8 @@ from {{packageName}}.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/modules/openapi-generator/src/main/resources/python-experimental/model_templates/schema_composed_or_anytype.handlebars b/modules/openapi-generator/src/main/resources/python-experimental/model_templates/schema_composed_or_anytype.handlebars index 763da96feeb..3ea4a7c841e 100644 --- a/modules/openapi-generator/src/main/resources/python-experimental/model_templates/schema_composed_or_anytype.handlebars +++ b/modules/openapi-generator/src/main/resources/python-experimental/model_templates/schema_composed_or_anytype.handlebars @@ -12,7 +12,7 @@ class {{#if this.classname}}{{classname}}{{else}}{{#if nameInSnakeCase}}{{name}} {{/if}} {{else}} {{#if getHasMultipleTypes}} - _SchemaTypeChecker(typing.Union[{{#if isArray}}tuple, {{/if}}{{#if isMap}}frozendict, {{/if}}{{#if isNull}}none_type, {{/if}}{{#if isString}}str, {{/if}}{{#if isByteArray}}str, {{/if}}{{#if isUnboundedInteger}}decimal.Decimal, {{/if}}{{#if isShort}}decimal.Decimal, {{/if}}{{#if isLong}}decimal.Decimal, {{/if}}{{#if isFloat}}decimal.Decimal, {{/if}}{{#if isDouble}}decimal.Decimal, {{/if}}{{#if isNumber}}decimal.Decimal, {{/if}}{{#if isDate}}str, {{/if}}{{#if isDateTime}}str, {{/if}}{{#if isDecimal}}str, {{/if}}{{#if isBoolean}}bool, {{/if}}]), + _SchemaTypeChecker(typing.Union[{{#if isArray}}tuple, {{/if}}{{#if isMap}}frozendict, {{/if}}{{#if isNull}}NoneClass, {{/if}}{{#if isString}}str, {{/if}}{{#if isByteArray}}str, {{/if}}{{#if isUnboundedInteger}}decimal.Decimal, {{/if}}{{#if isShort}}decimal.Decimal, {{/if}}{{#if isLong}}decimal.Decimal, {{/if}}{{#if isFloat}}decimal.Decimal, {{/if}}{{#if isDouble}}decimal.Decimal, {{/if}}{{#if isNumber}}decimal.Decimal, {{/if}}{{#if isDate}}str, {{/if}}{{#if isDateTime}}str, {{/if}}{{#if isDecimal}}str, {{/if}}{{#if isBoolean}}BoolClass, {{/if}}]), {{/if}} {{#if composedSchemas}} ComposedBase, diff --git a/modules/openapi-generator/src/main/resources/python-experimental/schemas.handlebars b/modules/openapi-generator/src/main/resources/python-experimental/schemas.handlebars index 9db3075849e..7f2245c64e9 100644 --- a/modules/openapi-generator/src/main/resources/python-experimental/schemas.handlebars +++ b/modules/openapi-generator/src/main/resources/python-experimental/schemas.handlebars @@ -46,12 +46,17 @@ class FileIO(io.FileIO): def __new__(cls, arg: typing.Union[io.FileIO, io.BufferedReader]): if isinstance(arg, (io.FileIO, io.BufferedReader)): + if arg.closed: + raise ApiValueError('Invalid file state; file is closed and must be open') arg.close() inst = super(FileIO, cls).__new__(cls, arg.name) super(FileIO, inst).__init__(arg.name) return inst raise ApiValueError('FileIO must be passed arg which contains the open file') + def __init__(self, arg: typing.Union[io.FileIO, io.BufferedReader]): + pass + def update(d: dict, u: dict): """ @@ -78,29 +83,46 @@ class ValidationMetadata(frozendict): path_to_item: typing.Tuple[typing.Union[str, int], ...] = tuple(['args[0]']), from_server: bool = False, configuration: typing.Optional[Configuration] = None, - base_classes: typing.FrozenSet[typing.Type] = frozenset(), + seen_classes: typing.FrozenSet[typing.Type] = frozenset(), + validated_path_to_schemas: typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set['Schema']] = frozendict() ): """ Args: path_to_item: the path to the current data being instantiated. For {'a': [1]} if the code is handling, 1, then the path is ('args[0]', 'a', 0) + This changes from location to location from_server: whether or not this data came form the server True when receiving server data False when instantiating model with client side data not form the server + This does not change from location to location configuration: the Configuration instance to use This is needed because in Configuration: - one can disable validation checking - base_classes: when deserializing data that matches multiple schemas, this is used to store + This does not change from location to location + seen_classes: when deserializing data that matches multiple schemas, this is used to store the schemas that have been traversed. This is used to stop processing when a cycle is seen. + This changes from location to location + validated_path_to_schemas: stores the already validated schema classes for a given path location + This does not change from location to location """ return super().__new__( cls, path_to_item=path_to_item, from_server=from_server, configuration=configuration, - base_classes=base_classes, + seen_classes=seen_classes, + validated_path_to_schemas=validated_path_to_schemas ) + def validation_ran_earlier(self, cls: type) -> bool: + validated_schemas = self.validated_path_to_schemas.get(self.path_to_item, set()) + validation_ran_earlier = validated_schemas and cls in validated_schemas + if validation_ran_earlier: + return True + if cls in self.seen_classes: + return True + return False + @property def path_to_item(self) -> typing.Tuple[typing.Union[str, int], ...]: return self.get('path_to_item') @@ -114,8 +136,12 @@ class ValidationMetadata(frozendict): return self.get('configuration') @property - def base_classes(self) -> typing.FrozenSet[typing.Type]: - return self.get('base_classes') + def seen_classes(self) -> typing.FrozenSet[typing.Type]: + return self.get('seen_classes') + + @property + def validated_path_to_schemas(self) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set['Schema']]: + return self.get('validated_path_to_schemas') class ValidatorBase: @@ -194,31 +220,6 @@ class ValidatorBase: path_to_item=validation_metadata.path_to_item ) - @classmethod - def __data_with_boolclass_instead_of_bool(cls, data: typing.Any) -> typing.Any: - """ - In python bool is a subclass of int so 1 == True and 0 == False - This prevents code from being able to see the difference between 1 and True and 0 and False - To fix this swap in BoolClass singletons for True and False so they will differ from integers - """ - if isinstance(data, (list, tuple)): - new_data = [] - for item in data: - new_item = cls.__data_with_boolclass_instead_of_bool(item) - new_data.append(new_item) - return tuple(new_data) - elif isinstance(data, (dict, frozendict)): - new_data = {} - for key, value in data.items(): - new_value = cls.__data_with_boolclass_instead_of_bool(value) - new_data[key] = new_value - return frozendict(new_data) - elif isinstance(data, bool): - if data: - return BoolClass.TRUE - return BoolClass.FALSE - return data - @classmethod def __check_tuple_validations( cls, validations, input_values, @@ -246,7 +247,7 @@ class ValidatorBase: if (cls.__is_json_validation_enabled('uniqueItems', validation_metadata.configuration) and 'unique_items' in validations and validations['unique_items'] and input_values): - unique_items = set(cls.__data_with_boolclass_instead_of_bool(input_values)) + unique_items = set(input_values) if len(input_values) > len(unique_items): cls.__raise_validation_error_message( value=input_values, @@ -362,128 +363,6 @@ class ValidatorBase: cls.__check_dict_validations(validations, input_values, validation_metadata) elif isinstance(input_values, decimal.Decimal): cls.__check_numeric_validations(validations, input_values, validation_metadata) - try: - return super()._validate_validations_pass(input_values, validation_metadata) - except AttributeError: - return True - - -class Validator(typing.Protocol): - def _validate_validations_pass( - cls, - input_values, - validation_metadata: ValidationMetadata - ): - pass - - -def _SchemaValidator(**validations: typing.Union[str, bool, None, int, float, list[dict[str, typing.Union[str, int, float]]]]) -> Validator: - class SchemaValidator(ValidatorBase): - @classmethod - def _validate_validations_pass( - cls, - input_values, - validation_metadata: ValidationMetadata - ): - cls._check_validations_for_types(validations, input_values, validation_metadata) - try: - return super()._validate_validations_pass(input_values, validation_metadata) - except AttributeError: - return True - - return SchemaValidator - - -class TypeChecker(typing.Protocol): - @classmethod - def _validate_type( - cls, arg_simple_class: type - ) -> typing.Tuple[type]: - pass - - -def _SchemaTypeChecker(union_type_cls: typing.Union[typing.Any]) -> TypeChecker: - if typing.get_origin(union_type_cls) is typing.Union: - union_classes = typing.get_args(union_type_cls) - else: - # note: when a union of a single class is passed in, the union disappears - union_classes = tuple([union_type_cls]) - """ - I want the type hint... union_type_cls - and to use it as a base class but when I do, I get - TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - """ - class SchemaTypeChecker: - @classmethod - def _validate_type(cls, arg_simple_class: type): - if arg_simple_class not in union_classes: - return union_classes - try: - return super()._validate_type(arg_simple_class) - except AttributeError: - return tuple() - - return SchemaTypeChecker - - -class EnumMakerBase: - @classmethod - @property - def _enum_by_value( - cls - ) -> type: - enum_classes = {} - if not hasattr(cls, "_enum_value_to_name"): - return enum_classes - for enum_value, enum_name in cls._enum_value_to_name.items(): - base_class = type(enum_value) - if base_class is none_type: - enum_classes[enum_value] = get_new_class( - "Dynamic" + cls.__name__, (cls, NoneClass)) - log_cache_usage(get_new_class) - elif base_class is bool: - enum_classes[enum_value] = get_new_class( - "Dynamic" + cls.__name__, (cls, BoolClass)) - log_cache_usage(get_new_class) - else: - enum_classes[enum_value] = get_new_class( - "Dynamic" + cls.__name__, (cls, Singleton, base_class)) - log_cache_usage(get_new_class) - return enum_classes - - -class EnumMakerInterface(typing.Protocol): - @classmethod - @property - def _enum_value_to_name( - cls - ) -> typing.Dict[typing.Union[str, decimal.Decimal, bool, none_type], str]: - pass - - @classmethod - @property - def _enum_by_value( - cls - ) -> type: - pass - - -def _SchemaEnumMaker(enum_value_to_name: typing.Dict[typing.Union[str, decimal.Decimal, bool, none_type], str]) -> EnumMakerInterface: - class SchemaEnumMaker(EnumMakerBase): - @classmethod - @property - def _enum_value_to_name( - cls - ) -> typing.Dict[typing.Union[str, decimal.Decimal, bool, none_type], str]: - pass - try: - super_enum_value_to_name = super()._enum_value_to_name - except AttributeError: - return enum_value_to_name - intersection = dict(enum_value_to_name.items() & super_enum_value_to_name.items()) - return intersection - - return SchemaEnumMaker class Singleton: @@ -498,7 +377,12 @@ class Singleton: if key not in cls._instances: if arg in {None, True, False}: inst = super().__new__(cls) - # inst._value = arg + cls._instances[key] = inst + elif isinstance(arg, BoolClass): + inst = super().__new__(cls) + cls._instances[key] = inst + elif isinstance(arg, NoneClass): + inst = super().__new__(cls) cls._instances[key] = inst else: cls._instances[key] = super().__new__(cls, arg) @@ -508,7 +392,7 @@ class Singleton: if isinstance(self, NoneClass): return f'<{self.__class__.__name__}: None>' elif isinstance(self, BoolClass): - if (self.__class__, True) in self._instances: + if bool(self): return f'<{self.__class__.__name__}: True>' return f'<{self.__class__.__name__}: False>' return f'<{self.__class__.__name__}: {super().__repr__()}>' @@ -539,10 +423,171 @@ class BoolClass(Singleton): def __bool__(self) -> bool: for key, instance in self._instances.items(): if self is instance: - return key[1] + return bool(key[1]) raise ValueError('Unable to find the boolean value of this instance') +class Validator(typing.Protocol): + @classmethod + def _validate( + cls, + arg, + validation_metadata: ValidationMetadata, + ) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]]: + pass + + +def _SchemaValidator(**validations: typing.Union[str, bool, None, int, float, list[dict[str, typing.Union[str, int, float]]]]) -> Validator: + class SchemaValidator(ValidatorBase): + @classmethod + def _validate( + cls, + arg, + validation_metadata: ValidationMetadata, + ) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]]: + """ + SchemaValidator _validate + Validates that validations pass + """ + cls._check_validations_for_types(validations, arg, validation_metadata) + return super()._validate(arg, validation_metadata) + + return SchemaValidator + + +def _SchemaTypeChecker(union_type_cls: typing.Union[typing.Any]) -> Validator: + if typing.get_origin(union_type_cls) is typing.Union: + union_classes = typing.get_args(union_type_cls) + else: + # note: when a union of a single class is passed in, the union disappears + union_classes = tuple([union_type_cls]) + """ + I want the type hint... union_type_cls + and to use it as a base class but when I do, I get + TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases + """ + class SchemaTypeChecker: + @staticmethod + def __get_valid_classes_phrase(input_classes): + """Returns a string phrase describing what types are allowed""" + all_classes = list(input_classes) + all_classes = sorted(all_classes, key=lambda cls: cls.__name__) + all_class_names = [cls.__name__ for cls in all_classes] + if len(all_class_names) == 1: + return "is {0}".format(all_class_names[0]) + return "is one of [{0}]".format(", ".join(all_class_names)) + + @classmethod + def __type_error_message( + cls, var_value=None, var_name=None, valid_classes=None, key_type=None + ): + """ + Keyword Args: + var_value (any): the variable which has the type_error + var_name (str): the name of the variable which has the typ error + valid_classes (tuple): the accepted classes for current_item's + value + key_type (bool): False if our value is a value in a dict + True if it is a key in a dict + False if our item is an item in a tuple + """ + key_or_value = "value" + if key_type: + key_or_value = "key" + valid_classes_phrase = cls.__get_valid_classes_phrase(valid_classes) + msg = "Invalid type. Required {1} type {2} and " "passed type was {3}".format( + var_name, + key_or_value, + valid_classes_phrase, + type(var_value).__name__, + ) + return msg + + @classmethod + def _get_type_error(cls, var_value, path_to_item, valid_classes, key_type=False): + error_msg = cls.__type_error_message( + var_name=path_to_item[-1], + var_value=var_value, + valid_classes=valid_classes, + key_type=key_type, + ) + return ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=valid_classes, + key_type=key_type, + ) + + @classmethod + def _validate( + cls, + arg, + validation_metadata: ValidationMetadata, + ) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]]: + """ + SchemaTypeChecker _validate + Validates arg's type + """ + arg_type = type(arg) + if arg_type in union_classes: + return super()._validate(arg, validation_metadata) + raise cls._get_type_error( + arg, + validation_metadata.path_to_item, + union_classes, + key_type=False, + ) + + return SchemaTypeChecker + + +class EnumMakerBase: + pass + + +class EnumMakerInterface(Validator): + @classmethod + @property + def _enum_value_to_name( + cls + ) -> typing.Dict[typing.Union[str, decimal.Decimal, bool, none_type], str]: + pass + + +def _SchemaEnumMaker(enum_value_to_name: typing.Dict[typing.Union[str, decimal.Decimal, bool, none_type], str]) -> EnumMakerInterface: + class SchemaEnumMaker(EnumMakerBase): + @classmethod + @property + def _enum_value_to_name( + cls + ) -> typing.Dict[typing.Union[str, decimal.Decimal, bool, none_type], str]: + pass + try: + super_enum_value_to_name = super()._enum_value_to_name + except AttributeError: + return enum_value_to_name + intersection = dict(enum_value_to_name.items() & super_enum_value_to_name.items()) + return intersection + + @classmethod + def _validate( + cls, + arg, + validation_metadata: ValidationMetadata, + ) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]]: + """ + SchemaEnumMaker _validate + Validates that arg is in the enum's allowed values + """ + try: + cls._enum_value_to_name[arg] + except KeyError: + raise ApiValueError("Invalid value {} passed in to {}, {}".format(arg, cls, cls._enum_value_to_name)) + return super()._validate(arg, validation_metadata) + + return SchemaEnumMaker + + class BoolBase: def is_true(self) -> bool: """ @@ -814,13 +859,14 @@ class ListBase: item_cls = getattr(cls, '_items', AnyTypeSchema) path_to_schemas = {} for i, value in enumerate(list_items): - if isinstance(value, item_cls): - continue item_validation_metadata = ValidationMetadata( from_server=validation_metadata.from_server, configuration=validation_metadata.configuration, - path_to_item=validation_metadata.path_to_item+(i,) + path_to_item=validation_metadata.path_to_item+(i,), + validated_path_to_schemas=validation_metadata.validated_path_to_schemas ) + if item_validation_metadata.validation_ran_earlier(item_cls): + continue other_path_to_schemas = item_cls._validate( value, validation_metadata=item_validation_metadata) update(path_to_schemas, other_path_to_schemas) @@ -850,14 +896,12 @@ class ListBase: _path_to_schemas = super()._validate(arg, validation_metadata=validation_metadata) if not isinstance(arg, tuple): return _path_to_schemas - if cls in validation_metadata.base_classes: - # we have already moved through this class so stop here - return _path_to_schemas updated_vm = ValidationMetadata( configuration=validation_metadata.configuration, from_server=validation_metadata.from_server, path_to_item=validation_metadata.path_to_item, - base_classes=validation_metadata.base_classes | frozenset({cls}) + seen_classes=validation_metadata.seen_classes | frozenset({cls}), + validated_path_to_schemas=validation_metadata.validated_path_to_schemas ) other_path_to_schemas = cls._validate_items(arg, validation_metadata=updated_vm) update(_path_to_schemas, other_path_to_schemas) @@ -1023,13 +1067,14 @@ class DictBase(Discriminable): raise ApiTypeError('Unable to find schema for value={} in class={} at path_to_item={}'.format( value, cls, validation_metadata.path_to_item+(property_name,) )) - if isinstance(value, schema): - continue arg_validation_metadata = ValidationMetadata( from_server=validation_metadata.from_server, configuration=validation_metadata.configuration, - path_to_item=validation_metadata.path_to_item+(property_name,) + path_to_item=validation_metadata.path_to_item+(property_name,), + validated_path_to_schemas=validation_metadata.validated_path_to_schemas ) + if arg_validation_metadata.validation_ran_earlier(schema): + continue other_path_to_schemas = schema._validate(value, validation_metadata=arg_validation_metadata) update(path_to_schemas, other_path_to_schemas) return path_to_schemas @@ -1082,15 +1127,15 @@ class DictBase(Discriminable): validation_metadata.path_to_item + (disc_prop_name,) ) ) - if discriminated_cls in validation_metadata.base_classes: - # we have already moved through this class so stop here - return _path_to_schemas updated_vm = ValidationMetadata( configuration=validation_metadata.configuration, from_server=validation_metadata.from_server, path_to_item=validation_metadata.path_to_item, - base_classes=validation_metadata.base_classes | frozenset({cls}) + seen_classes=validation_metadata.seen_classes | frozenset({cls}), + validated_path_to_schemas=validation_metadata.validated_path_to_schemas ) + if updated_vm.validation_ran_earlier(discriminated_cls): + return _path_to_schemas other_path_to_schemas = discriminated_cls._validate(arg, validation_metadata=updated_vm) update(_path_to_schemas, other_path_to_schemas) return _path_to_schemas @@ -1178,7 +1223,7 @@ class DictBase(Discriminable): return super().__getattribute__(name) -inheritable_primitive_types_set = {decimal.Decimal, str, tuple, frozendict, FileIO, bytes} +inheritable_primitive_types_set = {decimal.Decimal, str, tuple, frozendict, FileIO, bytes, BoolClass, NoneClass} class Schema: @@ -1191,117 +1236,12 @@ class Schema: - payload value is an allowed enum value """ - @staticmethod - def __get_simple_class(input_value): - """Returns an input_value's simple class that we will use for type checking - - Args: - input_value (class/class_instance): the item for which we will return - the simple class - """ - if isinstance(input_value, tuple): - return tuple - elif isinstance(input_value, frozendict): - return frozendict - elif isinstance(input_value, none_type): - return none_type - elif isinstance(input_value, bytes): - return bytes - elif isinstance(input_value, (io.FileIO, io.BufferedReader)): - return FileIO - elif isinstance(input_value, bool): - # this must be higher than the int check because - # isinstance(True, int) == True - return bool - elif isinstance(input_value, int): - return int - elif isinstance(input_value, float): - return float - elif isinstance(input_value, datetime): - # this must be higher than the date check because - # isinstance(datetime_instance, date) == True - return datetime - elif isinstance(input_value, date): - return date - elif isinstance(input_value, str): - return str - return type(input_value) - - @staticmethod - def __get_valid_classes_phrase(input_classes): - """Returns a string phrase describing what types are allowed""" - all_classes = list(input_classes) - all_classes = sorted(all_classes, key=lambda cls: cls.__name__) - all_class_names = [cls.__name__ for cls in all_classes] - if len(all_class_names) == 1: - return "is {0}".format(all_class_names[0]) - return "is one of [{0}]".format(", ".join(all_class_names)) - - @classmethod - def __type_error_message( - cls, var_value=None, var_name=None, valid_classes=None, key_type=None - ): - """ - Keyword Args: - var_value (any): the variable which has the type_error - var_name (str): the name of the variable which has the typ error - valid_classes (tuple): the accepted classes for current_item's - value - key_type (bool): False if our value is a value in a dict - True if it is a key in a dict - False if our item is an item in a tuple - """ - key_or_value = "value" - if key_type: - key_or_value = "key" - valid_classes_phrase = cls.__get_valid_classes_phrase(valid_classes) - msg = "Invalid type. Required {1} type {2} and " "passed type was {3}".format( - var_name, - key_or_value, - valid_classes_phrase, - type(var_value).__name__, - ) - return msg - - @classmethod - def __get_type_error(cls, var_value, path_to_item, valid_classes, key_type=False): - error_msg = cls.__type_error_message( - var_name=path_to_item[-1], - var_value=var_value, - valid_classes=valid_classes, - key_type=key_type, - ) - return ApiTypeError( - error_msg, - path_to_item=path_to_item, - valid_classes=valid_classes, - key_type=key_type, - ) - - @classmethod - def _class_by_base_class(cls, base_cls: type) -> type: - cls_name = "Dynamic"+cls.__name__ - if base_cls is bool: - new_cls = get_new_class(cls_name, (cls, BoolBase, BoolClass)) - elif base_cls is str: - new_cls = get_new_class(cls_name, (cls, StrBase, str)) - elif base_cls is decimal.Decimal: - new_cls = get_new_class(cls_name, (cls, NumberBase, decimal.Decimal)) - elif base_cls is tuple: - new_cls = get_new_class(cls_name, (cls, ListBase, tuple)) - elif base_cls is frozendict: - new_cls = get_new_class(cls_name, (cls, DictBase, frozendict)) - elif base_cls is none_type: - new_cls = get_new_class(cls_name, (cls, NoneBase, NoneClass)) - log_cache_usage(get_new_class) - return new_cls - @classmethod def _validate( cls, arg, validation_metadata: ValidationMetadata, - ): + ) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]]: """ Schema _validate Runs all schema validation logic and @@ -1313,9 +1253,7 @@ class Schema: Use cases: 1. inheritable type: string/decimal.Decimal/frozendict/tuple - 2. enum value cases: 'hi', 1 -> no base_class set because the enum includes the base class - 3. uninheritable type: True/False/None -> no base_class because the base class is not inheritable - _enum_by_value will handle this use case + 2. singletons: bool/None -> uses the base classes BoolClass/NoneClass Required Steps: 1. verify type of input is valid vs the allowed _types @@ -1329,38 +1267,29 @@ class Schema: ApiValueError: when a string can't be converted into a date or datetime and it must be one of those classes ApiTypeError: when the input type is not in the list of allowed spec types """ - base_class = cls.__get_simple_class(arg) - failed_type_check_classes = cls._validate_type(base_class) - if failed_type_check_classes: - raise cls.__get_type_error( - arg, - validation_metadata.path_to_item, - failed_type_check_classes, - key_type=False, - ) - if hasattr(cls, '_validate_validations_pass'): - cls._validate_validations_pass(arg, validation_metadata) - path_to_schemas = {} - if validation_metadata.path_to_item not in path_to_schemas: - path_to_schemas[validation_metadata.path_to_item] = set() + base_class = type(arg) + path_to_schemas = {validation_metadata.path_to_item: set()} path_to_schemas[validation_metadata.path_to_item].add(cls) - - if hasattr(cls, "_enum_by_value"): - cls._validate_enum_value(arg) - return path_to_schemas - - if base_class is none_type or base_class is bool: - return path_to_schemas - path_to_schemas[validation_metadata.path_to_item].add(base_class) return path_to_schemas - @classmethod - def _validate_enum_value(cls, arg): - try: - cls._enum_by_value[arg] - except KeyError: - raise ApiValueError("Invalid value {} passed in to {}, {}".format(arg, cls, cls._enum_value_to_name)) + @staticmethod + def __process_schema_classes( + schema_classes: typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]] + ): + """ + Processes and mutates schema_classes + If a SomeSchema is a subclass of DictSchema then remove DictSchema because it is already included + """ + if len(schema_classes) < 2: + return + x_schema = schema_type_classes & schema_classes + if not x_schema: + return + x_schema = x_schema.pop() + if any(c is not x_schema and issubclass(c, x_schema) for c in schema_classes): + # needed to not have a mro error in get_new_class + schema_classes.remove(x_schema) @classmethod def __get_new_cls( @@ -1387,51 +1316,35 @@ class Schema: and in list/dict _get_items,_get_properties the value will be directly assigned because value is of the correct type, and validation was run earlier when the instance was created """ - _path_to_schemas = cls._validate(arg, validation_metadata=validation_metadata) + _path_to_schemas = {} + if validation_metadata.validated_path_to_schemas: + update(_path_to_schemas, validation_metadata.validated_path_to_schemas) + if not validation_metadata.validation_ran_earlier(cls): + other_path_to_schemas = cls._validate(arg, validation_metadata=validation_metadata) + update(_path_to_schemas, other_path_to_schemas) # loop through it make a new class for each entry # do not modify the returned result because it is cached and we would be modifying the cached value path_to_schemas = {} for path, schema_classes in _path_to_schemas.items(): + """ + Use cases + 1. N number of schema classes + enum + type != bool/None, classes in path_to_schemas: tuple/frozendict/str/Decimal/bytes/FileIo + needs Singleton added + 2. N number of schema classes + enum + type == bool/None, classes in path_to_schemas: BoolClass/NoneClass + Singleton already added + 3. N number of schema classes, classes in path_to_schemas: BoolClass/NoneClass/tuple/frozendict/str/Decimal/bytes/FileIo + """ + cls.__process_schema_classes(schema_classes) enum_schema = any( - hasattr(this_cls, '_enum_by_value') for this_cls in schema_classes) + hasattr(this_cls, '_enum_value_to_name') for this_cls in schema_classes) inheritable_primitive_type = schema_classes.intersection(inheritable_primitive_types_set) - chosen_schema_classes = schema_classes - suffix = tuple() - if inheritable_primitive_type: - chosen_schema_classes = schema_classes - inheritable_primitive_types_set - if not enum_schema: - # include the inheritable_primitive_type - suffix = tuple(inheritable_primitive_type) + chosen_schema_classes = schema_classes - inheritable_primitive_type + suffix = tuple(inheritable_primitive_type) + if enum_schema and suffix[0] not in {NoneClass, BoolClass}: + suffix = (Singleton,) + suffix - if len(chosen_schema_classes) == 1 and not suffix: - mfg_cls = tuple(chosen_schema_classes)[0] - else: - x_schema = schema_descendents & chosen_schema_classes - if x_schema: - x_schema = x_schema.pop() - if any(c is not x_schema and issubclass(c, x_schema) for c in chosen_schema_classes): - # needed to not have a mro error in get_new_class - chosen_schema_classes.remove(x_schema) - used_classes = tuple(sorted(chosen_schema_classes, key=lambda a_cls: a_cls.__name__)) + suffix - mfg_cls = get_new_class(class_name='DynamicSchema', bases=used_classes) - - if inheritable_primitive_type and not enum_schema: - path_to_schemas[path] = mfg_cls - continue - - # Use case: value is None, True, False, or an enum value - value = arg - for key in path[1:]: - # if path is bigger than one, get the value that mfg_cls validated - value = value[key] - if hasattr(mfg_cls, '_enum_by_value'): - mfg_cls = mfg_cls._enum_by_value[value] - elif value in {True, False}: - mfg_cls = mfg_cls._class_by_base_class(bool) - elif value is None: - mfg_cls = mfg_cls._class_by_base_class(none_type) - else: - raise ApiValueError('Unhandled case value={} bases={}'.format(value, mfg_cls.__bases__)) + used_classes = tuple(sorted(chosen_schema_classes, key=lambda a_cls: a_cls.__name__)) + suffix + mfg_cls = get_new_class(class_name='DynamicSchema', bases=used_classes) path_to_schemas[path] = mfg_cls return path_to_schemas @@ -1445,6 +1358,7 @@ class Schema: ): # We have a Dynamic class and we are making an instance of it if issubclass(cls, frozendict): + print(cls.__bases__) properties = cls._get_properties(arg, path_to_item, path_to_schemas) return super(Schema, cls).__new__(cls, properties) elif issubclass(cls, tuple): @@ -1484,8 +1398,11 @@ class Schema: """ Schema _from_openapi_data """ - arg = cast_to_allowed_types(arg, from_server=True) - validation_metadata = ValidationMetadata(from_server=True, configuration=_configuration) + from_server = True + validated_path_to_schemas = {} + arg = cast_to_allowed_types(arg, from_server, validated_path_to_schemas) + validation_metadata = ValidationMetadata( + from_server=from_server, configuration=_configuration, validated_path_to_schemas=validated_path_to_schemas) path_to_schemas = cls.__get_new_cls(arg, validation_metadata) new_cls = path_to_schemas[validation_metadata.path_to_item] new_inst = new_cls._get_new_instance_without_conversion( @@ -1527,8 +1444,12 @@ class Schema: arg = args[0] else: arg = cls.__get_input_dict(*args, **kwargs) - validation_metadata = ValidationMetadata(configuration=_configuration, from_server=False) - arg = cast_to_allowed_types(arg, from_server=validation_metadata.from_server) + from_server = False + validated_path_to_schemas = {} + arg = cast_to_allowed_types( + arg, from_server, validated_path_to_schemas) + validation_metadata = ValidationMetadata( + configuration=_configuration, from_server=from_server, validated_path_to_schemas=validated_path_to_schemas) path_to_schemas = cls.__get_new_cls(arg, validation_metadata) new_cls = path_to_schemas[validation_metadata.path_to_item] return new_cls._get_new_instance_without_conversion( @@ -1555,22 +1476,53 @@ class Schema: pass -def cast_to_allowed_types(arg: typing.Union[str, date, datetime, decimal.Decimal, int, float, None, dict, frozendict, list, tuple, bytes, Schema], from_server=False) -> typing.Union[str, bytes, decimal.Decimal, None, frozendict, tuple, Schema]: +def cast_to_allowed_types( + arg: typing.Union[str, date, datetime, uuid.UUID, decimal.Decimal, int, float, None, dict, frozendict, list, tuple, bytes, Schema], + from_server: bool, + validated_path_to_schemas: typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]], + path_to_item: typing.Tuple[typing.Union[str, int], ...] = tuple(['args[0]']), +) -> typing.Union[frozendict, tuple, decimal.Decimal, str, bytes, BoolClass, NoneClass, FileIO]: """ - from_server=False date, datetime -> str - int, float -> Decimal - StrSchema will convert that to bytes and remember the encoding when we pass in str input + Casts the input payload arg into the allowed types + The input validated_path_to_schemas is mutated by running this function + + When from_server is False then + - date/datetime is cast to str + - int/float is cast to Decimal + + If a Schema instance is passed in it is converted back to a primitive instance because + One may need to validate that data to the original Schema class AND additional different classes + those additional classes will need to be added to the new manufactured class for that payload + If the code didn't do this and kept the payload as a Schema instance it would fail to validate to other + Schema classes and the code wouldn't be able to mfg a new class that includes all valid schemas + TODO: store the validated schema classes in validation_metadata + + Args: + arg: the payload + from_server: whether this payload came from the server or not + validated_path_to_schemas: a dict that stores the validated classes at any path location in the payload """ + if isinstance(arg, Schema): + # store the already run validations + schema_classes = set() + for cls in arg.__class__.__bases__: + if cls is Singleton: + continue + schema_classes.add(cls) + validated_path_to_schemas[path_to_item] = schema_classes + if isinstance(arg, str): - return arg - elif type(arg) is dict or type(arg) is frozendict: - return frozendict({key: cast_to_allowed_types(val) for key, val in arg.items()}) - elif isinstance(arg, bool): + return str(arg) + elif isinstance(arg, (dict, frozendict)): + return frozendict({key: cast_to_allowed_types(val, from_server, validated_path_to_schemas, path_to_item + (key,)) for key, val in arg.items()}) + elif isinstance(arg, (bool, BoolClass)): """ this check must come before isinstance(arg, (int, float)) because isinstance(True, int) is True """ - return arg + if arg: + return BoolClass.TRUE + return BoolClass.FALSE elif isinstance(arg, int): return decimal.Decimal(arg) elif isinstance(arg, float): @@ -1580,10 +1532,10 @@ def cast_to_allowed_types(arg: typing.Union[str, date, datetime, decimal.Decimal # 3.4028234663852886e+38 -> Decimal('340282346638528859811704183484516925440.0') return decimal.Decimal(str(decimal_from_float)+'.0') return decimal_from_float - elif type(arg) is list or type(arg) is tuple: - return tuple([cast_to_allowed_types(item) for item in arg]) - elif arg is None: - return arg + elif isinstance(arg, (tuple, list)): + return tuple([cast_to_allowed_types(item, from_server, validated_path_to_schemas, path_to_item + (i,)) for i, item in enumerate(arg)]) + elif isinstance(arg, (none_type, NoneClass)): + return NoneClass.NONE elif isinstance(arg, (date, datetime)): if not from_server: return arg.isoformat() @@ -1595,17 +1547,11 @@ def cast_to_allowed_types(arg: typing.Union[str, date, datetime, decimal.Decimal # ApiTypeError will be thrown later by _validate_type return arg elif isinstance(arg, decimal.Decimal): - return arg + return decimal.Decimal(arg) elif isinstance(arg, bytes): - return arg - elif isinstance(arg, decimal.Decimal): - return arg + return bytes(arg) elif isinstance(arg, (io.FileIO, io.BufferedReader)): - if arg.closed: - raise ApiValueError('Invalid file state; file is closed and must be open') - return arg - elif isinstance(arg, Schema): - return arg + return FileIO(arg) raise ValueError('Invalid type passed in got input={} type={}'.format(arg, type(arg))) @@ -1615,7 +1561,7 @@ class ComposedBase(Discriminable): def __get_allof_classes(cls, arg, validation_metadata: ValidationMetadata): path_to_schemas = defaultdict(set) for allof_cls in cls._composed_schemas['allOf']: - if allof_cls in validation_metadata.base_classes: + if validation_metadata.validation_ran_earlier(allof_cls): continue other_path_to_schemas = allof_cls._validate(arg, validation_metadata=validation_metadata) update(path_to_schemas, other_path_to_schemas) @@ -1630,27 +1576,20 @@ class ComposedBase(Discriminable): path_to_schemas: typing.Dict[typing.Tuple, typing.Set[typing.Type[Schema]]] ): oneof_classes = [] - chosen_oneof_cls = None - original_base_classes = validation_metadata.base_classes - new_base_classes = validation_metadata.base_classes path_to_schemas = defaultdict(set) for oneof_cls in cls._composed_schemas['oneOf']: if oneof_cls in path_to_schemas[validation_metadata.path_to_item]: oneof_classes.append(oneof_cls) continue - if isinstance(arg, oneof_cls): - # passed in instance is the correct type - chosen_oneof_cls = oneof_cls + if validation_metadata.validation_ran_earlier(oneof_cls): oneof_classes.append(oneof_cls) continue try: path_to_schemas = oneof_cls._validate(arg, validation_metadata=validation_metadata) - new_base_classes = validation_metadata.base_classes except (ApiValueError, ApiTypeError) as ex: if discriminated_cls is not None and oneof_cls is discriminated_cls: raise ex continue - chosen_oneof_cls = oneof_cls oneof_classes.append(oneof_cls) if not oneof_classes: raise ApiValueError( @@ -1672,15 +1611,9 @@ class ComposedBase(Discriminable): validation_metadata: ValidationMetadata ): anyof_classes = [] - chosen_anyof_cls = None - original_base_classes = validation_metadata.base_classes path_to_schemas = defaultdict(set) for anyof_cls in cls._composed_schemas['anyOf']: - if anyof_cls in validation_metadata.base_classes: - continue - if isinstance(arg, anyof_cls): - # passed in instance is the correct type - chosen_anyof_cls = anyof_cls + if validation_metadata.validation_ran_earlier(anyof_cls): anyof_classes.append(anyof_cls) continue @@ -1690,8 +1623,6 @@ class ComposedBase(Discriminable): if discriminated_cls is not None and anyof_cls is discriminated_cls: raise ex continue - original_base_classes = validation_metadata.base_classes - chosen_anyof_cls = anyof_cls anyof_classes.append(anyof_cls) update(path_to_schemas, other_path_to_schemas) if not anyof_classes: @@ -1706,7 +1637,7 @@ class ComposedBase(Discriminable): cls, arg, validation_metadata: ValidationMetadata, - ): + ) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]]: """ ComposedBase _validate We return dynamic classes of different bases depending upon the inputs @@ -1741,7 +1672,8 @@ class ComposedBase(Discriminable): configuration=validation_metadata.configuration, from_server=validation_metadata.from_server, path_to_item=validation_metadata.path_to_item, - base_classes=validation_metadata.base_classes | frozenset({cls}) + seen_classes=validation_metadata.seen_classes | frozenset({cls}), + validated_path_to_schemas=validation_metadata.validated_path_to_schemas ) # process composed schema @@ -1785,20 +1717,24 @@ class ComposedBase(Discriminable): not_cls = cls._composed_schemas['not'] if not_cls: other_path_to_schemas = None + not_exception = ApiValueError( + "Invalid value '{}' was passed in to {}. Value is invalid because it is disallowed by {}".format( + arg, + cls.__name__, + not_cls.__name__, + ) + ) + if updated_vm.validation_ran_earlier(not_cls): + raise not_exception + try: other_path_to_schemas = not_cls._validate(arg, validation_metadata=updated_vm) except (ApiValueError, ApiTypeError): pass if other_path_to_schemas: - raise ApiValueError( - "Invalid value '{}' was passed in to {}. Value is invalid because it is disallowed by {}".format( - arg, - cls.__name__, - not_cls.__name__, - ) - ) + raise not_exception - if discriminated_cls is not None: + if discriminated_cls is not None and not updated_vm.validation_ran_earlier(discriminated_cls): # TODO use an exception from this package here assert discriminated_cls in path_to_schemas[updated_vm.path_to_item] return path_to_schemas @@ -1806,7 +1742,7 @@ class ComposedBase(Discriminable): # DictBase, ListBase, NumberBase, StrBase, BoolBase, NoneBase class ComposedSchema( - _SchemaTypeChecker(typing.Union[none_type, str, decimal.Decimal, bool, tuple, frozendict]), + _SchemaTypeChecker(typing.Union[NoneClass, str, decimal.Decimal, BoolClass, tuple, frozendict]), ComposedBase, DictBase, ListBase, @@ -1844,7 +1780,7 @@ class ListSchema( class NoneSchema( - _SchemaTypeChecker(typing.Union[none_type]), + _SchemaTypeChecker(typing.Union[NoneClass]), NoneBase, Schema ): @@ -2115,7 +2051,7 @@ class BinarySchema( class BoolSchema( - _SchemaTypeChecker(typing.Union[bool]), + _SchemaTypeChecker(typing.Union[BoolClass]), BoolBase, Schema ): @@ -2130,7 +2066,7 @@ class BoolSchema( class AnyTypeSchema( _SchemaTypeChecker( - typing.Union[frozendict, tuple, decimal.Decimal, str, bool, none_type, bytes, FileIO] + typing.Union[frozendict, tuple, decimal.Decimal, str, BoolClass, NoneClass, bytes, FileIO] ), DictBase, ListBase, @@ -2157,7 +2093,7 @@ class DictSchema( return super().__new__(cls, *args, **kwargs) -schema_descendents = set([NoneSchema, DictSchema, ListSchema, NumberSchema, StrSchema, BoolSchema]) +schema_type_classes = set([NoneSchema, DictSchema, ListSchema, NumberSchema, StrSchema, BoolSchema]) def deserialize_file(response_data, configuration, content_disposition=None): diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/docs/EnumWithFalseDoesNotMatch0.md b/samples/openapi3/client/3_0_3_unit_test/python-experimental/docs/EnumWithFalseDoesNotMatch0.md index f1cef961444..03733e36e0c 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/docs/EnumWithFalseDoesNotMatch0.md +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/docs/EnumWithFalseDoesNotMatch0.md @@ -2,7 +2,7 @@ Type | Description | Notes ------------- | ------------- | ------------- -**bool** | | must be one of [False, ] +**bool** | | must be one of [BoolClass.FALSE, ] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/docs/EnumWithTrueDoesNotMatch1.md b/samples/openapi3/client/3_0_3_unit_test/python-experimental/docs/EnumWithTrueDoesNotMatch1.md index 09723bcb68c..add49387845 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/docs/EnumWithTrueDoesNotMatch1.md +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/docs/EnumWithTrueDoesNotMatch1.md @@ -2,7 +2,7 @@ Type | Description | Notes ------------- | ------------- | ------------- -**bool** | | must be one of [True, ] +**bool** | | must be one of [BoolClass.TRUE, ] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/additionalproperties_allows_a_schema_which_should_validate.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/additionalproperties_allows_a_schema_which_should_validate.py index 8e986da86fc..5f7428df6f0 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/additionalproperties_allows_a_schema_which_should_validate.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/additionalproperties_allows_a_schema_which_should_validate.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/additionalproperties_are_allowed_by_default.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/additionalproperties_are_allowed_by_default.py index 2251b2f815a..f51599e5a37 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/additionalproperties_are_allowed_by_default.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/additionalproperties_are_allowed_by_default.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/additionalproperties_can_exist_by_itself.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/additionalproperties_can_exist_by_itself.py index 383a01af174..7353e1a2495 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/additionalproperties_can_exist_by_itself.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/additionalproperties_can_exist_by_itself.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/additionalproperties_should_not_look_in_applicators.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/additionalproperties_should_not_look_in_applicators.py index 66547528189..11a38935e5d 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/additionalproperties_should_not_look_in_applicators.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/additionalproperties_should_not_look_in_applicators.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/array_type_matches_arrays.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/array_type_matches_arrays.py index 583f9843b64..36f1c01424a 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/array_type_matches_arrays.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/array_type_matches_arrays.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/boolean_type_matches_booleans.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/boolean_type_matches_booleans.py index 93cd0a0505f..405d65fe299 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/boolean_type_matches_booleans.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/boolean_type_matches_booleans.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/by_int.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/by_int.py index c5c44fbdc31..f03594a9430 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/by_int.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/by_int.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/by_number.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/by_number.py index 3bab9445575..5fdee3839eb 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/by_number.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/by_number.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/by_small_number.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/by_small_number.py index 5f96f0cdbdb..078b49c88f8 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/by_small_number.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/by_small_number.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/date_time_format.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/date_time_format.py index 0983f2f5e02..d2a861677dd 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/date_time_format.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/date_time_format.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/email_format.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/email_format.py index e2922a13474..69fcb222399 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/email_format.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/email_format.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/enum_with0_does_not_match_false.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/enum_with0_does_not_match_false.py index 6cb61f6f053..65b18883b74 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/enum_with0_does_not_match_false.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/enum_with0_does_not_match_false.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/enum_with1_does_not_match_true.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/enum_with1_does_not_match_true.py index 6904cda7fa3..48a26545d5e 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/enum_with1_does_not_match_true.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/enum_with1_does_not_match_true.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/enum_with_escaped_characters.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/enum_with_escaped_characters.py index 7db769c23e7..d8394a82a9a 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/enum_with_escaped_characters.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/enum_with_escaped_characters.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/enum_with_false_does_not_match0.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/enum_with_false_does_not_match0.py index 223022bb57b..e58c3e0f3b1 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/enum_with_false_does_not_match0.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/enum_with_false_does_not_match0.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker @@ -69,7 +71,7 @@ from unit_test_api.schemas import ( # noqa: F401 class EnumWithFalseDoesNotMatch0( _SchemaEnumMaker( enum_value_to_name={ - False: "FALSE", + BoolClass.FALSE: "FALSE", } ), BoolSchema @@ -83,4 +85,4 @@ class EnumWithFalseDoesNotMatch0( @classmethod @property def FALSE(cls): - return cls(False) + return cls(BoolClass.FALSE) diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/enum_with_true_does_not_match1.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/enum_with_true_does_not_match1.py index 6e997008625..750921e6038 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/enum_with_true_does_not_match1.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/enum_with_true_does_not_match1.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker @@ -69,7 +71,7 @@ from unit_test_api.schemas import ( # noqa: F401 class EnumWithTrueDoesNotMatch1( _SchemaEnumMaker( enum_value_to_name={ - True: "TRUE", + BoolClass.TRUE: "TRUE", } ), BoolSchema @@ -83,4 +85,4 @@ class EnumWithTrueDoesNotMatch1( @classmethod @property def TRUE(cls): - return cls(True) + return cls(BoolClass.TRUE) diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/enums_in_properties.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/enums_in_properties.py index 192305479fc..bdaf150d826 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/enums_in_properties.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/enums_in_properties.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/forbidden_property.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/forbidden_property.py index 0b1dc6f6a5d..ccdc7ddc587 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/forbidden_property.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/forbidden_property.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/hostname_format.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/hostname_format.py index 89778b24464..c9e0496649e 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/hostname_format.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/hostname_format.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/integer_type_matches_integers.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/integer_type_matches_integers.py index 472bd37aa71..825e64271a6 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/integer_type_matches_integers.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/integer_type_matches_integers.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/invalid_instance_should_not_raise_error_when_float_division_inf.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/invalid_instance_should_not_raise_error_when_float_division_inf.py index 84dcad131b2..8d6290fc262 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/invalid_instance_should_not_raise_error_when_float_division_inf.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/invalid_instance_should_not_raise_error_when_float_division_inf.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/invalid_string_value_for_default.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/invalid_string_value_for_default.py index 07ad386d3b8..827fe681241 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/invalid_string_value_for_default.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/invalid_string_value_for_default.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ipv4_format.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ipv4_format.py index b882729f886..59928308a3d 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ipv4_format.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ipv4_format.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ipv6_format.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ipv6_format.py index 9fa12e3fca7..79234be74fe 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ipv6_format.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ipv6_format.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/json_pointer_format.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/json_pointer_format.py index 670fd1785a1..d2fe143e890 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/json_pointer_format.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/json_pointer_format.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/maximum_validation.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/maximum_validation.py index 155a514da50..5df92433e0d 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/maximum_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/maximum_validation.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/maximum_validation_with_unsigned_integer.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/maximum_validation_with_unsigned_integer.py index 0aa1cb53eb9..950d86909f5 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/maximum_validation_with_unsigned_integer.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/maximum_validation_with_unsigned_integer.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/maxitems_validation.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/maxitems_validation.py index 20b1c37f9fc..c972ac75f4a 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/maxitems_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/maxitems_validation.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/maxlength_validation.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/maxlength_validation.py index daf2ce82f75..de4c7a9acbb 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/maxlength_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/maxlength_validation.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/maxproperties0_means_the_object_is_empty.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/maxproperties0_means_the_object_is_empty.py index 12231672ec2..c601df9f01c 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/maxproperties0_means_the_object_is_empty.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/maxproperties0_means_the_object_is_empty.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/maxproperties_validation.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/maxproperties_validation.py index 30b4e4d2158..f88050876c7 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/maxproperties_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/maxproperties_validation.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/minimum_validation.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/minimum_validation.py index bbe4414e080..2b4610a446e 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/minimum_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/minimum_validation.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/minimum_validation_with_signed_integer.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/minimum_validation_with_signed_integer.py index c0996a1a84b..8e7bc84dd4c 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/minimum_validation_with_signed_integer.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/minimum_validation_with_signed_integer.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/minitems_validation.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/minitems_validation.py index 14a07dd3414..b2311506841 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/minitems_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/minitems_validation.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/minlength_validation.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/minlength_validation.py index a4ac28a41cb..38933cceefb 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/minlength_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/minlength_validation.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/minproperties_validation.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/minproperties_validation.py index 74861d0b1ff..38e91f35b5a 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/minproperties_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/minproperties_validation.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/model_not.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/model_not.py index 1b1c92f096d..49841aa5162 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/model_not.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/model_not.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/nested_items.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/nested_items.py index 9b5e65ef0a3..c26c7882238 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/nested_items.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/nested_items.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/not_more_complex_schema.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/not_more_complex_schema.py index 66f38098b51..a6b6292f11d 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/not_more_complex_schema.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/not_more_complex_schema.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/nul_characters_in_strings.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/nul_characters_in_strings.py index 04ff26fd643..0ee14c8573c 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/nul_characters_in_strings.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/nul_characters_in_strings.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/null_type_matches_only_the_null_object.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/null_type_matches_only_the_null_object.py index 3ed5b3d6b3b..1c634f9eb14 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/null_type_matches_only_the_null_object.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/null_type_matches_only_the_null_object.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/number_type_matches_numbers.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/number_type_matches_numbers.py index 3b33c38f4cd..dda953a7cd9 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/number_type_matches_numbers.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/number_type_matches_numbers.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/object_properties_validation.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/object_properties_validation.py index a5ac3ccf95d..62b75e4b468 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/object_properties_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/object_properties_validation.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/pattern_is_not_anchored.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/pattern_is_not_anchored.py index 63923788782..cedc5529c77 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/pattern_is_not_anchored.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/pattern_is_not_anchored.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/pattern_validation.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/pattern_validation.py index 60d4530a637..2e80e68fc4d 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/pattern_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/pattern_validation.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/properties_with_escaped_characters.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/properties_with_escaped_characters.py index 5b1aceb23a4..e002e235506 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/properties_with_escaped_characters.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/properties_with_escaped_characters.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/property_named_ref_that_is_not_a_reference.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/property_named_ref_that_is_not_a_reference.py index 0f3628abc04..e041626a9a2 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/property_named_ref_that_is_not_a_reference.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/property_named_ref_that_is_not_a_reference.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ref_in_additionalproperties.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ref_in_additionalproperties.py index e9a1d9100a4..06a4940e935 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ref_in_additionalproperties.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ref_in_additionalproperties.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ref_in_allof.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ref_in_allof.py index 927d0c2530b..692e23e079a 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ref_in_allof.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ref_in_allof.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ref_in_anyof.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ref_in_anyof.py index 989ff30c91b..50a541d05dd 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ref_in_anyof.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ref_in_anyof.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ref_in_items.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ref_in_items.py index 9253eeeacc6..e9c980b72ce 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ref_in_items.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ref_in_items.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ref_in_oneof.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ref_in_oneof.py index 43ea96899ba..073d08ab9a7 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ref_in_oneof.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ref_in_oneof.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ref_in_property.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ref_in_property.py index e0f43592bbb..9dfabb68918 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ref_in_property.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/ref_in_property.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/required_default_validation.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/required_default_validation.py index 94993796890..3a5232f50ed 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/required_default_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/required_default_validation.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/required_validation.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/required_validation.py index a0d4c00017a..e8bb57f4fc5 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/required_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/required_validation.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/required_with_empty_array.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/required_with_empty_array.py index 4a7a203a126..1c9b31e6c39 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/required_with_empty_array.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/required_with_empty_array.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/simple_enum_validation.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/simple_enum_validation.py index 86f28a9dae3..53f2c567d22 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/simple_enum_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/simple_enum_validation.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/string_type_matches_strings.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/string_type_matches_strings.py index f1c3c9a0302..7f9e3f1d4b7 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/string_type_matches_strings.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/string_type_matches_strings.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/the_default_keyword_does_not_do_anything_if_the_property_is_missing.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/the_default_keyword_does_not_do_anything_if_the_property_is_missing.py index d59150db52b..342399c3dd7 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/the_default_keyword_does_not_do_anything_if_the_property_is_missing.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/the_default_keyword_does_not_do_anything_if_the_property_is_missing.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/uniqueitems_false_validation.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/uniqueitems_false_validation.py index 43b48358347..b44bd081856 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/uniqueitems_false_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/uniqueitems_false_validation.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/uniqueitems_validation.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/uniqueitems_validation.py index 7680173ee8b..799794310f0 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/uniqueitems_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/uniqueitems_validation.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/uri_format.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/uri_format.py index 61c87a3c4cf..8599fa87d50 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/uri_format.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/uri_format.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/uri_reference_format.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/uri_reference_format.py index 92c7c4fc73f..791ac4d70a6 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/uri_reference_format.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/uri_reference_format.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/uri_template_format.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/uri_template_format.py index 636b9b2f272..8a2e90d1064 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/uri_template_format.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/model/uri_template_format.py @@ -60,6 +60,8 @@ from unit_test_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/schemas.py b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/schemas.py index ad7860b5ca1..987bcf4f644 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/schemas.py +++ b/samples/openapi3/client/3_0_3_unit_test/python-experimental/unit_test_api/schemas.py @@ -53,12 +53,17 @@ class FileIO(io.FileIO): def __new__(cls, arg: typing.Union[io.FileIO, io.BufferedReader]): if isinstance(arg, (io.FileIO, io.BufferedReader)): + if arg.closed: + raise ApiValueError('Invalid file state; file is closed and must be open') arg.close() inst = super(FileIO, cls).__new__(cls, arg.name) super(FileIO, inst).__init__(arg.name) return inst raise ApiValueError('FileIO must be passed arg which contains the open file') + def __init__(self, arg: typing.Union[io.FileIO, io.BufferedReader]): + pass + def update(d: dict, u: dict): """ @@ -85,29 +90,46 @@ class ValidationMetadata(frozendict): path_to_item: typing.Tuple[typing.Union[str, int], ...] = tuple(['args[0]']), from_server: bool = False, configuration: typing.Optional[Configuration] = None, - base_classes: typing.FrozenSet[typing.Type] = frozenset(), + seen_classes: typing.FrozenSet[typing.Type] = frozenset(), + validated_path_to_schemas: typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set['Schema']] = frozendict() ): """ Args: path_to_item: the path to the current data being instantiated. For {'a': [1]} if the code is handling, 1, then the path is ('args[0]', 'a', 0) + This changes from location to location from_server: whether or not this data came form the server True when receiving server data False when instantiating model with client side data not form the server + This does not change from location to location configuration: the Configuration instance to use This is needed because in Configuration: - one can disable validation checking - base_classes: when deserializing data that matches multiple schemas, this is used to store + This does not change from location to location + seen_classes: when deserializing data that matches multiple schemas, this is used to store the schemas that have been traversed. This is used to stop processing when a cycle is seen. + This changes from location to location + validated_path_to_schemas: stores the already validated schema classes for a given path location + This does not change from location to location """ return super().__new__( cls, path_to_item=path_to_item, from_server=from_server, configuration=configuration, - base_classes=base_classes, + seen_classes=seen_classes, + validated_path_to_schemas=validated_path_to_schemas ) + def validation_ran_earlier(self, cls: type) -> bool: + validated_schemas = self.validated_path_to_schemas.get(self.path_to_item, set()) + validation_ran_earlier = validated_schemas and cls in validated_schemas + if validation_ran_earlier: + return True + if cls in self.seen_classes: + return True + return False + @property def path_to_item(self) -> typing.Tuple[typing.Union[str, int], ...]: return self.get('path_to_item') @@ -121,8 +143,12 @@ class ValidationMetadata(frozendict): return self.get('configuration') @property - def base_classes(self) -> typing.FrozenSet[typing.Type]: - return self.get('base_classes') + def seen_classes(self) -> typing.FrozenSet[typing.Type]: + return self.get('seen_classes') + + @property + def validated_path_to_schemas(self) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set['Schema']]: + return self.get('validated_path_to_schemas') class ValidatorBase: @@ -201,31 +227,6 @@ class ValidatorBase: path_to_item=validation_metadata.path_to_item ) - @classmethod - def __data_with_boolclass_instead_of_bool(cls, data: typing.Any) -> typing.Any: - """ - In python bool is a subclass of int so 1 == True and 0 == False - This prevents code from being able to see the difference between 1 and True and 0 and False - To fix this swap in BoolClass singletons for True and False so they will differ from integers - """ - if isinstance(data, (list, tuple)): - new_data = [] - for item in data: - new_item = cls.__data_with_boolclass_instead_of_bool(item) - new_data.append(new_item) - return tuple(new_data) - elif isinstance(data, (dict, frozendict)): - new_data = {} - for key, value in data.items(): - new_value = cls.__data_with_boolclass_instead_of_bool(value) - new_data[key] = new_value - return frozendict(new_data) - elif isinstance(data, bool): - if data: - return BoolClass.TRUE - return BoolClass.FALSE - return data - @classmethod def __check_tuple_validations( cls, validations, input_values, @@ -253,7 +254,7 @@ class ValidatorBase: if (cls.__is_json_validation_enabled('uniqueItems', validation_metadata.configuration) and 'unique_items' in validations and validations['unique_items'] and input_values): - unique_items = set(cls.__data_with_boolclass_instead_of_bool(input_values)) + unique_items = set(input_values) if len(input_values) > len(unique_items): cls.__raise_validation_error_message( value=input_values, @@ -369,128 +370,6 @@ class ValidatorBase: cls.__check_dict_validations(validations, input_values, validation_metadata) elif isinstance(input_values, decimal.Decimal): cls.__check_numeric_validations(validations, input_values, validation_metadata) - try: - return super()._validate_validations_pass(input_values, validation_metadata) - except AttributeError: - return True - - -class Validator(typing.Protocol): - def _validate_validations_pass( - cls, - input_values, - validation_metadata: ValidationMetadata - ): - pass - - -def _SchemaValidator(**validations: typing.Union[str, bool, None, int, float, list[dict[str, typing.Union[str, int, float]]]]) -> Validator: - class SchemaValidator(ValidatorBase): - @classmethod - def _validate_validations_pass( - cls, - input_values, - validation_metadata: ValidationMetadata - ): - cls._check_validations_for_types(validations, input_values, validation_metadata) - try: - return super()._validate_validations_pass(input_values, validation_metadata) - except AttributeError: - return True - - return SchemaValidator - - -class TypeChecker(typing.Protocol): - @classmethod - def _validate_type( - cls, arg_simple_class: type - ) -> typing.Tuple[type]: - pass - - -def _SchemaTypeChecker(union_type_cls: typing.Union[typing.Any]) -> TypeChecker: - if typing.get_origin(union_type_cls) is typing.Union: - union_classes = typing.get_args(union_type_cls) - else: - # note: when a union of a single class is passed in, the union disappears - union_classes = tuple([union_type_cls]) - """ - I want the type hint... union_type_cls - and to use it as a base class but when I do, I get - TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - """ - class SchemaTypeChecker: - @classmethod - def _validate_type(cls, arg_simple_class: type): - if arg_simple_class not in union_classes: - return union_classes - try: - return super()._validate_type(arg_simple_class) - except AttributeError: - return tuple() - - return SchemaTypeChecker - - -class EnumMakerBase: - @classmethod - @property - def _enum_by_value( - cls - ) -> type: - enum_classes = {} - if not hasattr(cls, "_enum_value_to_name"): - return enum_classes - for enum_value, enum_name in cls._enum_value_to_name.items(): - base_class = type(enum_value) - if base_class is none_type: - enum_classes[enum_value] = get_new_class( - "Dynamic" + cls.__name__, (cls, NoneClass)) - log_cache_usage(get_new_class) - elif base_class is bool: - enum_classes[enum_value] = get_new_class( - "Dynamic" + cls.__name__, (cls, BoolClass)) - log_cache_usage(get_new_class) - else: - enum_classes[enum_value] = get_new_class( - "Dynamic" + cls.__name__, (cls, Singleton, base_class)) - log_cache_usage(get_new_class) - return enum_classes - - -class EnumMakerInterface(typing.Protocol): - @classmethod - @property - def _enum_value_to_name( - cls - ) -> typing.Dict[typing.Union[str, decimal.Decimal, bool, none_type], str]: - pass - - @classmethod - @property - def _enum_by_value( - cls - ) -> type: - pass - - -def _SchemaEnumMaker(enum_value_to_name: typing.Dict[typing.Union[str, decimal.Decimal, bool, none_type], str]) -> EnumMakerInterface: - class SchemaEnumMaker(EnumMakerBase): - @classmethod - @property - def _enum_value_to_name( - cls - ) -> typing.Dict[typing.Union[str, decimal.Decimal, bool, none_type], str]: - pass - try: - super_enum_value_to_name = super()._enum_value_to_name - except AttributeError: - return enum_value_to_name - intersection = dict(enum_value_to_name.items() & super_enum_value_to_name.items()) - return intersection - - return SchemaEnumMaker class Singleton: @@ -505,7 +384,12 @@ class Singleton: if key not in cls._instances: if arg in {None, True, False}: inst = super().__new__(cls) - # inst._value = arg + cls._instances[key] = inst + elif isinstance(arg, BoolClass): + inst = super().__new__(cls) + cls._instances[key] = inst + elif isinstance(arg, NoneClass): + inst = super().__new__(cls) cls._instances[key] = inst else: cls._instances[key] = super().__new__(cls, arg) @@ -515,7 +399,7 @@ class Singleton: if isinstance(self, NoneClass): return f'<{self.__class__.__name__}: None>' elif isinstance(self, BoolClass): - if (self.__class__, True) in self._instances: + if bool(self): return f'<{self.__class__.__name__}: True>' return f'<{self.__class__.__name__}: False>' return f'<{self.__class__.__name__}: {super().__repr__()}>' @@ -546,10 +430,171 @@ class BoolClass(Singleton): def __bool__(self) -> bool: for key, instance in self._instances.items(): if self is instance: - return key[1] + return bool(key[1]) raise ValueError('Unable to find the boolean value of this instance') +class Validator(typing.Protocol): + @classmethod + def _validate( + cls, + arg, + validation_metadata: ValidationMetadata, + ) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]]: + pass + + +def _SchemaValidator(**validations: typing.Union[str, bool, None, int, float, list[dict[str, typing.Union[str, int, float]]]]) -> Validator: + class SchemaValidator(ValidatorBase): + @classmethod + def _validate( + cls, + arg, + validation_metadata: ValidationMetadata, + ) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]]: + """ + SchemaValidator _validate + Validates that validations pass + """ + cls._check_validations_for_types(validations, arg, validation_metadata) + return super()._validate(arg, validation_metadata) + + return SchemaValidator + + +def _SchemaTypeChecker(union_type_cls: typing.Union[typing.Any]) -> Validator: + if typing.get_origin(union_type_cls) is typing.Union: + union_classes = typing.get_args(union_type_cls) + else: + # note: when a union of a single class is passed in, the union disappears + union_classes = tuple([union_type_cls]) + """ + I want the type hint... union_type_cls + and to use it as a base class but when I do, I get + TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases + """ + class SchemaTypeChecker: + @staticmethod + def __get_valid_classes_phrase(input_classes): + """Returns a string phrase describing what types are allowed""" + all_classes = list(input_classes) + all_classes = sorted(all_classes, key=lambda cls: cls.__name__) + all_class_names = [cls.__name__ for cls in all_classes] + if len(all_class_names) == 1: + return "is {0}".format(all_class_names[0]) + return "is one of [{0}]".format(", ".join(all_class_names)) + + @classmethod + def __type_error_message( + cls, var_value=None, var_name=None, valid_classes=None, key_type=None + ): + """ + Keyword Args: + var_value (any): the variable which has the type_error + var_name (str): the name of the variable which has the typ error + valid_classes (tuple): the accepted classes for current_item's + value + key_type (bool): False if our value is a value in a dict + True if it is a key in a dict + False if our item is an item in a tuple + """ + key_or_value = "value" + if key_type: + key_or_value = "key" + valid_classes_phrase = cls.__get_valid_classes_phrase(valid_classes) + msg = "Invalid type. Required {1} type {2} and " "passed type was {3}".format( + var_name, + key_or_value, + valid_classes_phrase, + type(var_value).__name__, + ) + return msg + + @classmethod + def _get_type_error(cls, var_value, path_to_item, valid_classes, key_type=False): + error_msg = cls.__type_error_message( + var_name=path_to_item[-1], + var_value=var_value, + valid_classes=valid_classes, + key_type=key_type, + ) + return ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=valid_classes, + key_type=key_type, + ) + + @classmethod + def _validate( + cls, + arg, + validation_metadata: ValidationMetadata, + ) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]]: + """ + SchemaTypeChecker _validate + Validates arg's type + """ + arg_type = type(arg) + if arg_type in union_classes: + return super()._validate(arg, validation_metadata) + raise cls._get_type_error( + arg, + validation_metadata.path_to_item, + union_classes, + key_type=False, + ) + + return SchemaTypeChecker + + +class EnumMakerBase: + pass + + +class EnumMakerInterface(Validator): + @classmethod + @property + def _enum_value_to_name( + cls + ) -> typing.Dict[typing.Union[str, decimal.Decimal, bool, none_type], str]: + pass + + +def _SchemaEnumMaker(enum_value_to_name: typing.Dict[typing.Union[str, decimal.Decimal, bool, none_type], str]) -> EnumMakerInterface: + class SchemaEnumMaker(EnumMakerBase): + @classmethod + @property + def _enum_value_to_name( + cls + ) -> typing.Dict[typing.Union[str, decimal.Decimal, bool, none_type], str]: + pass + try: + super_enum_value_to_name = super()._enum_value_to_name + except AttributeError: + return enum_value_to_name + intersection = dict(enum_value_to_name.items() & super_enum_value_to_name.items()) + return intersection + + @classmethod + def _validate( + cls, + arg, + validation_metadata: ValidationMetadata, + ) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]]: + """ + SchemaEnumMaker _validate + Validates that arg is in the enum's allowed values + """ + try: + cls._enum_value_to_name[arg] + except KeyError: + raise ApiValueError("Invalid value {} passed in to {}, {}".format(arg, cls, cls._enum_value_to_name)) + return super()._validate(arg, validation_metadata) + + return SchemaEnumMaker + + class BoolBase: def is_true(self) -> bool: """ @@ -821,13 +866,14 @@ class ListBase: item_cls = getattr(cls, '_items', AnyTypeSchema) path_to_schemas = {} for i, value in enumerate(list_items): - if isinstance(value, item_cls): - continue item_validation_metadata = ValidationMetadata( from_server=validation_metadata.from_server, configuration=validation_metadata.configuration, - path_to_item=validation_metadata.path_to_item+(i,) + path_to_item=validation_metadata.path_to_item+(i,), + validated_path_to_schemas=validation_metadata.validated_path_to_schemas ) + if item_validation_metadata.validation_ran_earlier(item_cls): + continue other_path_to_schemas = item_cls._validate( value, validation_metadata=item_validation_metadata) update(path_to_schemas, other_path_to_schemas) @@ -857,14 +903,12 @@ class ListBase: _path_to_schemas = super()._validate(arg, validation_metadata=validation_metadata) if not isinstance(arg, tuple): return _path_to_schemas - if cls in validation_metadata.base_classes: - # we have already moved through this class so stop here - return _path_to_schemas updated_vm = ValidationMetadata( configuration=validation_metadata.configuration, from_server=validation_metadata.from_server, path_to_item=validation_metadata.path_to_item, - base_classes=validation_metadata.base_classes | frozenset({cls}) + seen_classes=validation_metadata.seen_classes | frozenset({cls}), + validated_path_to_schemas=validation_metadata.validated_path_to_schemas ) other_path_to_schemas = cls._validate_items(arg, validation_metadata=updated_vm) update(_path_to_schemas, other_path_to_schemas) @@ -1030,13 +1074,14 @@ class DictBase(Discriminable): raise ApiTypeError('Unable to find schema for value={} in class={} at path_to_item={}'.format( value, cls, validation_metadata.path_to_item+(property_name,) )) - if isinstance(value, schema): - continue arg_validation_metadata = ValidationMetadata( from_server=validation_metadata.from_server, configuration=validation_metadata.configuration, - path_to_item=validation_metadata.path_to_item+(property_name,) + path_to_item=validation_metadata.path_to_item+(property_name,), + validated_path_to_schemas=validation_metadata.validated_path_to_schemas ) + if arg_validation_metadata.validation_ran_earlier(schema): + continue other_path_to_schemas = schema._validate(value, validation_metadata=arg_validation_metadata) update(path_to_schemas, other_path_to_schemas) return path_to_schemas @@ -1089,15 +1134,15 @@ class DictBase(Discriminable): validation_metadata.path_to_item + (disc_prop_name,) ) ) - if discriminated_cls in validation_metadata.base_classes: - # we have already moved through this class so stop here - return _path_to_schemas updated_vm = ValidationMetadata( configuration=validation_metadata.configuration, from_server=validation_metadata.from_server, path_to_item=validation_metadata.path_to_item, - base_classes=validation_metadata.base_classes | frozenset({cls}) + seen_classes=validation_metadata.seen_classes | frozenset({cls}), + validated_path_to_schemas=validation_metadata.validated_path_to_schemas ) + if updated_vm.validation_ran_earlier(discriminated_cls): + return _path_to_schemas other_path_to_schemas = discriminated_cls._validate(arg, validation_metadata=updated_vm) update(_path_to_schemas, other_path_to_schemas) return _path_to_schemas @@ -1185,7 +1230,7 @@ class DictBase(Discriminable): return super().__getattribute__(name) -inheritable_primitive_types_set = {decimal.Decimal, str, tuple, frozendict, FileIO, bytes} +inheritable_primitive_types_set = {decimal.Decimal, str, tuple, frozendict, FileIO, bytes, BoolClass, NoneClass} class Schema: @@ -1198,117 +1243,12 @@ class Schema: - payload value is an allowed enum value """ - @staticmethod - def __get_simple_class(input_value): - """Returns an input_value's simple class that we will use for type checking - - Args: - input_value (class/class_instance): the item for which we will return - the simple class - """ - if isinstance(input_value, tuple): - return tuple - elif isinstance(input_value, frozendict): - return frozendict - elif isinstance(input_value, none_type): - return none_type - elif isinstance(input_value, bytes): - return bytes - elif isinstance(input_value, (io.FileIO, io.BufferedReader)): - return FileIO - elif isinstance(input_value, bool): - # this must be higher than the int check because - # isinstance(True, int) == True - return bool - elif isinstance(input_value, int): - return int - elif isinstance(input_value, float): - return float - elif isinstance(input_value, datetime): - # this must be higher than the date check because - # isinstance(datetime_instance, date) == True - return datetime - elif isinstance(input_value, date): - return date - elif isinstance(input_value, str): - return str - return type(input_value) - - @staticmethod - def __get_valid_classes_phrase(input_classes): - """Returns a string phrase describing what types are allowed""" - all_classes = list(input_classes) - all_classes = sorted(all_classes, key=lambda cls: cls.__name__) - all_class_names = [cls.__name__ for cls in all_classes] - if len(all_class_names) == 1: - return "is {0}".format(all_class_names[0]) - return "is one of [{0}]".format(", ".join(all_class_names)) - - @classmethod - def __type_error_message( - cls, var_value=None, var_name=None, valid_classes=None, key_type=None - ): - """ - Keyword Args: - var_value (any): the variable which has the type_error - var_name (str): the name of the variable which has the typ error - valid_classes (tuple): the accepted classes for current_item's - value - key_type (bool): False if our value is a value in a dict - True if it is a key in a dict - False if our item is an item in a tuple - """ - key_or_value = "value" - if key_type: - key_or_value = "key" - valid_classes_phrase = cls.__get_valid_classes_phrase(valid_classes) - msg = "Invalid type. Required {1} type {2} and " "passed type was {3}".format( - var_name, - key_or_value, - valid_classes_phrase, - type(var_value).__name__, - ) - return msg - - @classmethod - def __get_type_error(cls, var_value, path_to_item, valid_classes, key_type=False): - error_msg = cls.__type_error_message( - var_name=path_to_item[-1], - var_value=var_value, - valid_classes=valid_classes, - key_type=key_type, - ) - return ApiTypeError( - error_msg, - path_to_item=path_to_item, - valid_classes=valid_classes, - key_type=key_type, - ) - - @classmethod - def _class_by_base_class(cls, base_cls: type) -> type: - cls_name = "Dynamic"+cls.__name__ - if base_cls is bool: - new_cls = get_new_class(cls_name, (cls, BoolBase, BoolClass)) - elif base_cls is str: - new_cls = get_new_class(cls_name, (cls, StrBase, str)) - elif base_cls is decimal.Decimal: - new_cls = get_new_class(cls_name, (cls, NumberBase, decimal.Decimal)) - elif base_cls is tuple: - new_cls = get_new_class(cls_name, (cls, ListBase, tuple)) - elif base_cls is frozendict: - new_cls = get_new_class(cls_name, (cls, DictBase, frozendict)) - elif base_cls is none_type: - new_cls = get_new_class(cls_name, (cls, NoneBase, NoneClass)) - log_cache_usage(get_new_class) - return new_cls - @classmethod def _validate( cls, arg, validation_metadata: ValidationMetadata, - ): + ) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]]: """ Schema _validate Runs all schema validation logic and @@ -1320,9 +1260,7 @@ class Schema: Use cases: 1. inheritable type: string/decimal.Decimal/frozendict/tuple - 2. enum value cases: 'hi', 1 -> no base_class set because the enum includes the base class - 3. uninheritable type: True/False/None -> no base_class because the base class is not inheritable - _enum_by_value will handle this use case + 2. singletons: bool/None -> uses the base classes BoolClass/NoneClass Required Steps: 1. verify type of input is valid vs the allowed _types @@ -1336,38 +1274,29 @@ class Schema: ApiValueError: when a string can't be converted into a date or datetime and it must be one of those classes ApiTypeError: when the input type is not in the list of allowed spec types """ - base_class = cls.__get_simple_class(arg) - failed_type_check_classes = cls._validate_type(base_class) - if failed_type_check_classes: - raise cls.__get_type_error( - arg, - validation_metadata.path_to_item, - failed_type_check_classes, - key_type=False, - ) - if hasattr(cls, '_validate_validations_pass'): - cls._validate_validations_pass(arg, validation_metadata) - path_to_schemas = {} - if validation_metadata.path_to_item not in path_to_schemas: - path_to_schemas[validation_metadata.path_to_item] = set() + base_class = type(arg) + path_to_schemas = {validation_metadata.path_to_item: set()} path_to_schemas[validation_metadata.path_to_item].add(cls) - - if hasattr(cls, "_enum_by_value"): - cls._validate_enum_value(arg) - return path_to_schemas - - if base_class is none_type or base_class is bool: - return path_to_schemas - path_to_schemas[validation_metadata.path_to_item].add(base_class) return path_to_schemas - @classmethod - def _validate_enum_value(cls, arg): - try: - cls._enum_by_value[arg] - except KeyError: - raise ApiValueError("Invalid value {} passed in to {}, {}".format(arg, cls, cls._enum_value_to_name)) + @staticmethod + def __process_schema_classes( + schema_classes: typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]] + ): + """ + Processes and mutates schema_classes + If a SomeSchema is a subclass of DictSchema then remove DictSchema because it is already included + """ + if len(schema_classes) < 2: + return + x_schema = schema_type_classes & schema_classes + if not x_schema: + return + x_schema = x_schema.pop() + if any(c is not x_schema and issubclass(c, x_schema) for c in schema_classes): + # needed to not have a mro error in get_new_class + schema_classes.remove(x_schema) @classmethod def __get_new_cls( @@ -1394,51 +1323,35 @@ class Schema: and in list/dict _get_items,_get_properties the value will be directly assigned because value is of the correct type, and validation was run earlier when the instance was created """ - _path_to_schemas = cls._validate(arg, validation_metadata=validation_metadata) + _path_to_schemas = {} + if validation_metadata.validated_path_to_schemas: + update(_path_to_schemas, validation_metadata.validated_path_to_schemas) + if not validation_metadata.validation_ran_earlier(cls): + other_path_to_schemas = cls._validate(arg, validation_metadata=validation_metadata) + update(_path_to_schemas, other_path_to_schemas) # loop through it make a new class for each entry # do not modify the returned result because it is cached and we would be modifying the cached value path_to_schemas = {} for path, schema_classes in _path_to_schemas.items(): + """ + Use cases + 1. N number of schema classes + enum + type != bool/None, classes in path_to_schemas: tuple/frozendict/str/Decimal/bytes/FileIo + needs Singleton added + 2. N number of schema classes + enum + type == bool/None, classes in path_to_schemas: BoolClass/NoneClass + Singleton already added + 3. N number of schema classes, classes in path_to_schemas: BoolClass/NoneClass/tuple/frozendict/str/Decimal/bytes/FileIo + """ + cls.__process_schema_classes(schema_classes) enum_schema = any( - hasattr(this_cls, '_enum_by_value') for this_cls in schema_classes) + hasattr(this_cls, '_enum_value_to_name') for this_cls in schema_classes) inheritable_primitive_type = schema_classes.intersection(inheritable_primitive_types_set) - chosen_schema_classes = schema_classes - suffix = tuple() - if inheritable_primitive_type: - chosen_schema_classes = schema_classes - inheritable_primitive_types_set - if not enum_schema: - # include the inheritable_primitive_type - suffix = tuple(inheritable_primitive_type) + chosen_schema_classes = schema_classes - inheritable_primitive_type + suffix = tuple(inheritable_primitive_type) + if enum_schema and suffix[0] not in {NoneClass, BoolClass}: + suffix = (Singleton,) + suffix - if len(chosen_schema_classes) == 1 and not suffix: - mfg_cls = tuple(chosen_schema_classes)[0] - else: - x_schema = schema_descendents & chosen_schema_classes - if x_schema: - x_schema = x_schema.pop() - if any(c is not x_schema and issubclass(c, x_schema) for c in chosen_schema_classes): - # needed to not have a mro error in get_new_class - chosen_schema_classes.remove(x_schema) - used_classes = tuple(sorted(chosen_schema_classes, key=lambda a_cls: a_cls.__name__)) + suffix - mfg_cls = get_new_class(class_name='DynamicSchema', bases=used_classes) - - if inheritable_primitive_type and not enum_schema: - path_to_schemas[path] = mfg_cls - continue - - # Use case: value is None, True, False, or an enum value - value = arg - for key in path[1:]: - # if path is bigger than one, get the value that mfg_cls validated - value = value[key] - if hasattr(mfg_cls, '_enum_by_value'): - mfg_cls = mfg_cls._enum_by_value[value] - elif value in {True, False}: - mfg_cls = mfg_cls._class_by_base_class(bool) - elif value is None: - mfg_cls = mfg_cls._class_by_base_class(none_type) - else: - raise ApiValueError('Unhandled case value={} bases={}'.format(value, mfg_cls.__bases__)) + used_classes = tuple(sorted(chosen_schema_classes, key=lambda a_cls: a_cls.__name__)) + suffix + mfg_cls = get_new_class(class_name='DynamicSchema', bases=used_classes) path_to_schemas[path] = mfg_cls return path_to_schemas @@ -1452,6 +1365,7 @@ class Schema: ): # We have a Dynamic class and we are making an instance of it if issubclass(cls, frozendict): + print(cls.__bases__) properties = cls._get_properties(arg, path_to_item, path_to_schemas) return super(Schema, cls).__new__(cls, properties) elif issubclass(cls, tuple): @@ -1491,8 +1405,11 @@ class Schema: """ Schema _from_openapi_data """ - arg = cast_to_allowed_types(arg, from_server=True) - validation_metadata = ValidationMetadata(from_server=True, configuration=_configuration) + from_server = True + validated_path_to_schemas = {} + arg = cast_to_allowed_types(arg, from_server, validated_path_to_schemas) + validation_metadata = ValidationMetadata( + from_server=from_server, configuration=_configuration, validated_path_to_schemas=validated_path_to_schemas) path_to_schemas = cls.__get_new_cls(arg, validation_metadata) new_cls = path_to_schemas[validation_metadata.path_to_item] new_inst = new_cls._get_new_instance_without_conversion( @@ -1534,8 +1451,12 @@ class Schema: arg = args[0] else: arg = cls.__get_input_dict(*args, **kwargs) - validation_metadata = ValidationMetadata(configuration=_configuration, from_server=False) - arg = cast_to_allowed_types(arg, from_server=validation_metadata.from_server) + from_server = False + validated_path_to_schemas = {} + arg = cast_to_allowed_types( + arg, from_server, validated_path_to_schemas) + validation_metadata = ValidationMetadata( + configuration=_configuration, from_server=from_server, validated_path_to_schemas=validated_path_to_schemas) path_to_schemas = cls.__get_new_cls(arg, validation_metadata) new_cls = path_to_schemas[validation_metadata.path_to_item] return new_cls._get_new_instance_without_conversion( @@ -1562,22 +1483,53 @@ class Schema: pass -def cast_to_allowed_types(arg: typing.Union[str, date, datetime, decimal.Decimal, int, float, None, dict, frozendict, list, tuple, bytes, Schema], from_server=False) -> typing.Union[str, bytes, decimal.Decimal, None, frozendict, tuple, Schema]: +def cast_to_allowed_types( + arg: typing.Union[str, date, datetime, uuid.UUID, decimal.Decimal, int, float, None, dict, frozendict, list, tuple, bytes, Schema], + from_server: bool, + validated_path_to_schemas: typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]], + path_to_item: typing.Tuple[typing.Union[str, int], ...] = tuple(['args[0]']), +) -> typing.Union[frozendict, tuple, decimal.Decimal, str, bytes, BoolClass, NoneClass, FileIO]: """ - from_server=False date, datetime -> str - int, float -> Decimal - StrSchema will convert that to bytes and remember the encoding when we pass in str input + Casts the input payload arg into the allowed types + The input validated_path_to_schemas is mutated by running this function + + When from_server is False then + - date/datetime is cast to str + - int/float is cast to Decimal + + If a Schema instance is passed in it is converted back to a primitive instance because + One may need to validate that data to the original Schema class AND additional different classes + those additional classes will need to be added to the new manufactured class for that payload + If the code didn't do this and kept the payload as a Schema instance it would fail to validate to other + Schema classes and the code wouldn't be able to mfg a new class that includes all valid schemas + TODO: store the validated schema classes in validation_metadata + + Args: + arg: the payload + from_server: whether this payload came from the server or not + validated_path_to_schemas: a dict that stores the validated classes at any path location in the payload """ + if isinstance(arg, Schema): + # store the already run validations + schema_classes = set() + for cls in arg.__class__.__bases__: + if cls is Singleton: + continue + schema_classes.add(cls) + validated_path_to_schemas[path_to_item] = schema_classes + if isinstance(arg, str): - return arg - elif type(arg) is dict or type(arg) is frozendict: - return frozendict({key: cast_to_allowed_types(val) for key, val in arg.items()}) - elif isinstance(arg, bool): + return str(arg) + elif isinstance(arg, (dict, frozendict)): + return frozendict({key: cast_to_allowed_types(val, from_server, validated_path_to_schemas, path_to_item + (key,)) for key, val in arg.items()}) + elif isinstance(arg, (bool, BoolClass)): """ this check must come before isinstance(arg, (int, float)) because isinstance(True, int) is True """ - return arg + if arg: + return BoolClass.TRUE + return BoolClass.FALSE elif isinstance(arg, int): return decimal.Decimal(arg) elif isinstance(arg, float): @@ -1587,10 +1539,10 @@ def cast_to_allowed_types(arg: typing.Union[str, date, datetime, decimal.Decimal # 3.4028234663852886e+38 -> Decimal('340282346638528859811704183484516925440.0') return decimal.Decimal(str(decimal_from_float)+'.0') return decimal_from_float - elif type(arg) is list or type(arg) is tuple: - return tuple([cast_to_allowed_types(item) for item in arg]) - elif arg is None: - return arg + elif isinstance(arg, (tuple, list)): + return tuple([cast_to_allowed_types(item, from_server, validated_path_to_schemas, path_to_item + (i,)) for i, item in enumerate(arg)]) + elif isinstance(arg, (none_type, NoneClass)): + return NoneClass.NONE elif isinstance(arg, (date, datetime)): if not from_server: return arg.isoformat() @@ -1602,17 +1554,11 @@ def cast_to_allowed_types(arg: typing.Union[str, date, datetime, decimal.Decimal # ApiTypeError will be thrown later by _validate_type return arg elif isinstance(arg, decimal.Decimal): - return arg + return decimal.Decimal(arg) elif isinstance(arg, bytes): - return arg - elif isinstance(arg, decimal.Decimal): - return arg + return bytes(arg) elif isinstance(arg, (io.FileIO, io.BufferedReader)): - if arg.closed: - raise ApiValueError('Invalid file state; file is closed and must be open') - return arg - elif isinstance(arg, Schema): - return arg + return FileIO(arg) raise ValueError('Invalid type passed in got input={} type={}'.format(arg, type(arg))) @@ -1622,7 +1568,7 @@ class ComposedBase(Discriminable): def __get_allof_classes(cls, arg, validation_metadata: ValidationMetadata): path_to_schemas = defaultdict(set) for allof_cls in cls._composed_schemas['allOf']: - if allof_cls in validation_metadata.base_classes: + if validation_metadata.validation_ran_earlier(allof_cls): continue other_path_to_schemas = allof_cls._validate(arg, validation_metadata=validation_metadata) update(path_to_schemas, other_path_to_schemas) @@ -1637,27 +1583,20 @@ class ComposedBase(Discriminable): path_to_schemas: typing.Dict[typing.Tuple, typing.Set[typing.Type[Schema]]] ): oneof_classes = [] - chosen_oneof_cls = None - original_base_classes = validation_metadata.base_classes - new_base_classes = validation_metadata.base_classes path_to_schemas = defaultdict(set) for oneof_cls in cls._composed_schemas['oneOf']: if oneof_cls in path_to_schemas[validation_metadata.path_to_item]: oneof_classes.append(oneof_cls) continue - if isinstance(arg, oneof_cls): - # passed in instance is the correct type - chosen_oneof_cls = oneof_cls + if validation_metadata.validation_ran_earlier(oneof_cls): oneof_classes.append(oneof_cls) continue try: path_to_schemas = oneof_cls._validate(arg, validation_metadata=validation_metadata) - new_base_classes = validation_metadata.base_classes except (ApiValueError, ApiTypeError) as ex: if discriminated_cls is not None and oneof_cls is discriminated_cls: raise ex continue - chosen_oneof_cls = oneof_cls oneof_classes.append(oneof_cls) if not oneof_classes: raise ApiValueError( @@ -1679,15 +1618,9 @@ class ComposedBase(Discriminable): validation_metadata: ValidationMetadata ): anyof_classes = [] - chosen_anyof_cls = None - original_base_classes = validation_metadata.base_classes path_to_schemas = defaultdict(set) for anyof_cls in cls._composed_schemas['anyOf']: - if anyof_cls in validation_metadata.base_classes: - continue - if isinstance(arg, anyof_cls): - # passed in instance is the correct type - chosen_anyof_cls = anyof_cls + if validation_metadata.validation_ran_earlier(anyof_cls): anyof_classes.append(anyof_cls) continue @@ -1697,8 +1630,6 @@ class ComposedBase(Discriminable): if discriminated_cls is not None and anyof_cls is discriminated_cls: raise ex continue - original_base_classes = validation_metadata.base_classes - chosen_anyof_cls = anyof_cls anyof_classes.append(anyof_cls) update(path_to_schemas, other_path_to_schemas) if not anyof_classes: @@ -1713,7 +1644,7 @@ class ComposedBase(Discriminable): cls, arg, validation_metadata: ValidationMetadata, - ): + ) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]]: """ ComposedBase _validate We return dynamic classes of different bases depending upon the inputs @@ -1748,7 +1679,8 @@ class ComposedBase(Discriminable): configuration=validation_metadata.configuration, from_server=validation_metadata.from_server, path_to_item=validation_metadata.path_to_item, - base_classes=validation_metadata.base_classes | frozenset({cls}) + seen_classes=validation_metadata.seen_classes | frozenset({cls}), + validated_path_to_schemas=validation_metadata.validated_path_to_schemas ) # process composed schema @@ -1792,20 +1724,24 @@ class ComposedBase(Discriminable): not_cls = cls._composed_schemas['not'] if not_cls: other_path_to_schemas = None + not_exception = ApiValueError( + "Invalid value '{}' was passed in to {}. Value is invalid because it is disallowed by {}".format( + arg, + cls.__name__, + not_cls.__name__, + ) + ) + if updated_vm.validation_ran_earlier(not_cls): + raise not_exception + try: other_path_to_schemas = not_cls._validate(arg, validation_metadata=updated_vm) except (ApiValueError, ApiTypeError): pass if other_path_to_schemas: - raise ApiValueError( - "Invalid value '{}' was passed in to {}. Value is invalid because it is disallowed by {}".format( - arg, - cls.__name__, - not_cls.__name__, - ) - ) + raise not_exception - if discriminated_cls is not None: + if discriminated_cls is not None and not updated_vm.validation_ran_earlier(discriminated_cls): # TODO use an exception from this package here assert discriminated_cls in path_to_schemas[updated_vm.path_to_item] return path_to_schemas @@ -1813,7 +1749,7 @@ class ComposedBase(Discriminable): # DictBase, ListBase, NumberBase, StrBase, BoolBase, NoneBase class ComposedSchema( - _SchemaTypeChecker(typing.Union[none_type, str, decimal.Decimal, bool, tuple, frozendict]), + _SchemaTypeChecker(typing.Union[NoneClass, str, decimal.Decimal, BoolClass, tuple, frozendict]), ComposedBase, DictBase, ListBase, @@ -1851,7 +1787,7 @@ class ListSchema( class NoneSchema( - _SchemaTypeChecker(typing.Union[none_type]), + _SchemaTypeChecker(typing.Union[NoneClass]), NoneBase, Schema ): @@ -2122,7 +2058,7 @@ class BinarySchema( class BoolSchema( - _SchemaTypeChecker(typing.Union[bool]), + _SchemaTypeChecker(typing.Union[BoolClass]), BoolBase, Schema ): @@ -2137,7 +2073,7 @@ class BoolSchema( class AnyTypeSchema( _SchemaTypeChecker( - typing.Union[frozendict, tuple, decimal.Decimal, str, bool, none_type, bytes, FileIO] + typing.Union[frozendict, tuple, decimal.Decimal, str, BoolClass, NoneClass, bytes, FileIO] ), DictBase, ListBase, @@ -2164,7 +2100,7 @@ class DictSchema( return super().__new__(cls, *args, **kwargs) -schema_descendents = set([NoneSchema, DictSchema, ListSchema, NumberSchema, StrSchema, BoolSchema]) +schema_type_classes = set([NoneSchema, DictSchema, ListSchema, NumberSchema, StrSchema, BoolSchema]) def deserialize_file(response_data, configuration, content_disposition=None): diff --git a/samples/openapi3/client/petstore/python-experimental/docs/BooleanEnum.md b/samples/openapi3/client/petstore/python-experimental/docs/BooleanEnum.md index 1235414f1e3..bd60b098096 100644 --- a/samples/openapi3/client/petstore/python-experimental/docs/BooleanEnum.md +++ b/samples/openapi3/client/petstore/python-experimental/docs/BooleanEnum.md @@ -2,7 +2,7 @@ Type | Description | Notes ------------- | ------------- | ------------- -**bool** | | must be one of [True, ] +**bool** | | must be one of [BoolClass.TRUE, ] [[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/another_fake_api_endpoints/call_123_test_special_tags.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/another_fake_api_endpoints/call_123_test_special_tags.py index 61ce6b70dd8..943d62ce478 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/another_fake_api_endpoints/call_123_test_special_tags.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/another_fake_api_endpoints/call_123_test_special_tags.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/default_api_endpoints/foo_get.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/default_api_endpoints/foo_get.py index d365457ba5f..9c321a2dc9c 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/default_api_endpoints/foo_get.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/default_api_endpoints/foo_get.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/additional_properties_with_array_of_enums.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/additional_properties_with_array_of_enums.py index b810d093599..be1abb21db1 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/additional_properties_with_array_of_enums.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/additional_properties_with_array_of_enums.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/array_model.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/array_model.py index 76fc4eb0523..380c4e37fe0 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/array_model.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/array_model.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/array_of_enums.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/array_of_enums.py index bcd41c33970..a8b420e409e 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/array_of_enums.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/array_of_enums.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/body_with_file_schema.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/body_with_file_schema.py index bd6940fdea8..0c6b77e9524 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/body_with_file_schema.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/body_with_file_schema.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/body_with_query_params.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/body_with_query_params.py index f391b867dfd..0678ee1e422 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/body_with_query_params.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/body_with_query_params.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/boolean.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/boolean.py index cb41c9f75bd..d3664ca80b1 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/boolean.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/boolean.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/case_sensitive_params.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/case_sensitive_params.py index 78ad2a45b32..5fc282857ae 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/case_sensitive_params.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/case_sensitive_params.py @@ -58,6 +58,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/client_model.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/client_model.py index 1b821d62cbb..f5dba651d67 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/client_model.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/client_model.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/composed_one_of_different_types.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/composed_one_of_different_types.py index 28bd085987c..15edba9ec92 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/composed_one_of_different_types.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/composed_one_of_different_types.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/delete_coffee.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/delete_coffee.py index d92684e66a2..0824c6bb56c 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/delete_coffee.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/delete_coffee.py @@ -58,6 +58,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/endpoint_parameters.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/endpoint_parameters.py index 39daed76072..666b832fc7c 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/endpoint_parameters.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/endpoint_parameters.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/enum_parameters.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/enum_parameters.py index eadcbb45872..b6e8924f588 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/enum_parameters.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/enum_parameters.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/fake_health_get.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/fake_health_get.py index 87d8f01968d..6c6324c4a0c 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/fake_health_get.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/fake_health_get.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/group_parameters.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/group_parameters.py index f23fa27f15a..fd2d96c9732 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/group_parameters.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/group_parameters.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/inline_additional_properties.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/inline_additional_properties.py index b966ddb8ff2..7f2d1202cd1 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/inline_additional_properties.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/inline_additional_properties.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/inline_composition.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/inline_composition.py index 06df8ec3b9e..99d7e470a80 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/inline_composition.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/inline_composition.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/json_form_data.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/json_form_data.py index cc4c0f5e5d4..34dfe5627ce 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/json_form_data.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/json_form_data.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/json_with_charset.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/json_with_charset.py index ea85e142df2..f923afb9363 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/json_with_charset.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/json_with_charset.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/mammal.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/mammal.py index 62af68de202..9b32bf0a620 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/mammal.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/mammal.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/number_with_validations.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/number_with_validations.py index a805ac6751a..0a626c82490 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/number_with_validations.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/number_with_validations.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/object_in_query.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/object_in_query.py index aad17c08e5c..94b5e0d8655 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/object_in_query.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/object_in_query.py @@ -58,6 +58,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/object_model_with_ref_props.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/object_model_with_ref_props.py index 47b010528e8..0dfa23dcb31 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/object_model_with_ref_props.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/object_model_with_ref_props.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/parameter_collisions.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/parameter_collisions.py index 9566d007ead..6cedc0e070a 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/parameter_collisions.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/parameter_collisions.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/query_parameter_collection_format.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/query_parameter_collection_format.py index 1a7cb1db97d..8a330bc9ee2 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/query_parameter_collection_format.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/query_parameter_collection_format.py @@ -58,6 +58,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/ref_object_in_query.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/ref_object_in_query.py index ce6becc4d87..31c96a704f5 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/ref_object_in_query.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/ref_object_in_query.py @@ -58,6 +58,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/response_without_schema.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/response_without_schema.py index 59c536759a2..bb56af4d75f 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/response_without_schema.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/response_without_schema.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/string.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/string.py index 50e48a52ff1..311dcc72a32 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/string.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/string.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/string_enum.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/string_enum.py index bee9d1aa22d..32cf1d5615f 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/string_enum.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/string_enum.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/upload_download_file.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/upload_download_file.py index 71595e309e4..d272589ed50 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/upload_download_file.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/upload_download_file.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/upload_file.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/upload_file.py index e092ff00146..e308b76b1f2 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/upload_file.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/upload_file.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/upload_files.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/upload_files.py index 9da5c260aea..574195370bc 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/upload_files.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_api_endpoints/upload_files.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_classname_tags123_api_endpoints/classname.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_classname_tags123_api_endpoints/classname.py index 0a439014dae..a9d14bad610 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_classname_tags123_api_endpoints/classname.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/fake_classname_tags123_api_endpoints/classname.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/add_pet.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/add_pet.py index a6d99272f58..9c288856f06 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/add_pet.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/add_pet.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/delete_pet.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/delete_pet.py index f109924c342..73c6243b64e 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/delete_pet.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/delete_pet.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/find_pets_by_status.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/find_pets_by_status.py index ef7933713d5..ba51127bae2 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/find_pets_by_status.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/find_pets_by_status.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/find_pets_by_tags.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/find_pets_by_tags.py index 867b0a0a535..7be1cd57d8d 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/find_pets_by_tags.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/find_pets_by_tags.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/get_pet_by_id.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/get_pet_by_id.py index 04eec525b53..a7509c97427 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/get_pet_by_id.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/get_pet_by_id.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/update_pet.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/update_pet.py index 275d192c418..c7d9459244b 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/update_pet.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/update_pet.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/update_pet_with_form.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/update_pet_with_form.py index 0c1f5cc5046..c9ba7a9816a 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/update_pet_with_form.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/update_pet_with_form.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/upload_file_with_required_file.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/upload_file_with_required_file.py index 05558584289..689f54addd2 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/upload_file_with_required_file.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/upload_file_with_required_file.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/upload_image.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/upload_image.py index 95836e036e7..70cce044b13 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/upload_image.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/pet_api_endpoints/upload_image.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/store_api_endpoints/delete_order.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/store_api_endpoints/delete_order.py index 791d2347ceb..46f33d453bb 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/store_api_endpoints/delete_order.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/store_api_endpoints/delete_order.py @@ -58,6 +58,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/store_api_endpoints/get_inventory.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/store_api_endpoints/get_inventory.py index be6a45c2ed6..73410c09c75 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/store_api_endpoints/get_inventory.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/store_api_endpoints/get_inventory.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/store_api_endpoints/get_order_by_id.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/store_api_endpoints/get_order_by_id.py index 4539bfcf1b9..56ef500f9df 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/store_api_endpoints/get_order_by_id.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/store_api_endpoints/get_order_by_id.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/store_api_endpoints/place_order.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/store_api_endpoints/place_order.py index 7707e9be67f..73a63555820 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/store_api_endpoints/place_order.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/store_api_endpoints/place_order.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/create_user.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/create_user.py index ec13814a996..2871f0d215c 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/create_user.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/create_user.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/create_users_with_array_input.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/create_users_with_array_input.py index 555d7e45a63..a2a462399b5 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/create_users_with_array_input.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/create_users_with_array_input.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/create_users_with_list_input.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/create_users_with_list_input.py index 0e367df7b12..e79cba97e82 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/create_users_with_list_input.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/create_users_with_list_input.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/delete_user.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/delete_user.py index 6d6121ce01c..34dc9d85bc5 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/delete_user.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/delete_user.py @@ -58,6 +58,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/get_user_by_name.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/get_user_by_name.py index 9dd751d22bd..71a98199130 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/get_user_by_name.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/get_user_by_name.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/login_user.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/login_user.py index c3f74727125..d48dc43dc6d 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/login_user.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/login_user.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/logout_user.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/logout_user.py index 7fbedc55b94..d91518c02c9 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/logout_user.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/logout_user.py @@ -58,6 +58,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/update_user.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/update_user.py index b7e3931b6a5..15cc7be1100 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/update_user.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/api/user_api_endpoints/update_user.py @@ -59,6 +59,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/additional_properties_class.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/additional_properties_class.py index 5ccf44cceb0..8339daf8f7e 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/additional_properties_class.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/additional_properties_class.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/additional_properties_with_array_of_enums.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/additional_properties_with_array_of_enums.py index f7e9ee93367..cf4ff6075bc 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/additional_properties_with_array_of_enums.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/additional_properties_with_array_of_enums.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/address.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/address.py index c9ba9a4dc32..8aabd4c6e1b 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/address.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/address.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/animal.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/animal.py index 92b478614a3..8081aca81d7 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/animal.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/animal.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/animal_farm.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/animal_farm.py index 31ab2facb71..dc1e04af56e 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/animal_farm.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/animal_farm.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/any_type_not_string.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/any_type_not_string.py index 45915e64206..d3b1f5179c1 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/any_type_not_string.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/any_type_not_string.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/api_response.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/api_response.py index 669e8c14366..62fc4e31daa 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/api_response.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/api_response.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/apple.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/apple.py index 107b8ad0c56..f0ca74fc195 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/apple.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/apple.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker @@ -67,7 +69,7 @@ from petstore_api.schemas import ( # noqa: F401 class Apple( - _SchemaTypeChecker(typing.Union[frozendict, none_type, ]), + _SchemaTypeChecker(typing.Union[frozendict, NoneClass, ]), DictBase, NoneBase, Schema diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/apple_req.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/apple_req.py index 71519bb0ee0..bb6ec8503fb 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/apple_req.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/apple_req.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_holding_any_type.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_holding_any_type.py index ea1353a02c5..427e3a78492 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_holding_any_type.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_holding_any_type.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_of_array_of_number_only.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_of_array_of_number_only.py index 3f73c652b89..4d961402e33 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_of_array_of_number_only.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_of_array_of_number_only.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_of_enums.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_of_enums.py index a541336f645..55735ae7a1f 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_of_enums.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_of_enums.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_of_number_only.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_of_number_only.py index 2e32429c76f..cf97c7288ac 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_of_number_only.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_of_number_only.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_test.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_test.py index ccb8e8364e3..92af59070d9 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_test.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_test.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_with_validations_in_items.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_with_validations_in_items.py index 5534b804c81..02df64785d0 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_with_validations_in_items.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/array_with_validations_in_items.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/banana.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/banana.py index 32fd6d33aba..2dd4fbc2d12 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/banana.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/banana.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/banana_req.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/banana_req.py index eef932bcc17..b77c7566e73 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/banana_req.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/banana_req.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/bar.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/bar.py index b6955c0c38a..5d00a2a89d4 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/bar.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/bar.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/basque_pig.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/basque_pig.py index 1be687ece16..6bc0e9e7b9c 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/basque_pig.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/basque_pig.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/boolean.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/boolean.py index db84ecedc30..4c79b9b00a1 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/boolean.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/boolean.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/boolean_enum.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/boolean_enum.py index f3f6bb20053..a223a2ce062 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/boolean_enum.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/boolean_enum.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker @@ -69,7 +71,7 @@ from petstore_api.schemas import ( # noqa: F401 class BooleanEnum( _SchemaEnumMaker( enum_value_to_name={ - True: "TRUE", + BoolClass.TRUE: "TRUE", } ), BoolSchema @@ -83,4 +85,4 @@ class BooleanEnum( @classmethod @property def TRUE(cls): - return cls(True) + return cls(BoolClass.TRUE) diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/capitalization.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/capitalization.py index 698d6b5eb3b..56cf406a703 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/capitalization.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/capitalization.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/cat.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/cat.py index e43e618a441..e77e96fcfa7 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/cat.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/cat.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/category.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/category.py index 9cf45a54e98..ef727200727 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/category.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/category.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/child_cat.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/child_cat.py index 381628a1d70..7a8751c2c11 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/child_cat.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/child_cat.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/class_model.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/class_model.py index a79a2afefce..d7cf4de512e 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/class_model.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/class_model.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/client.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/client.py index 976072a8b31..13ad5e5ff35 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/client.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/client.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/complex_quadrilateral.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/complex_quadrilateral.py index e5a46fb124d..aafa7e29d2a 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/complex_quadrilateral.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/complex_quadrilateral.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_any_of_different_types_no_validations.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_any_of_different_types_no_validations.py index c113226e096..c0fa339d9fd 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_any_of_different_types_no_validations.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_any_of_different_types_no_validations.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_array.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_array.py index 248d470db97..221abb75d3e 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_array.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_array.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_bool.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_bool.py index 8cb6de2269e..c7fae992ce8 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_bool.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_bool.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_none.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_none.py index 4a6dca2dfcd..c0fbf1abdeb 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_none.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_none.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_number.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_number.py index 81140f5a8ad..6c53edc3429 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_number.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_number.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_object.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_object.py index 9f5f707b20d..3579c7965d7 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_object.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_object.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_one_of_different_types.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_one_of_different_types.py index 3dcf8d990cb..3e27e2a996f 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_one_of_different_types.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_one_of_different_types.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_string.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_string.py index 5925aa1b14a..da33e5202f4 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_string.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/composed_string.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/currency.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/currency.py index 5d6fa533e1d..0844fa544bb 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/currency.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/currency.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/danish_pig.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/danish_pig.py index ec281c4eff6..3f309151259 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/danish_pig.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/danish_pig.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/date_time_test.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/date_time_test.py index 2b9c4a1fb34..a4cc1eea68d 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/date_time_test.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/date_time_test.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/date_time_with_validations.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/date_time_with_validations.py index c7236b7e93d..f4c7c07278b 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/date_time_with_validations.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/date_time_with_validations.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/date_with_validations.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/date_with_validations.py index 701dceec4bd..f3dceba1cd5 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/date_with_validations.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/date_with_validations.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/decimal_payload.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/decimal_payload.py index 02d99b636e1..1bae8338481 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/decimal_payload.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/decimal_payload.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/dog.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/dog.py index ff433100129..130512a669e 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/dog.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/dog.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/drawing.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/drawing.py index 54083c97049..c3cb01e0aed 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/drawing.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/drawing.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/enum_arrays.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/enum_arrays.py index 7061dcbac01..be4182fe233 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/enum_arrays.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/enum_arrays.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/enum_class.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/enum_class.py index 7d12b8cb99b..019001d2088 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/enum_class.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/enum_class.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/enum_test.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/enum_test.py index 965f861eb53..319b0282de4 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/enum_test.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/enum_test.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/equilateral_triangle.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/equilateral_triangle.py index 82a9ae64278..c572964a57b 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/equilateral_triangle.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/equilateral_triangle.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/file.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/file.py index 0d39c45d8e5..3e68cefa31e 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/file.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/file.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/file_schema_test_class.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/file_schema_test_class.py index 659e0a552c0..ce058035357 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/file_schema_test_class.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/file_schema_test_class.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/foo.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/foo.py index 7a8df911023..8d650b5604a 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/foo.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/foo.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/format_test.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/format_test.py index d64a93e001a..a7d1bbb9f37 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/format_test.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/format_test.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/fruit.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/fruit.py index 6d8f255c5b0..bd6051a6616 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/fruit.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/fruit.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/fruit_req.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/fruit_req.py index 5729f1625ad..3458ea63f6a 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/fruit_req.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/fruit_req.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/gm_fruit.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/gm_fruit.py index f591a7ff3ee..cd2ab6559f4 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/gm_fruit.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/gm_fruit.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/grandparent_animal.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/grandparent_animal.py index a8b0106897f..7b6a7464095 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/grandparent_animal.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/grandparent_animal.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/has_only_read_only.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/has_only_read_only.py index ca6317b2457..4830db9c7d4 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/has_only_read_only.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/has_only_read_only.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/health_check_result.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/health_check_result.py index 7f67db6e231..c48f1c3803c 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/health_check_result.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/health_check_result.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker @@ -79,7 +81,7 @@ class HealthCheckResult( class NullableMessage( - _SchemaTypeChecker(typing.Union[none_type, str, ]), + _SchemaTypeChecker(typing.Union[NoneClass, str, ]), StrBase, NoneBase, Schema diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum.py index 515755e788f..2fc839f1da3 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum_big.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum_big.py index 5d92610f1ac..33659622629 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum_big.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum_big.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum_one_value.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum_one_value.py index f934e35f25a..706ea7f682a 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum_one_value.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum_one_value.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum_with_default_value.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum_with_default_value.py index 401cd77dd56..c4aac3b348c 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum_with_default_value.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_enum_with_default_value.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_max10.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_max10.py index 3c515835a49..0915ff33f97 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_max10.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_max10.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_min15.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_min15.py index d7d070c2220..cb59a2b7db3 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_min15.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/integer_min15.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/isosceles_triangle.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/isosceles_triangle.py index 178878c06d6..8a3bb200bf6 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/isosceles_triangle.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/isosceles_triangle.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/mammal.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/mammal.py index 33af6e183f6..a2eb42d4dbb 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/mammal.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/mammal.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/map_test.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/map_test.py index 68ff2efbf01..a9f8383cb5a 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/map_test.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/map_test.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/mixed_properties_and_additional_properties_class.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/mixed_properties_and_additional_properties_class.py index 8ed67fef179..70477d2f5aa 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/mixed_properties_and_additional_properties_class.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/mixed_properties_and_additional_properties_class.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/model200_response.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/model200_response.py index c3741abc664..edca0435ec9 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/model200_response.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/model200_response.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/model_return.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/model_return.py index de277a4a893..4fe5b613f54 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/model_return.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/model_return.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/money.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/money.py index 1569585e7a8..fc48f495a69 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/money.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/money.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/name.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/name.py index c908733cdf8..f70569b177d 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/name.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/name.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/no_additional_properties.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/no_additional_properties.py index 0ea307c5ce9..a54984228a0 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/no_additional_properties.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/no_additional_properties.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/nullable_class.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/nullable_class.py index cecd3781163..71559959bdb 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/nullable_class.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/nullable_class.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker @@ -77,7 +79,7 @@ class NullableClass( class integer_prop( - _SchemaTypeChecker(typing.Union[none_type, decimal.Decimal, ]), + _SchemaTypeChecker(typing.Union[NoneClass, decimal.Decimal, ]), IntBase, NoneBase, Schema @@ -96,7 +98,7 @@ class NullableClass( class number_prop( - _SchemaTypeChecker(typing.Union[none_type, decimal.Decimal, ]), + _SchemaTypeChecker(typing.Union[NoneClass, decimal.Decimal, ]), NumberBase, NoneBase, Schema @@ -115,7 +117,7 @@ class NullableClass( class boolean_prop( - _SchemaTypeChecker(typing.Union[none_type, bool, ]), + _SchemaTypeChecker(typing.Union[NoneClass, BoolClass, ]), BoolBase, NoneBase, Schema @@ -134,7 +136,7 @@ class NullableClass( class string_prop( - _SchemaTypeChecker(typing.Union[none_type, str, ]), + _SchemaTypeChecker(typing.Union[NoneClass, str, ]), StrBase, NoneBase, Schema @@ -153,7 +155,7 @@ class NullableClass( class date_prop( - _SchemaTypeChecker(typing.Union[none_type, str, ]), + _SchemaTypeChecker(typing.Union[NoneClass, str, ]), DateBase, NoneBase, Schema @@ -172,7 +174,7 @@ class NullableClass( class datetime_prop( - _SchemaTypeChecker(typing.Union[none_type, str, ]), + _SchemaTypeChecker(typing.Union[NoneClass, str, ]), DateTimeBase, NoneBase, Schema @@ -191,7 +193,7 @@ class NullableClass( class array_nullable_prop( - _SchemaTypeChecker(typing.Union[tuple, none_type, ]), + _SchemaTypeChecker(typing.Union[tuple, NoneClass, ]), ListBase, NoneBase, Schema @@ -210,7 +212,7 @@ class NullableClass( class array_and_items_nullable_prop( - _SchemaTypeChecker(typing.Union[tuple, none_type, ]), + _SchemaTypeChecker(typing.Union[tuple, NoneClass, ]), ListBase, NoneBase, Schema @@ -234,7 +236,7 @@ class NullableClass( class _items( - _SchemaTypeChecker(typing.Union[frozendict, none_type, ]), + _SchemaTypeChecker(typing.Union[frozendict, NoneClass, ]), DictBase, NoneBase, Schema @@ -255,7 +257,7 @@ class NullableClass( class object_nullable_prop( - _SchemaTypeChecker(typing.Union[frozendict, none_type, ]), + _SchemaTypeChecker(typing.Union[frozendict, NoneClass, ]), DictBase, NoneBase, Schema @@ -277,7 +279,7 @@ class NullableClass( class object_and_items_nullable_prop( - _SchemaTypeChecker(typing.Union[frozendict, none_type, ]), + _SchemaTypeChecker(typing.Union[frozendict, NoneClass, ]), DictBase, NoneBase, Schema @@ -285,7 +287,7 @@ class NullableClass( class _additional_properties( - _SchemaTypeChecker(typing.Union[frozendict, none_type, ]), + _SchemaTypeChecker(typing.Union[frozendict, NoneClass, ]), DictBase, NoneBase, Schema @@ -324,7 +326,7 @@ class NullableClass( class _additional_properties( - _SchemaTypeChecker(typing.Union[frozendict, none_type, ]), + _SchemaTypeChecker(typing.Union[frozendict, NoneClass, ]), DictBase, NoneBase, Schema @@ -359,7 +361,7 @@ class NullableClass( class _additional_properties( - _SchemaTypeChecker(typing.Union[frozendict, none_type, ]), + _SchemaTypeChecker(typing.Union[frozendict, NoneClass, ]), DictBase, NoneBase, Schema diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/nullable_shape.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/nullable_shape.py index 95b354fbb1f..c24703964e7 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/nullable_shape.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/nullable_shape.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/nullable_string.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/nullable_string.py index a2aeca7fa84..7cf3c74f318 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/nullable_string.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/nullable_string.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker @@ -67,7 +69,7 @@ from petstore_api.schemas import ( # noqa: F401 class NullableString( - _SchemaTypeChecker(typing.Union[none_type, str, ]), + _SchemaTypeChecker(typing.Union[NoneClass, str, ]), StrBase, NoneBase, Schema diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/number.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/number.py index 0008b50857e..47361523e04 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/number.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/number.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/number_only.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/number_only.py index 9f5613e28d0..6f4036faa4f 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/number_only.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/number_only.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/number_with_validations.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/number_with_validations.py index 96d1f661df4..3963b0b297d 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/number_with_validations.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/number_with_validations.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/object_interface.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/object_interface.py index be1f174ae81..d8eec30dee1 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/object_interface.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/object_interface.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/object_model_with_ref_props.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/object_model_with_ref_props.py index 148779aa988..11de28c5997 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/object_model_with_ref_props.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/object_model_with_ref_props.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/object_with_decimal_properties.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/object_with_decimal_properties.py index d19b61f8d68..69264d1642a 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/object_with_decimal_properties.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/object_with_decimal_properties.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/object_with_difficultly_named_props.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/object_with_difficultly_named_props.py index 4b1255298a2..f4e66878f9e 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/object_with_difficultly_named_props.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/object_with_difficultly_named_props.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/object_with_inline_composition_property.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/object_with_inline_composition_property.py index 4b0017d3af4..caff3025fa7 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/object_with_inline_composition_property.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/object_with_inline_composition_property.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/object_with_validations.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/object_with_validations.py index 812aea156aa..1eb29795fb0 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/object_with_validations.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/object_with_validations.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/order.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/order.py index 6c2ec31a937..c7a69be9164 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/order.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/order.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/parent_pet.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/parent_pet.py index bcb200fd763..50bae9f0b7e 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/parent_pet.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/parent_pet.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/pet.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/pet.py index 18a2feaf801..6b1cd00870b 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/pet.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/pet.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/pig.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/pig.py index 410dd496ae3..ef89f2a9bd0 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/pig.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/pig.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/player.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/player.py index d4b2cb288cf..99e382ec645 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/player.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/player.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/quadrilateral.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/quadrilateral.py index aef042f053b..ac2bba6417a 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/quadrilateral.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/quadrilateral.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/quadrilateral_interface.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/quadrilateral_interface.py index 70c2ce8b060..bd28482b08c 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/quadrilateral_interface.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/quadrilateral_interface.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/read_only_first.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/read_only_first.py index 0896f3db9c9..496b72a0529 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/read_only_first.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/read_only_first.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/scalene_triangle.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/scalene_triangle.py index cd193e90d84..8f521da2498 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/scalene_triangle.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/scalene_triangle.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/shape.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/shape.py index 777d40b6410..c14b212935a 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/shape.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/shape.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/shape_or_null.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/shape_or_null.py index 91aef06addb..71049a63149 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/shape_or_null.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/shape_or_null.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/simple_quadrilateral.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/simple_quadrilateral.py index 3e375e3f562..0d65abab0a8 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/simple_quadrilateral.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/simple_quadrilateral.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/some_object.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/some_object.py index 2d8e71360af..d7a74609692 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/some_object.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/some_object.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/special_model_name.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/special_model_name.py index 5325437bd12..696e59a4e42 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/special_model_name.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/special_model_name.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string.py index a36e1550699..f3dc03700e3 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string_boolean_map.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string_boolean_map.py index 2b4b5435f60..1ef5b11d746 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string_boolean_map.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string_boolean_map.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string_enum.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string_enum.py index 3d1ababa10f..4f23fa3c0da 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string_enum.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string_enum.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker @@ -67,10 +69,10 @@ from petstore_api.schemas import ( # noqa: F401 class StringEnum( - _SchemaTypeChecker(typing.Union[none_type, str, ]), + _SchemaTypeChecker(typing.Union[NoneClass, str, ]), _SchemaEnumMaker( enum_value_to_name={ - None: "NONE", + NoneClass.NONE: "NONE", "placed": "PLACED", "approved": "APPROVED", "delivered": "DELIVERED", @@ -92,7 +94,7 @@ class StringEnum( @classmethod @property def NONE(cls): - return cls._enum_by_value[None](None) + return cls(None) @classmethod @property diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string_enum_with_default_value.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string_enum_with_default_value.py index 6ab987f43ef..519bf0b4b5e 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string_enum_with_default_value.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string_enum_with_default_value.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string_with_validation.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string_with_validation.py index b82088d24f4..9b41e07bf05 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string_with_validation.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/string_with_validation.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/tag.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/tag.py index 6d166baafaf..f9fbfb67d3c 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/tag.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/tag.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/triangle.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/triangle.py index 0d02cfba1ed..7686cdd34cf 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/triangle.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/triangle.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/triangle_interface.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/triangle_interface.py index f0241962c07..07fae72e4ef 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/triangle_interface.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/triangle_interface.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/user.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/user.py index bf1320556ac..d640593bbd6 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/user.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/user.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker @@ -86,7 +88,7 @@ class User( class objectWithNoDeclaredPropsNullable( - _SchemaTypeChecker(typing.Union[frozendict, none_type, ]), + _SchemaTypeChecker(typing.Union[frozendict, NoneClass, ]), DictBase, NoneBase, Schema diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/uuid_string.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/uuid_string.py index fb4c32c0dc2..c80979f32fb 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/uuid_string.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/uuid_string.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/whale.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/whale.py index 78a28fa763c..4bcb2f0e3b6 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/whale.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/whale.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/zebra.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/zebra.py index 649555d548a..51220d56536 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/model/zebra.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/model/zebra.py @@ -60,6 +60,8 @@ from petstore_api.schemas import ( # noqa: F401 BoolBase, BinaryBase, Schema, + NoneClass, + BoolClass, _SchemaValidator, _SchemaTypeChecker, _SchemaEnumMaker diff --git a/samples/openapi3/client/petstore/python-experimental/petstore_api/schemas.py b/samples/openapi3/client/petstore/python-experimental/petstore_api/schemas.py index 1338d43bfa1..578c03da74a 100644 --- a/samples/openapi3/client/petstore/python-experimental/petstore_api/schemas.py +++ b/samples/openapi3/client/petstore/python-experimental/petstore_api/schemas.py @@ -53,12 +53,17 @@ class FileIO(io.FileIO): def __new__(cls, arg: typing.Union[io.FileIO, io.BufferedReader]): if isinstance(arg, (io.FileIO, io.BufferedReader)): + if arg.closed: + raise ApiValueError('Invalid file state; file is closed and must be open') arg.close() inst = super(FileIO, cls).__new__(cls, arg.name) super(FileIO, inst).__init__(arg.name) return inst raise ApiValueError('FileIO must be passed arg which contains the open file') + def __init__(self, arg: typing.Union[io.FileIO, io.BufferedReader]): + pass + def update(d: dict, u: dict): """ @@ -85,29 +90,46 @@ class ValidationMetadata(frozendict): path_to_item: typing.Tuple[typing.Union[str, int], ...] = tuple(['args[0]']), from_server: bool = False, configuration: typing.Optional[Configuration] = None, - base_classes: typing.FrozenSet[typing.Type] = frozenset(), + seen_classes: typing.FrozenSet[typing.Type] = frozenset(), + validated_path_to_schemas: typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set['Schema']] = frozendict() ): """ Args: path_to_item: the path to the current data being instantiated. For {'a': [1]} if the code is handling, 1, then the path is ('args[0]', 'a', 0) + This changes from location to location from_server: whether or not this data came form the server True when receiving server data False when instantiating model with client side data not form the server + This does not change from location to location configuration: the Configuration instance to use This is needed because in Configuration: - one can disable validation checking - base_classes: when deserializing data that matches multiple schemas, this is used to store + This does not change from location to location + seen_classes: when deserializing data that matches multiple schemas, this is used to store the schemas that have been traversed. This is used to stop processing when a cycle is seen. + This changes from location to location + validated_path_to_schemas: stores the already validated schema classes for a given path location + This does not change from location to location """ return super().__new__( cls, path_to_item=path_to_item, from_server=from_server, configuration=configuration, - base_classes=base_classes, + seen_classes=seen_classes, + validated_path_to_schemas=validated_path_to_schemas ) + def validation_ran_earlier(self, cls: type) -> bool: + validated_schemas = self.validated_path_to_schemas.get(self.path_to_item, set()) + validation_ran_earlier = validated_schemas and cls in validated_schemas + if validation_ran_earlier: + return True + if cls in self.seen_classes: + return True + return False + @property def path_to_item(self) -> typing.Tuple[typing.Union[str, int], ...]: return self.get('path_to_item') @@ -121,8 +143,12 @@ class ValidationMetadata(frozendict): return self.get('configuration') @property - def base_classes(self) -> typing.FrozenSet[typing.Type]: - return self.get('base_classes') + def seen_classes(self) -> typing.FrozenSet[typing.Type]: + return self.get('seen_classes') + + @property + def validated_path_to_schemas(self) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set['Schema']]: + return self.get('validated_path_to_schemas') class ValidatorBase: @@ -201,31 +227,6 @@ class ValidatorBase: path_to_item=validation_metadata.path_to_item ) - @classmethod - def __data_with_boolclass_instead_of_bool(cls, data: typing.Any) -> typing.Any: - """ - In python bool is a subclass of int so 1 == True and 0 == False - This prevents code from being able to see the difference between 1 and True and 0 and False - To fix this swap in BoolClass singletons for True and False so they will differ from integers - """ - if isinstance(data, (list, tuple)): - new_data = [] - for item in data: - new_item = cls.__data_with_boolclass_instead_of_bool(item) - new_data.append(new_item) - return tuple(new_data) - elif isinstance(data, (dict, frozendict)): - new_data = {} - for key, value in data.items(): - new_value = cls.__data_with_boolclass_instead_of_bool(value) - new_data[key] = new_value - return frozendict(new_data) - elif isinstance(data, bool): - if data: - return BoolClass.TRUE - return BoolClass.FALSE - return data - @classmethod def __check_tuple_validations( cls, validations, input_values, @@ -253,7 +254,7 @@ class ValidatorBase: if (cls.__is_json_validation_enabled('uniqueItems', validation_metadata.configuration) and 'unique_items' in validations and validations['unique_items'] and input_values): - unique_items = set(cls.__data_with_boolclass_instead_of_bool(input_values)) + unique_items = set(input_values) if len(input_values) > len(unique_items): cls.__raise_validation_error_message( value=input_values, @@ -369,128 +370,6 @@ class ValidatorBase: cls.__check_dict_validations(validations, input_values, validation_metadata) elif isinstance(input_values, decimal.Decimal): cls.__check_numeric_validations(validations, input_values, validation_metadata) - try: - return super()._validate_validations_pass(input_values, validation_metadata) - except AttributeError: - return True - - -class Validator(typing.Protocol): - def _validate_validations_pass( - cls, - input_values, - validation_metadata: ValidationMetadata - ): - pass - - -def _SchemaValidator(**validations: typing.Union[str, bool, None, int, float, list[dict[str, typing.Union[str, int, float]]]]) -> Validator: - class SchemaValidator(ValidatorBase): - @classmethod - def _validate_validations_pass( - cls, - input_values, - validation_metadata: ValidationMetadata - ): - cls._check_validations_for_types(validations, input_values, validation_metadata) - try: - return super()._validate_validations_pass(input_values, validation_metadata) - except AttributeError: - return True - - return SchemaValidator - - -class TypeChecker(typing.Protocol): - @classmethod - def _validate_type( - cls, arg_simple_class: type - ) -> typing.Tuple[type]: - pass - - -def _SchemaTypeChecker(union_type_cls: typing.Union[typing.Any]) -> TypeChecker: - if typing.get_origin(union_type_cls) is typing.Union: - union_classes = typing.get_args(union_type_cls) - else: - # note: when a union of a single class is passed in, the union disappears - union_classes = tuple([union_type_cls]) - """ - I want the type hint... union_type_cls - and to use it as a base class but when I do, I get - TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases - """ - class SchemaTypeChecker: - @classmethod - def _validate_type(cls, arg_simple_class: type): - if arg_simple_class not in union_classes: - return union_classes - try: - return super()._validate_type(arg_simple_class) - except AttributeError: - return tuple() - - return SchemaTypeChecker - - -class EnumMakerBase: - @classmethod - @property - def _enum_by_value( - cls - ) -> type: - enum_classes = {} - if not hasattr(cls, "_enum_value_to_name"): - return enum_classes - for enum_value, enum_name in cls._enum_value_to_name.items(): - base_class = type(enum_value) - if base_class is none_type: - enum_classes[enum_value] = get_new_class( - "Dynamic" + cls.__name__, (cls, NoneClass)) - log_cache_usage(get_new_class) - elif base_class is bool: - enum_classes[enum_value] = get_new_class( - "Dynamic" + cls.__name__, (cls, BoolClass)) - log_cache_usage(get_new_class) - else: - enum_classes[enum_value] = get_new_class( - "Dynamic" + cls.__name__, (cls, Singleton, base_class)) - log_cache_usage(get_new_class) - return enum_classes - - -class EnumMakerInterface(typing.Protocol): - @classmethod - @property - def _enum_value_to_name( - cls - ) -> typing.Dict[typing.Union[str, decimal.Decimal, bool, none_type], str]: - pass - - @classmethod - @property - def _enum_by_value( - cls - ) -> type: - pass - - -def _SchemaEnumMaker(enum_value_to_name: typing.Dict[typing.Union[str, decimal.Decimal, bool, none_type], str]) -> EnumMakerInterface: - class SchemaEnumMaker(EnumMakerBase): - @classmethod - @property - def _enum_value_to_name( - cls - ) -> typing.Dict[typing.Union[str, decimal.Decimal, bool, none_type], str]: - pass - try: - super_enum_value_to_name = super()._enum_value_to_name - except AttributeError: - return enum_value_to_name - intersection = dict(enum_value_to_name.items() & super_enum_value_to_name.items()) - return intersection - - return SchemaEnumMaker class Singleton: @@ -505,7 +384,12 @@ class Singleton: if key not in cls._instances: if arg in {None, True, False}: inst = super().__new__(cls) - # inst._value = arg + cls._instances[key] = inst + elif isinstance(arg, BoolClass): + inst = super().__new__(cls) + cls._instances[key] = inst + elif isinstance(arg, NoneClass): + inst = super().__new__(cls) cls._instances[key] = inst else: cls._instances[key] = super().__new__(cls, arg) @@ -515,7 +399,7 @@ class Singleton: if isinstance(self, NoneClass): return f'<{self.__class__.__name__}: None>' elif isinstance(self, BoolClass): - if (self.__class__, True) in self._instances: + if bool(self): return f'<{self.__class__.__name__}: True>' return f'<{self.__class__.__name__}: False>' return f'<{self.__class__.__name__}: {super().__repr__()}>' @@ -546,10 +430,171 @@ class BoolClass(Singleton): def __bool__(self) -> bool: for key, instance in self._instances.items(): if self is instance: - return key[1] + return bool(key[1]) raise ValueError('Unable to find the boolean value of this instance') +class Validator(typing.Protocol): + @classmethod + def _validate( + cls, + arg, + validation_metadata: ValidationMetadata, + ) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]]: + pass + + +def _SchemaValidator(**validations: typing.Union[str, bool, None, int, float, list[dict[str, typing.Union[str, int, float]]]]) -> Validator: + class SchemaValidator(ValidatorBase): + @classmethod + def _validate( + cls, + arg, + validation_metadata: ValidationMetadata, + ) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]]: + """ + SchemaValidator _validate + Validates that validations pass + """ + cls._check_validations_for_types(validations, arg, validation_metadata) + return super()._validate(arg, validation_metadata) + + return SchemaValidator + + +def _SchemaTypeChecker(union_type_cls: typing.Union[typing.Any]) -> Validator: + if typing.get_origin(union_type_cls) is typing.Union: + union_classes = typing.get_args(union_type_cls) + else: + # note: when a union of a single class is passed in, the union disappears + union_classes = tuple([union_type_cls]) + """ + I want the type hint... union_type_cls + and to use it as a base class but when I do, I get + TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases + """ + class SchemaTypeChecker: + @staticmethod + def __get_valid_classes_phrase(input_classes): + """Returns a string phrase describing what types are allowed""" + all_classes = list(input_classes) + all_classes = sorted(all_classes, key=lambda cls: cls.__name__) + all_class_names = [cls.__name__ for cls in all_classes] + if len(all_class_names) == 1: + return "is {0}".format(all_class_names[0]) + return "is one of [{0}]".format(", ".join(all_class_names)) + + @classmethod + def __type_error_message( + cls, var_value=None, var_name=None, valid_classes=None, key_type=None + ): + """ + Keyword Args: + var_value (any): the variable which has the type_error + var_name (str): the name of the variable which has the typ error + valid_classes (tuple): the accepted classes for current_item's + value + key_type (bool): False if our value is a value in a dict + True if it is a key in a dict + False if our item is an item in a tuple + """ + key_or_value = "value" + if key_type: + key_or_value = "key" + valid_classes_phrase = cls.__get_valid_classes_phrase(valid_classes) + msg = "Invalid type. Required {1} type {2} and " "passed type was {3}".format( + var_name, + key_or_value, + valid_classes_phrase, + type(var_value).__name__, + ) + return msg + + @classmethod + def _get_type_error(cls, var_value, path_to_item, valid_classes, key_type=False): + error_msg = cls.__type_error_message( + var_name=path_to_item[-1], + var_value=var_value, + valid_classes=valid_classes, + key_type=key_type, + ) + return ApiTypeError( + error_msg, + path_to_item=path_to_item, + valid_classes=valid_classes, + key_type=key_type, + ) + + @classmethod + def _validate( + cls, + arg, + validation_metadata: ValidationMetadata, + ) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]]: + """ + SchemaTypeChecker _validate + Validates arg's type + """ + arg_type = type(arg) + if arg_type in union_classes: + return super()._validate(arg, validation_metadata) + raise cls._get_type_error( + arg, + validation_metadata.path_to_item, + union_classes, + key_type=False, + ) + + return SchemaTypeChecker + + +class EnumMakerBase: + pass + + +class EnumMakerInterface(Validator): + @classmethod + @property + def _enum_value_to_name( + cls + ) -> typing.Dict[typing.Union[str, decimal.Decimal, bool, none_type], str]: + pass + + +def _SchemaEnumMaker(enum_value_to_name: typing.Dict[typing.Union[str, decimal.Decimal, bool, none_type], str]) -> EnumMakerInterface: + class SchemaEnumMaker(EnumMakerBase): + @classmethod + @property + def _enum_value_to_name( + cls + ) -> typing.Dict[typing.Union[str, decimal.Decimal, bool, none_type], str]: + pass + try: + super_enum_value_to_name = super()._enum_value_to_name + except AttributeError: + return enum_value_to_name + intersection = dict(enum_value_to_name.items() & super_enum_value_to_name.items()) + return intersection + + @classmethod + def _validate( + cls, + arg, + validation_metadata: ValidationMetadata, + ) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]]: + """ + SchemaEnumMaker _validate + Validates that arg is in the enum's allowed values + """ + try: + cls._enum_value_to_name[arg] + except KeyError: + raise ApiValueError("Invalid value {} passed in to {}, {}".format(arg, cls, cls._enum_value_to_name)) + return super()._validate(arg, validation_metadata) + + return SchemaEnumMaker + + class BoolBase: def is_true(self) -> bool: """ @@ -821,13 +866,14 @@ class ListBase: item_cls = getattr(cls, '_items', AnyTypeSchema) path_to_schemas = {} for i, value in enumerate(list_items): - if isinstance(value, item_cls): - continue item_validation_metadata = ValidationMetadata( from_server=validation_metadata.from_server, configuration=validation_metadata.configuration, - path_to_item=validation_metadata.path_to_item+(i,) + path_to_item=validation_metadata.path_to_item+(i,), + validated_path_to_schemas=validation_metadata.validated_path_to_schemas ) + if item_validation_metadata.validation_ran_earlier(item_cls): + continue other_path_to_schemas = item_cls._validate( value, validation_metadata=item_validation_metadata) update(path_to_schemas, other_path_to_schemas) @@ -857,14 +903,12 @@ class ListBase: _path_to_schemas = super()._validate(arg, validation_metadata=validation_metadata) if not isinstance(arg, tuple): return _path_to_schemas - if cls in validation_metadata.base_classes: - # we have already moved through this class so stop here - return _path_to_schemas updated_vm = ValidationMetadata( configuration=validation_metadata.configuration, from_server=validation_metadata.from_server, path_to_item=validation_metadata.path_to_item, - base_classes=validation_metadata.base_classes | frozenset({cls}) + seen_classes=validation_metadata.seen_classes | frozenset({cls}), + validated_path_to_schemas=validation_metadata.validated_path_to_schemas ) other_path_to_schemas = cls._validate_items(arg, validation_metadata=updated_vm) update(_path_to_schemas, other_path_to_schemas) @@ -1030,13 +1074,14 @@ class DictBase(Discriminable): raise ApiTypeError('Unable to find schema for value={} in class={} at path_to_item={}'.format( value, cls, validation_metadata.path_to_item+(property_name,) )) - if isinstance(value, schema): - continue arg_validation_metadata = ValidationMetadata( from_server=validation_metadata.from_server, configuration=validation_metadata.configuration, - path_to_item=validation_metadata.path_to_item+(property_name,) + path_to_item=validation_metadata.path_to_item+(property_name,), + validated_path_to_schemas=validation_metadata.validated_path_to_schemas ) + if arg_validation_metadata.validation_ran_earlier(schema): + continue other_path_to_schemas = schema._validate(value, validation_metadata=arg_validation_metadata) update(path_to_schemas, other_path_to_schemas) return path_to_schemas @@ -1089,15 +1134,15 @@ class DictBase(Discriminable): validation_metadata.path_to_item + (disc_prop_name,) ) ) - if discriminated_cls in validation_metadata.base_classes: - # we have already moved through this class so stop here - return _path_to_schemas updated_vm = ValidationMetadata( configuration=validation_metadata.configuration, from_server=validation_metadata.from_server, path_to_item=validation_metadata.path_to_item, - base_classes=validation_metadata.base_classes | frozenset({cls}) + seen_classes=validation_metadata.seen_classes | frozenset({cls}), + validated_path_to_schemas=validation_metadata.validated_path_to_schemas ) + if updated_vm.validation_ran_earlier(discriminated_cls): + return _path_to_schemas other_path_to_schemas = discriminated_cls._validate(arg, validation_metadata=updated_vm) update(_path_to_schemas, other_path_to_schemas) return _path_to_schemas @@ -1185,7 +1230,7 @@ class DictBase(Discriminable): return super().__getattribute__(name) -inheritable_primitive_types_set = {decimal.Decimal, str, tuple, frozendict, FileIO, bytes} +inheritable_primitive_types_set = {decimal.Decimal, str, tuple, frozendict, FileIO, bytes, BoolClass, NoneClass} class Schema: @@ -1198,117 +1243,12 @@ class Schema: - payload value is an allowed enum value """ - @staticmethod - def __get_simple_class(input_value): - """Returns an input_value's simple class that we will use for type checking - - Args: - input_value (class/class_instance): the item for which we will return - the simple class - """ - if isinstance(input_value, tuple): - return tuple - elif isinstance(input_value, frozendict): - return frozendict - elif isinstance(input_value, none_type): - return none_type - elif isinstance(input_value, bytes): - return bytes - elif isinstance(input_value, (io.FileIO, io.BufferedReader)): - return FileIO - elif isinstance(input_value, bool): - # this must be higher than the int check because - # isinstance(True, int) == True - return bool - elif isinstance(input_value, int): - return int - elif isinstance(input_value, float): - return float - elif isinstance(input_value, datetime): - # this must be higher than the date check because - # isinstance(datetime_instance, date) == True - return datetime - elif isinstance(input_value, date): - return date - elif isinstance(input_value, str): - return str - return type(input_value) - - @staticmethod - def __get_valid_classes_phrase(input_classes): - """Returns a string phrase describing what types are allowed""" - all_classes = list(input_classes) - all_classes = sorted(all_classes, key=lambda cls: cls.__name__) - all_class_names = [cls.__name__ for cls in all_classes] - if len(all_class_names) == 1: - return "is {0}".format(all_class_names[0]) - return "is one of [{0}]".format(", ".join(all_class_names)) - - @classmethod - def __type_error_message( - cls, var_value=None, var_name=None, valid_classes=None, key_type=None - ): - """ - Keyword Args: - var_value (any): the variable which has the type_error - var_name (str): the name of the variable which has the typ error - valid_classes (tuple): the accepted classes for current_item's - value - key_type (bool): False if our value is a value in a dict - True if it is a key in a dict - False if our item is an item in a tuple - """ - key_or_value = "value" - if key_type: - key_or_value = "key" - valid_classes_phrase = cls.__get_valid_classes_phrase(valid_classes) - msg = "Invalid type. Required {1} type {2} and " "passed type was {3}".format( - var_name, - key_or_value, - valid_classes_phrase, - type(var_value).__name__, - ) - return msg - - @classmethod - def __get_type_error(cls, var_value, path_to_item, valid_classes, key_type=False): - error_msg = cls.__type_error_message( - var_name=path_to_item[-1], - var_value=var_value, - valid_classes=valid_classes, - key_type=key_type, - ) - return ApiTypeError( - error_msg, - path_to_item=path_to_item, - valid_classes=valid_classes, - key_type=key_type, - ) - - @classmethod - def _class_by_base_class(cls, base_cls: type) -> type: - cls_name = "Dynamic"+cls.__name__ - if base_cls is bool: - new_cls = get_new_class(cls_name, (cls, BoolBase, BoolClass)) - elif base_cls is str: - new_cls = get_new_class(cls_name, (cls, StrBase, str)) - elif base_cls is decimal.Decimal: - new_cls = get_new_class(cls_name, (cls, NumberBase, decimal.Decimal)) - elif base_cls is tuple: - new_cls = get_new_class(cls_name, (cls, ListBase, tuple)) - elif base_cls is frozendict: - new_cls = get_new_class(cls_name, (cls, DictBase, frozendict)) - elif base_cls is none_type: - new_cls = get_new_class(cls_name, (cls, NoneBase, NoneClass)) - log_cache_usage(get_new_class) - return new_cls - @classmethod def _validate( cls, arg, validation_metadata: ValidationMetadata, - ): + ) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]]: """ Schema _validate Runs all schema validation logic and @@ -1320,9 +1260,7 @@ class Schema: Use cases: 1. inheritable type: string/decimal.Decimal/frozendict/tuple - 2. enum value cases: 'hi', 1 -> no base_class set because the enum includes the base class - 3. uninheritable type: True/False/None -> no base_class because the base class is not inheritable - _enum_by_value will handle this use case + 2. singletons: bool/None -> uses the base classes BoolClass/NoneClass Required Steps: 1. verify type of input is valid vs the allowed _types @@ -1336,38 +1274,29 @@ class Schema: ApiValueError: when a string can't be converted into a date or datetime and it must be one of those classes ApiTypeError: when the input type is not in the list of allowed spec types """ - base_class = cls.__get_simple_class(arg) - failed_type_check_classes = cls._validate_type(base_class) - if failed_type_check_classes: - raise cls.__get_type_error( - arg, - validation_metadata.path_to_item, - failed_type_check_classes, - key_type=False, - ) - if hasattr(cls, '_validate_validations_pass'): - cls._validate_validations_pass(arg, validation_metadata) - path_to_schemas = {} - if validation_metadata.path_to_item not in path_to_schemas: - path_to_schemas[validation_metadata.path_to_item] = set() + base_class = type(arg) + path_to_schemas = {validation_metadata.path_to_item: set()} path_to_schemas[validation_metadata.path_to_item].add(cls) - - if hasattr(cls, "_enum_by_value"): - cls._validate_enum_value(arg) - return path_to_schemas - - if base_class is none_type or base_class is bool: - return path_to_schemas - path_to_schemas[validation_metadata.path_to_item].add(base_class) return path_to_schemas - @classmethod - def _validate_enum_value(cls, arg): - try: - cls._enum_by_value[arg] - except KeyError: - raise ApiValueError("Invalid value {} passed in to {}, {}".format(arg, cls, cls._enum_value_to_name)) + @staticmethod + def __process_schema_classes( + schema_classes: typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]] + ): + """ + Processes and mutates schema_classes + If a SomeSchema is a subclass of DictSchema then remove DictSchema because it is already included + """ + if len(schema_classes) < 2: + return + x_schema = schema_type_classes & schema_classes + if not x_schema: + return + x_schema = x_schema.pop() + if any(c is not x_schema and issubclass(c, x_schema) for c in schema_classes): + # needed to not have a mro error in get_new_class + schema_classes.remove(x_schema) @classmethod def __get_new_cls( @@ -1394,51 +1323,35 @@ class Schema: and in list/dict _get_items,_get_properties the value will be directly assigned because value is of the correct type, and validation was run earlier when the instance was created """ - _path_to_schemas = cls._validate(arg, validation_metadata=validation_metadata) + _path_to_schemas = {} + if validation_metadata.validated_path_to_schemas: + update(_path_to_schemas, validation_metadata.validated_path_to_schemas) + if not validation_metadata.validation_ran_earlier(cls): + other_path_to_schemas = cls._validate(arg, validation_metadata=validation_metadata) + update(_path_to_schemas, other_path_to_schemas) # loop through it make a new class for each entry # do not modify the returned result because it is cached and we would be modifying the cached value path_to_schemas = {} for path, schema_classes in _path_to_schemas.items(): + """ + Use cases + 1. N number of schema classes + enum + type != bool/None, classes in path_to_schemas: tuple/frozendict/str/Decimal/bytes/FileIo + needs Singleton added + 2. N number of schema classes + enum + type == bool/None, classes in path_to_schemas: BoolClass/NoneClass + Singleton already added + 3. N number of schema classes, classes in path_to_schemas: BoolClass/NoneClass/tuple/frozendict/str/Decimal/bytes/FileIo + """ + cls.__process_schema_classes(schema_classes) enum_schema = any( - hasattr(this_cls, '_enum_by_value') for this_cls in schema_classes) + hasattr(this_cls, '_enum_value_to_name') for this_cls in schema_classes) inheritable_primitive_type = schema_classes.intersection(inheritable_primitive_types_set) - chosen_schema_classes = schema_classes - suffix = tuple() - if inheritable_primitive_type: - chosen_schema_classes = schema_classes - inheritable_primitive_types_set - if not enum_schema: - # include the inheritable_primitive_type - suffix = tuple(inheritable_primitive_type) + chosen_schema_classes = schema_classes - inheritable_primitive_type + suffix = tuple(inheritable_primitive_type) + if enum_schema and suffix[0] not in {NoneClass, BoolClass}: + suffix = (Singleton,) + suffix - if len(chosen_schema_classes) == 1 and not suffix: - mfg_cls = tuple(chosen_schema_classes)[0] - else: - x_schema = schema_descendents & chosen_schema_classes - if x_schema: - x_schema = x_schema.pop() - if any(c is not x_schema and issubclass(c, x_schema) for c in chosen_schema_classes): - # needed to not have a mro error in get_new_class - chosen_schema_classes.remove(x_schema) - used_classes = tuple(sorted(chosen_schema_classes, key=lambda a_cls: a_cls.__name__)) + suffix - mfg_cls = get_new_class(class_name='DynamicSchema', bases=used_classes) - - if inheritable_primitive_type and not enum_schema: - path_to_schemas[path] = mfg_cls - continue - - # Use case: value is None, True, False, or an enum value - value = arg - for key in path[1:]: - # if path is bigger than one, get the value that mfg_cls validated - value = value[key] - if hasattr(mfg_cls, '_enum_by_value'): - mfg_cls = mfg_cls._enum_by_value[value] - elif value in {True, False}: - mfg_cls = mfg_cls._class_by_base_class(bool) - elif value is None: - mfg_cls = mfg_cls._class_by_base_class(none_type) - else: - raise ApiValueError('Unhandled case value={} bases={}'.format(value, mfg_cls.__bases__)) + used_classes = tuple(sorted(chosen_schema_classes, key=lambda a_cls: a_cls.__name__)) + suffix + mfg_cls = get_new_class(class_name='DynamicSchema', bases=used_classes) path_to_schemas[path] = mfg_cls return path_to_schemas @@ -1452,6 +1365,7 @@ class Schema: ): # We have a Dynamic class and we are making an instance of it if issubclass(cls, frozendict): + print(cls.__bases__) properties = cls._get_properties(arg, path_to_item, path_to_schemas) return super(Schema, cls).__new__(cls, properties) elif issubclass(cls, tuple): @@ -1491,8 +1405,11 @@ class Schema: """ Schema _from_openapi_data """ - arg = cast_to_allowed_types(arg, from_server=True) - validation_metadata = ValidationMetadata(from_server=True, configuration=_configuration) + from_server = True + validated_path_to_schemas = {} + arg = cast_to_allowed_types(arg, from_server, validated_path_to_schemas) + validation_metadata = ValidationMetadata( + from_server=from_server, configuration=_configuration, validated_path_to_schemas=validated_path_to_schemas) path_to_schemas = cls.__get_new_cls(arg, validation_metadata) new_cls = path_to_schemas[validation_metadata.path_to_item] new_inst = new_cls._get_new_instance_without_conversion( @@ -1534,8 +1451,12 @@ class Schema: arg = args[0] else: arg = cls.__get_input_dict(*args, **kwargs) - validation_metadata = ValidationMetadata(configuration=_configuration, from_server=False) - arg = cast_to_allowed_types(arg, from_server=validation_metadata.from_server) + from_server = False + validated_path_to_schemas = {} + arg = cast_to_allowed_types( + arg, from_server, validated_path_to_schemas) + validation_metadata = ValidationMetadata( + configuration=_configuration, from_server=from_server, validated_path_to_schemas=validated_path_to_schemas) path_to_schemas = cls.__get_new_cls(arg, validation_metadata) new_cls = path_to_schemas[validation_metadata.path_to_item] return new_cls._get_new_instance_without_conversion( @@ -1562,22 +1483,53 @@ class Schema: pass -def cast_to_allowed_types(arg: typing.Union[str, date, datetime, decimal.Decimal, int, float, None, dict, frozendict, list, tuple, bytes, Schema], from_server=False) -> typing.Union[str, bytes, decimal.Decimal, None, frozendict, tuple, Schema]: +def cast_to_allowed_types( + arg: typing.Union[str, date, datetime, uuid.UUID, decimal.Decimal, int, float, None, dict, frozendict, list, tuple, bytes, Schema], + from_server: bool, + validated_path_to_schemas: typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]], + path_to_item: typing.Tuple[typing.Union[str, int], ...] = tuple(['args[0]']), +) -> typing.Union[frozendict, tuple, decimal.Decimal, str, bytes, BoolClass, NoneClass, FileIO]: """ - from_server=False date, datetime -> str - int, float -> Decimal - StrSchema will convert that to bytes and remember the encoding when we pass in str input + Casts the input payload arg into the allowed types + The input validated_path_to_schemas is mutated by running this function + + When from_server is False then + - date/datetime is cast to str + - int/float is cast to Decimal + + If a Schema instance is passed in it is converted back to a primitive instance because + One may need to validate that data to the original Schema class AND additional different classes + those additional classes will need to be added to the new manufactured class for that payload + If the code didn't do this and kept the payload as a Schema instance it would fail to validate to other + Schema classes and the code wouldn't be able to mfg a new class that includes all valid schemas + TODO: store the validated schema classes in validation_metadata + + Args: + arg: the payload + from_server: whether this payload came from the server or not + validated_path_to_schemas: a dict that stores the validated classes at any path location in the payload """ + if isinstance(arg, Schema): + # store the already run validations + schema_classes = set() + for cls in arg.__class__.__bases__: + if cls is Singleton: + continue + schema_classes.add(cls) + validated_path_to_schemas[path_to_item] = schema_classes + if isinstance(arg, str): - return arg - elif type(arg) is dict or type(arg) is frozendict: - return frozendict({key: cast_to_allowed_types(val) for key, val in arg.items()}) - elif isinstance(arg, bool): + return str(arg) + elif isinstance(arg, (dict, frozendict)): + return frozendict({key: cast_to_allowed_types(val, from_server, validated_path_to_schemas, path_to_item + (key,)) for key, val in arg.items()}) + elif isinstance(arg, (bool, BoolClass)): """ this check must come before isinstance(arg, (int, float)) because isinstance(True, int) is True """ - return arg + if arg: + return BoolClass.TRUE + return BoolClass.FALSE elif isinstance(arg, int): return decimal.Decimal(arg) elif isinstance(arg, float): @@ -1587,10 +1539,10 @@ def cast_to_allowed_types(arg: typing.Union[str, date, datetime, decimal.Decimal # 3.4028234663852886e+38 -> Decimal('340282346638528859811704183484516925440.0') return decimal.Decimal(str(decimal_from_float)+'.0') return decimal_from_float - elif type(arg) is list or type(arg) is tuple: - return tuple([cast_to_allowed_types(item) for item in arg]) - elif arg is None: - return arg + elif isinstance(arg, (tuple, list)): + return tuple([cast_to_allowed_types(item, from_server, validated_path_to_schemas, path_to_item + (i,)) for i, item in enumerate(arg)]) + elif isinstance(arg, (none_type, NoneClass)): + return NoneClass.NONE elif isinstance(arg, (date, datetime)): if not from_server: return arg.isoformat() @@ -1602,17 +1554,11 @@ def cast_to_allowed_types(arg: typing.Union[str, date, datetime, decimal.Decimal # ApiTypeError will be thrown later by _validate_type return arg elif isinstance(arg, decimal.Decimal): - return arg + return decimal.Decimal(arg) elif isinstance(arg, bytes): - return arg - elif isinstance(arg, decimal.Decimal): - return arg + return bytes(arg) elif isinstance(arg, (io.FileIO, io.BufferedReader)): - if arg.closed: - raise ApiValueError('Invalid file state; file is closed and must be open') - return arg - elif isinstance(arg, Schema): - return arg + return FileIO(arg) raise ValueError('Invalid type passed in got input={} type={}'.format(arg, type(arg))) @@ -1622,7 +1568,7 @@ class ComposedBase(Discriminable): def __get_allof_classes(cls, arg, validation_metadata: ValidationMetadata): path_to_schemas = defaultdict(set) for allof_cls in cls._composed_schemas['allOf']: - if allof_cls in validation_metadata.base_classes: + if validation_metadata.validation_ran_earlier(allof_cls): continue other_path_to_schemas = allof_cls._validate(arg, validation_metadata=validation_metadata) update(path_to_schemas, other_path_to_schemas) @@ -1637,27 +1583,20 @@ class ComposedBase(Discriminable): path_to_schemas: typing.Dict[typing.Tuple, typing.Set[typing.Type[Schema]]] ): oneof_classes = [] - chosen_oneof_cls = None - original_base_classes = validation_metadata.base_classes - new_base_classes = validation_metadata.base_classes path_to_schemas = defaultdict(set) for oneof_cls in cls._composed_schemas['oneOf']: if oneof_cls in path_to_schemas[validation_metadata.path_to_item]: oneof_classes.append(oneof_cls) continue - if isinstance(arg, oneof_cls): - # passed in instance is the correct type - chosen_oneof_cls = oneof_cls + if validation_metadata.validation_ran_earlier(oneof_cls): oneof_classes.append(oneof_cls) continue try: path_to_schemas = oneof_cls._validate(arg, validation_metadata=validation_metadata) - new_base_classes = validation_metadata.base_classes except (ApiValueError, ApiTypeError) as ex: if discriminated_cls is not None and oneof_cls is discriminated_cls: raise ex continue - chosen_oneof_cls = oneof_cls oneof_classes.append(oneof_cls) if not oneof_classes: raise ApiValueError( @@ -1679,15 +1618,9 @@ class ComposedBase(Discriminable): validation_metadata: ValidationMetadata ): anyof_classes = [] - chosen_anyof_cls = None - original_base_classes = validation_metadata.base_classes path_to_schemas = defaultdict(set) for anyof_cls in cls._composed_schemas['anyOf']: - if anyof_cls in validation_metadata.base_classes: - continue - if isinstance(arg, anyof_cls): - # passed in instance is the correct type - chosen_anyof_cls = anyof_cls + if validation_metadata.validation_ran_earlier(anyof_cls): anyof_classes.append(anyof_cls) continue @@ -1697,8 +1630,6 @@ class ComposedBase(Discriminable): if discriminated_cls is not None and anyof_cls is discriminated_cls: raise ex continue - original_base_classes = validation_metadata.base_classes - chosen_anyof_cls = anyof_cls anyof_classes.append(anyof_cls) update(path_to_schemas, other_path_to_schemas) if not anyof_classes: @@ -1713,7 +1644,7 @@ class ComposedBase(Discriminable): cls, arg, validation_metadata: ValidationMetadata, - ): + ) -> typing.Dict[typing.Tuple[typing.Union[str, int], ...], typing.Set[typing.Union['Schema', str, decimal.Decimal, BoolClass, NoneClass, frozendict, tuple]]]: """ ComposedBase _validate We return dynamic classes of different bases depending upon the inputs @@ -1748,7 +1679,8 @@ class ComposedBase(Discriminable): configuration=validation_metadata.configuration, from_server=validation_metadata.from_server, path_to_item=validation_metadata.path_to_item, - base_classes=validation_metadata.base_classes | frozenset({cls}) + seen_classes=validation_metadata.seen_classes | frozenset({cls}), + validated_path_to_schemas=validation_metadata.validated_path_to_schemas ) # process composed schema @@ -1792,20 +1724,24 @@ class ComposedBase(Discriminable): not_cls = cls._composed_schemas['not'] if not_cls: other_path_to_schemas = None + not_exception = ApiValueError( + "Invalid value '{}' was passed in to {}. Value is invalid because it is disallowed by {}".format( + arg, + cls.__name__, + not_cls.__name__, + ) + ) + if updated_vm.validation_ran_earlier(not_cls): + raise not_exception + try: other_path_to_schemas = not_cls._validate(arg, validation_metadata=updated_vm) except (ApiValueError, ApiTypeError): pass if other_path_to_schemas: - raise ApiValueError( - "Invalid value '{}' was passed in to {}. Value is invalid because it is disallowed by {}".format( - arg, - cls.__name__, - not_cls.__name__, - ) - ) + raise not_exception - if discriminated_cls is not None: + if discriminated_cls is not None and not updated_vm.validation_ran_earlier(discriminated_cls): # TODO use an exception from this package here assert discriminated_cls in path_to_schemas[updated_vm.path_to_item] return path_to_schemas @@ -1813,7 +1749,7 @@ class ComposedBase(Discriminable): # DictBase, ListBase, NumberBase, StrBase, BoolBase, NoneBase class ComposedSchema( - _SchemaTypeChecker(typing.Union[none_type, str, decimal.Decimal, bool, tuple, frozendict]), + _SchemaTypeChecker(typing.Union[NoneClass, str, decimal.Decimal, BoolClass, tuple, frozendict]), ComposedBase, DictBase, ListBase, @@ -1851,7 +1787,7 @@ class ListSchema( class NoneSchema( - _SchemaTypeChecker(typing.Union[none_type]), + _SchemaTypeChecker(typing.Union[NoneClass]), NoneBase, Schema ): @@ -2122,7 +2058,7 @@ class BinarySchema( class BoolSchema( - _SchemaTypeChecker(typing.Union[bool]), + _SchemaTypeChecker(typing.Union[BoolClass]), BoolBase, Schema ): @@ -2137,7 +2073,7 @@ class BoolSchema( class AnyTypeSchema( _SchemaTypeChecker( - typing.Union[frozendict, tuple, decimal.Decimal, str, bool, none_type, bytes, FileIO] + typing.Union[frozendict, tuple, decimal.Decimal, str, BoolClass, NoneClass, bytes, FileIO] ), DictBase, ListBase, @@ -2164,7 +2100,7 @@ class DictSchema( return super().__new__(cls, *args, **kwargs) -schema_descendents = set([NoneSchema, DictSchema, ListSchema, NumberSchema, StrSchema, BoolSchema]) +schema_type_classes = set([NoneSchema, DictSchema, ListSchema, NumberSchema, StrSchema, BoolSchema]) def deserialize_file(response_data, configuration, content_disposition=None): diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_boolean_enum.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_boolean_enum.py index 811a18defed..bd343b2847c 100644 --- a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_boolean_enum.py +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_boolean_enum.py @@ -31,7 +31,7 @@ class TestBooleanEnum(unittest.TestCase): assert model is BooleanEnum.TRUE assert model.is_true() assert model.is_false() is False - assert repr(model) == '' + assert repr(model) == '' with self.assertRaises(petstore_api.ApiValueError): BooleanEnum(False) diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_combine_schemas.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_combine_schemas.py index c6571ded220..403d9709f82 100644 --- a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_combine_schemas.py +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_combine_schemas.py @@ -10,7 +10,7 @@ """ -import sys +import decimal import unittest import petstore_api @@ -40,20 +40,12 @@ class TestCombineNonObjectSchemas(unittest.TestCase): assert EnumPlusPrim._enum_value_to_name == {0: "POSITIVE_0"} - # _enum_value_to_name only contains one key - assert set(EnumPlusPrim._enum_value_to_name) == {0} - # the value is the expected enum class - enum_value_cls = EnumPlusPrim._enum_by_value[0] - assert issubclass(enum_value_cls, EnumPlusPrim) - assert issubclass(enum_value_cls, Singleton) - assert issubclass(enum_value_cls, int) - # the enum stored in that class is expected - enum_value = enum_value_cls.POSITIVE_0 + enum_value = EnumPlusPrim.POSITIVE_0 assert isinstance(enum_value, EnumPlusPrim) assert isinstance(enum_value, Singleton) - assert isinstance(enum_value, int) + assert isinstance(enum_value, decimal.Decimal) # we can access this enum from our class - assert EnumPlusPrim.POSITIVE_0 == enum_value + assert EnumPlusPrim.POSITIVE_0 == 0 # invalid value throws an exception with self.assertRaises(petstore_api.ApiValueError): @@ -64,7 +56,7 @@ class TestCombineNonObjectSchemas(unittest.TestCase): assert val == 0 assert isinstance(val, EnumPlusPrim) assert isinstance(val, Singleton) - assert isinstance(val, int) + assert isinstance(val, decimal.Decimal) def test_valid_enum_plus_enum(self): class IntegerOneEnum(IntegerEnum, IntegerEnumOneValue): @@ -78,20 +70,12 @@ class TestCombineNonObjectSchemas(unittest.TestCase): assert IntegerOneEnum._enum_value_to_name == {0: "POSITIVE_0"} - # _enum_by_value only contains one key - assert set(IntegerOneEnum._enum_by_value) == {0} - # the value is the expected enum class - enum_value_cls = IntegerOneEnum._enum_by_value[0] - assert issubclass(enum_value_cls, IntegerOneEnum) - assert issubclass(enum_value_cls, Singleton) - assert issubclass(enum_value_cls, int) - # the enum stored in that class is expected - enum_value = enum_value_cls.POSITIVE_0 + enum_value = IntegerOneEnum.POSITIVE_0 assert isinstance(enum_value, IntegerOneEnum) assert isinstance(enum_value, Singleton) - assert isinstance(enum_value, int) + assert isinstance(enum_value, decimal.Decimal) # we can access this enum from our class - assert IntegerOneEnum.POSITIVE_0 == enum_value + assert IntegerOneEnum.POSITIVE_0 == 0 # accessing invalid enum throws an exception invalid_enums = ['POSITIVE_1', 'POSITIVE_2'] diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_date_time_with_validations.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_date_time_with_validations.py index 3d26e42bc1d..0703a36da14 100644 --- a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_date_time_with_validations.py +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_date_time_with_validations.py @@ -56,7 +56,7 @@ class TestDateTimeWithValidations(unittest.TestCase): # value error is raised if an invalid string is passed in with self.assertRaisesRegex( petstore_api.ApiValueError, - r"Value does not conform to the required ISO-8601 datetime format. Invalid value 'abcd' for type datetime at \('args\[0\]',\)" + r"Invalid value `abcd`, must match regular expression `.+?` at \('args\[0\]',\)" ): DateTimeWithValidations._from_openapi_data("abcd") diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_date_with_validations.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_date_with_validations.py index fff79f16cfc..e2fcae60f46 100644 --- a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_date_with_validations.py +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_date_with_validations.py @@ -66,8 +66,8 @@ class TestDateWithValidations(unittest.TestCase): # value error is raised if an invalid string is passed in with self.assertRaisesRegex( - petstore_api.ApiValueError, - r"Value does not conform to the required ISO-8601 date format. Invalid value 'abcd' for type date at \('args\[0\]',\)" + petstore_api.ApiValueError, + r"Invalid value `abcd`, must match regular expression `.+?` at \('args\[0\]',\)" ): DateWithValidations._from_openapi_data("abcd") diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_drawing.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_drawing.py index 3be8388499c..ba919798147 100644 --- a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_drawing.py +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_drawing.py @@ -99,29 +99,26 @@ class TestDrawing(unittest.TestCase): ) """ - we can't pass in an incorrect type for shapes - 'shapes' items has type 'Shape', which is a oneOf [Triangle, Quadrilateral] - composed schema. We are not able to assign Triangle tor Quadrilateral - to a shapes item because those instances do not include Shape validation - Shape could require additional validations that Triangle + Quadrilateral do not include + We can pass in a Triangle instance in shapes + Under the hood it is converted into a dict, and that dict payload + does validate as a Shape, so this works """ from petstore_api.model.triangle import Triangle - err_msg = (r"Incorrect type passed in, required type was " - r"and passed type was at " - r"\('args\[0\]', 'shapes', 0\)") - with self.assertRaisesRegex( - petstore_api.ApiTypeError, - err_msg - ): - inst = Drawing( - mainShape=isosceles_triangle, - shapes=[ - Triangle( - shapeType="Triangle", - triangleType="EquilateralTriangle" - ) - ] - ) + inst = Drawing( + mainShape=isosceles_triangle, + shapes=[ + Triangle( + shapeType="Triangle", + triangleType="EquilateralTriangle" + ) + ] + ) + self.assertEqual(len(inst.shapes), 1) + from petstore_api.model.triangle_interface import TriangleInterface + assert isinstance(inst.shapes[0], shape.Shape) + assert isinstance(inst.shapes[0], Triangle) + assert isinstance(inst.shapes[0], EquilateralTriangle) + assert isinstance(inst.shapes[0], TriangleInterface) def test_deserialize_oneof_reference_with_null_type(self): """ diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_fake_api.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_fake_api.py index bb006c131c2..fb6d11e2afc 100644 --- a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_fake_api.py +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_fake_api.py @@ -491,6 +491,7 @@ class TestFakeApi(ApiTestMixin): with open(file_path1, "rb") as some_file: file_bytes = some_file.read() file1 = open(file_path1, "rb") + file2 = open(file_path1, "rb") response_json = { 'code': 200, 'type': 'blah', @@ -501,7 +502,7 @@ class TestFakeApi(ApiTestMixin): mock_request.return_value = self.response( self.json_bytes(response_json) ) - api_response = self.api.upload_files(body={'files': [file1, file1]}) + api_response = self.api.upload_files(body={'files': [file1, file2]}) self.assert_request_called_with( mock_request, 'http://petstore.swagger.io:80/v2/fake/uploadFiles', @@ -526,6 +527,7 @@ class TestFakeApi(ApiTestMixin): self.fail("upload_file() raised {0} unexpectedly".format(type(e))) finally: file1.close() + file2.close() # sending just bytes works also with patch.object(RESTClientObject, 'request') as mock_request: diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_nullable_string.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_nullable_string.py index d873e45531b..1949de4837b 100644 --- a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_nullable_string.py +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_nullable_string.py @@ -33,7 +33,7 @@ class TestNullableString(unittest.TestCase): assert isinstance(inst, NullableString) assert isinstance(inst, Schema) assert inst.is_none() is True - assert repr(inst) == '' + assert repr(inst) == '' inst = NullableString('approved') assert inst.is_none() is False @@ -46,7 +46,7 @@ class TestNullableString(unittest.TestCase): for invalid_value in invalid_values: with self.assertRaisesRegex( petstore_api.ApiTypeError, - r"Invalid type. Required value type is one of \[NoneType, str\] and passed type was Decimal at \['args\[0\]'\]" + r"Invalid type. Required value type is one of \[NoneClass, str\] and passed type was Decimal at \['args\[0\]'\]" ): NullableString(invalid_value) diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_string_enum.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_string_enum.py index a877eddfd2f..0485242b37e 100644 --- a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_string_enum.py +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_string_enum.py @@ -31,14 +31,14 @@ class TestStringEnum(unittest.TestCase): inst = StringEnum(None) assert isinstance(inst, StringEnum) assert isinstance(inst, NoneClass) - assert repr(inst) == '' + assert repr(inst) == '' inst = StringEnum('approved') assert isinstance(inst, StringEnum) assert isinstance(inst, Singleton) assert isinstance(inst, str) assert inst == 'approved' - assert repr(inst) == "" + assert repr(inst) == "" with self.assertRaises(petstore_api.ApiValueError): StringEnum('garbage') diff --git a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_validate.py b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_validate.py index cc62ccff3cc..19592fe3842 100644 --- a/samples/openapi3/client/petstore/python-experimental/tests_manual/test_validate.py +++ b/samples/openapi3/client/petstore/python-experimental/tests_manual/test_validate.py @@ -3,7 +3,7 @@ from collections import defaultdict from decimal import Decimal import typing -from unittest.mock import patch +from unittest.mock import patch, call import unittest import petstore_api @@ -26,6 +26,8 @@ from petstore_api.model.banana import Banana from petstore_api.schemas import ( AnyTypeSchema, + BoolClass, + NoneClass, StrSchema, NumberSchema, Schema, @@ -52,12 +54,12 @@ class TestValidateResults(unittest.TestCase): def test_str_enum_validate(self): vm = ValidationMetadata() path_to_schemas = StringEnum._validate("placed", validation_metadata=vm) - assert path_to_schemas == {("args[0]",): set([StringEnum])} + assert path_to_schemas == {("args[0]",): {str, StringEnum}} def test_nullable_enum_validate(self): vm = ValidationMetadata() - path_to_schemas = StringEnum._validate(None, validation_metadata=vm) - assert path_to_schemas == {("args[0]",): set([StringEnum])} + path_to_schemas = StringEnum._validate(NoneClass.NONE, validation_metadata=vm) + assert path_to_schemas == {("args[0]",): {NoneClass, StringEnum}} def test_empty_list_validate(self): vm = ValidationMetadata() @@ -105,8 +107,8 @@ class TestValidateResults(unittest.TestCase): def test_bool_enum_validate(self): vm = ValidationMetadata() - path_to_schemas = BooleanEnum._validate(True, validation_metadata=vm) - assert path_to_schemas == {("args[0]",): set([BooleanEnum])} + path_to_schemas = BooleanEnum._validate(BoolClass.TRUE, validation_metadata=vm) + assert path_to_schemas == {("args[0]",): {BoolClass, BooleanEnum}} def test_oneof_composition_pig_validate(self): vm = ValidationMetadata() @@ -137,7 +139,7 @@ class TestValidateCalls(unittest.TestCase): with patch.object( Schema, "_validate", return_value=return_value ) as mock_validate: - instance = ArrayHoldingAnyType([]) + ArrayHoldingAnyType([]) assert mock_validate.call_count == 1 with patch.object( @@ -151,7 +153,7 @@ class TestValidateCalls(unittest.TestCase): with patch.object( Schema, "_validate", return_value=return_value ) as mock_validate: - instance = Foo({}) + Foo({}) assert mock_validate.call_count == 1 with patch.object( @@ -161,237 +163,118 @@ class TestValidateCalls(unittest.TestCase): assert mock_validate.call_count == 1 def test_list_validate_direct_instantiation(self): - expected_call_by_index = { - 0: [ - ArrayWithValidationsInItems, - ((Decimal("7"),),), - ValidationMetadata(path_to_item=("args[0]",)), - ], - 1: [ - ArrayWithValidationsInItems._items, - (Decimal("7"),), - ValidationMetadata(path_to_item=("args[0]", 0)), - ], - } - call_index = 0 - result_by_call_index = { - 0: defaultdict( - set, [(("args[0]",), set([ArrayWithValidationsInItems, tuple]))] - ), - 1: defaultdict( - set, - [(("args[0]", 0), set([ArrayWithValidationsInItems._items, Decimal]))], - ), - } - - @classmethod - def new_validate( - cls, - *args, - validation_metadata: typing.Optional[ValidationMetadata] = None, - ): - nonlocal call_index - assert [cls, args, validation_metadata] == expected_call_by_index[ - call_index - ] - result = result_by_call_index.get(call_index) - call_index += 1 - if result is None: - raise petstore_api.ApiValueError("boom") - return result - - with patch.object(Schema, "_validate", new=new_validate): + results = [ + {("args[0]",): {ArrayWithValidationsInItems, tuple}}, + {("args[0]", 0): {ArrayWithValidationsInItems._items, Decimal}} + ] + with patch.object(Schema, "_validate", side_effect=results) as mock_validate: ArrayWithValidationsInItems([7]) + calls = [ + call( + (Decimal("7"),), + validation_metadata=ValidationMetadata(path_to_item=("args[0]",)) + ), + call( + Decimal("7"), + ValidationMetadata(path_to_item=("args[0]", 0)) + ) + ] + mock_validate.assert_has_calls( + calls + ) def test_list_validate_direct_instantiation_cast_item(self): - # validation is skipped if items are of the correct type - expected_call_by_index = { - 0: [ - ArrayWithValidationsInItems, - ((Decimal("7"),),), - ValidationMetadata(path_to_item=("args[0]",)), - ], - } - call_index = 0 - result_by_call_index = { - 0: defaultdict( - set, [(("args[0]",), set([ArrayWithValidationsInItems, tuple]))] - ), - } - - @classmethod - def new_validate( - cls, - *args, - validation_metadata: typing.Optional[ValidationMetadata] = None, - ): - nonlocal call_index - assert [cls, args, validation_metadata] == expected_call_by_index[ - call_index - ] - result = result_by_call_index.get(call_index) - call_index += 1 - if result is None: - raise petstore_api.ApiValueError("boom") - return result - + # item validation is skipped if items are of the correct type item = ArrayWithValidationsInItems._items(7) - with patch.object(Schema, "_validate", new=new_validate): + return_value = {("args[0]",): {ArrayWithValidationsInItems, tuple}} + with patch.object(Schema, "_validate", return_value=return_value) as mock_validate: ArrayWithValidationsInItems([item]) + mock_validate.assert_called_once_with( + tuple([Decimal('7')]), + validation_metadata=ValidationMetadata( + validated_path_to_schemas={('args[0]', 0): {ArrayWithValidationsInItems._items, Decimal}} + ) + ) def test_list_validate_from_openai_data_instantiation(self): - expected_call_by_index = { - 0: [ - ArrayWithValidationsInItems, - ((Decimal("7"),),), - ValidationMetadata(path_to_item=("args[0]",), from_server=True), - ], - 1: [ - ArrayWithValidationsInItems._items, - (Decimal("7"),), - ValidationMetadata(path_to_item=("args[0]", 0), from_server=True), - ], - } - call_index = 0 - result_by_call_index = { - 0: defaultdict( - set, [(("args[0]",), set([ArrayWithValidationsInItems, tuple]))] - ), - 1: defaultdict( - set, - [(("args[0]", 0), set([ArrayWithValidationsInItems._items, Decimal]))], - ), - } - @classmethod - def new_validate( - cls, - *args, - validation_metadata: typing.Optional[ValidationMetadata] = None, - ): - nonlocal call_index - assert [cls, args, validation_metadata] == expected_call_by_index[ - call_index - ] - result = result_by_call_index.get(call_index) - call_index += 1 - if result is None: - raise petstore_api.ApiValueError("boom") - return result - - with patch.object(Schema, "_validate", new=new_validate): + results = [ + {("args[0]",): {ArrayWithValidationsInItems, tuple}}, + {("args[0]", 0): {ArrayWithValidationsInItems._items, Decimal}} + ] + with patch.object(Schema, "_validate", side_effect=results) as mock_validate: ArrayWithValidationsInItems._from_openapi_data([7]) + calls = [ + call( + (Decimal("7"),), + validation_metadata=ValidationMetadata(path_to_item=("args[0]",), from_server=True) + ), + call( + Decimal("7"), + ValidationMetadata(path_to_item=("args[0]", 0), from_server=True) + ) + ] + mock_validate.assert_has_calls( + calls + ) def test_dict_validate_direct_instantiation(self): - expected_call_by_index = { - 0: [ - Foo, - (frozendict({"bar": "a"}),), - ValidationMetadata(path_to_item=("args[0]",)), - ], - 1: [ - StrSchema, - ("a",), - ValidationMetadata(path_to_item=("args[0]", "bar")), - ], - } - call_index = 0 - result_by_call_index = { - 0: defaultdict(set, [(("args[0]",), set([Foo, frozendict]))]), - 1: defaultdict(set, [(("args[0]", "bar"), set([StrSchema, str]))]), - } - - @classmethod - def new_validate( - cls, - *args, - validation_metadata: typing.Optional[ValidationMetadata] = None, - ): - nonlocal call_index - assert [cls, args, validation_metadata] == expected_call_by_index[ - call_index - ] - result = result_by_call_index.get(call_index) - call_index += 1 - if result is None: - raise petstore_api.ApiValueError("boom") - return result - - with patch.object(Schema, "_validate", new=new_validate): + call_results = [ + {("args[0]",): {Foo, frozendict}}, + {("args[0]", "bar"): {StrSchema, str}} + ] + with patch.object(Schema, "_validate", side_effect=call_results) as mock_validate: Foo(bar="a") + calls = [ + call( + frozendict({"bar": "a"}), + validation_metadata=ValidationMetadata(path_to_item=("args[0]",)), + ), + call( + "a", + ValidationMetadata(path_to_item=("args[0]", "bar")), + ), + ] + mock_validate.assert_has_calls( + calls + ) def test_dict_validate_direct_instantiation_cast_item(self): - expected_call_by_index = { - 0: [ - Foo, - (frozendict({"bar": "a"}),), - ValidationMetadata(path_to_item=("args[0]",)), - ], - } - call_index = 0 - result_by_call_index = { - 0: defaultdict(set, [(("args[0]",), set([Foo, frozendict]))]), - } - - @classmethod - def new_validate( - cls, - *args, - validation_metadata: typing.Optional[ValidationMetadata] = None, - ): - nonlocal call_index - assert [cls, args, validation_metadata] == expected_call_by_index[ - call_index - ] - result = result_by_call_index.get(call_index) - call_index += 1 - if result is None: - raise petstore_api.ApiValueError("boom") - return result - bar = StrSchema("a") - with patch.object(Schema, "_validate", new=new_validate): + return_value = { + ("args[0]",): {Foo, frozendict} + } + # only the Foo dict is validated because the bar property value was already validated + with patch.object(Schema, "_validate", return_value=return_value) as mock_validate: Foo(bar=bar) + mock_validate.assert_called_once_with( + frozendict(dict(bar='a')), + validation_metadata=ValidationMetadata( + validated_path_to_schemas={('args[0]', 'bar'): {str, StrSchema}} + ) + ) def test_dict_validate_from_openapi_data_instantiation(self): - expected_call_by_index = { - 0: [ - Foo, - (frozendict({"bar": "a"}),), - ValidationMetadata(path_to_item=("args[0]",), from_server=True), - ], - 1: [ - StrSchema, - ("a",), - ValidationMetadata( - path_to_item=("args[0]", "bar"), from_server=True - ), - ], - } - call_index = 0 - result_by_call_index = { - 0: defaultdict(set, [(("args[0]",), set([Foo, frozendict]))]), - 1: defaultdict(set, [(("args[0]", "bar"), set([StrSchema, str]))]), - } - @classmethod - def new_validate( - cls, - *args, - validation_metadata: typing.Optional[ValidationMetadata] = None, - ): - nonlocal call_index - assert [cls, args, validation_metadata] == expected_call_by_index[ - call_index - ] - result = result_by_call_index.get(call_index) - call_index += 1 - if result is None: - raise petstore_api.ApiValueError("boom") - return result - - with patch.object(Schema, "_validate", new=new_validate): + return_values = [ + {("args[0]",): {Foo, frozendict}}, + {("args[0]", 'bar'): {StrSchema, str}} + ] + with patch.object(Schema, "_validate", side_effect=return_values) as mock_validate: Foo._from_openapi_data({"bar": "a"}) + calls = [ + call( + frozendict({"bar": "a"}), + validation_metadata=ValidationMetadata(path_to_item=("args[0]",), from_server=True), + ), + call( + "a", + ValidationMetadata(path_to_item=("args[0]", "bar"), from_server=True), + ), + ] + mock_validate.assert_has_calls( + calls + ) if __name__ == "__main__":