From 9bc1ae1dc2e8e8ed193c5c2a20219ba476cd6565 Mon Sep 17 00:00:00 2001 From: Justin Black Date: Tue, 6 Jun 2023 10:39:00 -0700 Subject: [PATCH] v3 convert nested schemas into sequential schemas (#177) * Writes nested schemas earlier and uses them later * Refactors order CodegenSchema properties are set in to match the order in getSchemas * Adjusts ref input to setSchemaLocationInfo * Tweak improves schema template * Adds properties classes * Replaces properties with field * Uses Schema_() * Uses dataclass properties * Adds missing type info * Updates all_of * Adds any_of, all_of tuples * Fixes types definition * Fixed test_any_type_schema tests * Fixes dataclass type setting issues * Fixes simple schema format type * Adds and uses PatternInfo for pattern schema info, validate_regex changed to validate_pattern * Fixes not constraint tests * Adds tuple_to_instance * Writes out allOf/anyOf/oneOf types * Updates classproperty decorator * Adds enum return types * Fixes type errors in schemas.py * Adds schema singleton metaclass * Replaces CodegenServer variables with object schema containing variables in properties * Generates server variables as an object schema to keep all schemas at the root depth * Fixes new signatures in servers schemas * Simplifies Server variables definition * Uses schema default for server variables * Adds required vars in server definition * Fixes classproperty and SchemaBase classes * Fixes broken configuration tests * Fixes server docs * Adds isInlineDefinition * Adds allOf/anyOf/oneOf/properties jsonPathPiece * Uses jsonPathPiece in properties/allOf/anyOf/oneOf * Fixes properties typeddict name * Templates updated to write allOf/anyOf/oneOf/properties earlier if possible * generates properties/allOf/anyOf/oneOf before class if possible * Adds and uses schemas.INPUT_TYPES_ALL_INCL_SCHEMA * Adds another usage of schemas.INPUT_TYPES_ALL_INCL_SCHEMA * Changes SchemaBase to SingletonMeta * Only calculates allSchemas once * Reduces iteration through allSchemas from 2x to 1x * Removes some getKey invocations * Consolidates more getKey usages * Deletes getKey with one input * Adds comment * Updates the definition of required properties, reduces the number of calls to getKey * Updates getKey to use sourceJsonPath * Adds class name generation that includes numbered suffixes when needed * Uses pre order traversal for naming schema classes * Fixes oneOf/anyOf/allOf type aliases * Adds and uses schemas.INPUT_BASE_TYPES * Adds string representation of CodegenKey * Fixes java tests * Samples regenerated * Samples regenerated --- .../codegen/CodegenConfig.java | 4 +- .../codegen/DefaultCodegen.java | 306 +-- .../languages/PythonClientCodegen.java | 15 +- .../codegen/model/ArrayListWithContext.java | 26 + .../codegen/model/CodegenKey.java | 12 + .../codegen/model/CodegenSchema.java | 130 +- .../codegen/model/CodegenServer.java | 6 +- .../codegen/model/InlineContext.java | 11 + .../model/LinkedHashMapWithContext.java | 23 + .../python/_helper_types_all_incl_schema.hbs | 2 +- .../components/schemas/_helper_allof_type.hbs | 9 + .../components/schemas/_helper_anyof_type.hbs | 9 + .../schemas/_helper_composed_schemas.hbs | 69 +- .../schemas/_helper_dict_partial.hbs | 50 +- .../components/schemas/_helper_enums.hbs | 6 +- .../schemas/_helper_getitem_property.hbs | 6 +- .../components/schemas/_helper_getitems.hbs | 10 +- .../components/schemas/_helper_getschemas.hbs | 27 + .../schemas/_helper_list_partial.hbs | 7 +- .../python/components/schemas/_helper_new.hbs | 34 +- .../_helper_new_property_value_type.hbs | 10 +- .../_helper_new_ref_property_value_type.hbs | 6 +- .../components/schemas/_helper_oneof_type.hbs | 9 + .../schemas/_helper_properties_type.hbs | 12 + .../schemas/_helper_property_type_hints.hbs | 12 +- .../_helper_schema_composed_or_anytype.hbs | 6 +- .../schemas/_helper_schema_dict.hbs | 6 +- .../schemas/_helper_schema_enum.hbs | 18 +- .../schemas/_helper_schema_list.hbs | 10 +- .../schemas/_helper_schema_simple.hbs | 17 +- .../components/schemas/_helper_types.hbs | 4 +- .../_helper_types_all_incl_schema_newline.hbs | 17 - .../schemas/_helper_validations.hbs | 30 +- .../python/components/schemas/schema.hbs | 5 +- .../configurations/schema_configuration.hbs | 42 +- .../src/main/resources/python/schemas.hbs | 376 ++-- .../src/main/resources/python/server.hbs | 25 +- .../main/resources/python/servers/server.hbs | 62 +- .../resources/python/servers/server_doc.hbs | 6 +- .../python/shared_imports/schema_imports.hbs | 1 + .../codegen/DefaultCodegenTest.java | 163 +- .../codegen/DefaultGeneratorTest.java | 8 +- .../schema/allof_combined_with_anyof_oneof.md | 8 +- ...ted_allof_to_check_validation_semantics.md | 4 +- ...ted_anyof_to_check_validation_semantics.md | 4 +- .../docs/components/schema/nested_items.md | 8 +- ...ted_oneof_to_check_validation_semantics.md | 4 +- .../unit_test_api/components/schema/_not.py | 47 +- ...s_allows_a_schema_which_should_validate.py | 62 +- ...tionalproperties_are_allowed_by_default.py | 92 +- ...dditionalproperties_can_exist_by_itself.py | 14 +- ...operties_should_not_look_in_applicators.py | 292 ++- .../unit_test_api/components/schema/allof.py | 465 ++--- .../schema/allof_combined_with_anyof_oneof.py | 482 ++--- .../components/schema/allof_simple_types.py | 329 +-- .../schema/allof_with_base_schema.py | 489 ++--- .../schema/allof_with_one_empty_schema.py | 55 +- .../allof_with_the_first_empty_schema.py | 59 +- .../allof_with_the_last_empty_schema.py | 59 +- .../schema/allof_with_two_empty_schemas.py | 59 +- .../unit_test_api/components/schema/anyof.py | 196 +- .../components/schema/anyof_complex_types.py | 465 ++--- .../schema/anyof_with_base_schema.py | 298 ++- .../schema/anyof_with_one_empty_schema.py | 59 +- .../schema/array_type_matches_arrays.py | 25 +- .../schema/boolean_type_matches_booleans.py | 1 + .../unit_test_api/components/schema/by_int.py | 46 +- .../components/schema/by_number.py | 46 +- .../components/schema/by_small_number.py | 46 +- .../components/schema/date_time_format.py | 46 +- .../components/schema/email_format.py | 46 +- .../schema/enum_with0_does_not_match_false.py | 18 +- .../schema/enum_with1_does_not_match_true.py | 18 +- .../schema/enum_with_escaped_characters.py | 22 +- .../schema/enum_with_false_does_not_match0.py | 18 +- .../schema/enum_with_true_does_not_match1.py | 18 +- .../components/schema/enums_in_properties.py | 133 +- .../components/schema/forbidden_property.py | 73 +- .../components/schema/hostname_format.py | 46 +- .../schema/integer_type_matches_integers.py | 1 + ...not_raise_error_when_float_division_inf.py | 12 +- .../invalid_string_value_for_default.py | 87 +- .../components/schema/ipv4_format.py | 46 +- .../components/schema/ipv6_format.py | 46 +- .../components/schema/json_pointer_format.py | 46 +- .../components/schema/maximum_validation.py | 46 +- ...aximum_validation_with_unsigned_integer.py | 46 +- .../components/schema/maxitems_validation.py | 46 +- .../components/schema/maxlength_validation.py | 46 +- ...axproperties0_means_the_object_is_empty.py | 46 +- .../schema/maxproperties_validation.py | 46 +- .../components/schema/minimum_validation.py | 46 +- .../minimum_validation_with_signed_integer.py | 46 +- .../components/schema/minitems_validation.py | 46 +- .../components/schema/minlength_validation.py | 46 +- .../schema/minproperties_validation.py | 46 +- ...ted_allof_to_check_validation_semantics.py | 201 +- ...ted_anyof_to_check_validation_semantics.py | 201 +- .../components/schema/nested_items.py | 229 +- ...ted_oneof_to_check_validation_semantics.py | 201 +- .../schema/not_more_complex_schema.py | 195 +- .../schema/nul_characters_in_strings.py | 18 +- .../null_type_matches_only_the_null_object.py | 1 + .../schema/number_type_matches_numbers.py | 1 + .../schema/object_properties_validation.py | 70 +- .../schema/object_type_matches_objects.py | 1 + .../unit_test_api/components/schema/oneof.py | 196 +- .../components/schema/oneof_complex_types.py | 465 ++--- .../schema/oneof_with_base_schema.py | 298 ++- .../schema/oneof_with_empty_schema.py | 59 +- .../components/schema/oneof_with_required.py | 602 +++--- .../schema/pattern_is_not_anchored.py | 50 +- .../components/schema/pattern_validation.py | 50 +- .../properties_with_escaped_characters.py | 90 +- ...perty_named_ref_that_is_not_a_reference.py | 60 +- .../schema/ref_in_additionalproperties.py | 25 +- .../components/schema/ref_in_allof.py | 57 +- .../components/schema/ref_in_anyof.py | 57 +- .../components/schema/ref_in_items.py | 25 +- .../components/schema/ref_in_not.py | 49 +- .../components/schema/ref_in_oneof.py | 57 +- .../components/schema/ref_in_property.py | 73 +- .../schema/required_default_validation.py | 73 +- .../components/schema/required_validation.py | 85 +- .../schema/required_with_empty_array.py | 73 +- .../required_with_escaped_characters.py | 48 +- .../schema/simple_enum_validation.py | 26 +- .../schema/string_type_matches_strings.py | 1 + ..._do_anything_if_the_property_is_missing.py | 70 +- .../schema/uniqueitems_false_validation.py | 46 +- .../schema/uniqueitems_validation.py | 46 +- .../components/schema/uri_format.py | 46 +- .../components/schema/uri_reference_format.py | 46 +- .../components/schema/uri_template_format.py | 46 +- .../configurations/schema_configuration.py | 42 +- .../python/src/unit_test_api/schemas.py | 380 ++-- .../python/src/unit_test_api/server.py | 25 +- .../src/unit_test_api/servers/server_0.py | 4 +- .../shared_imports/schema_imports.py | 1 + .../components/schema/addition_operator.py | 77 +- .../components/schema/operator.py | 70 +- .../components/schema/subtraction_operator.py | 77 +- .../configurations/schema_configuration.py | 42 +- .../python/src/this_package/schemas.py | 383 ++-- .../python/src/this_package/server.py | 25 +- .../src/this_package/servers/server_0.py | 4 +- .../shared_imports/schema_imports.py | 1 + .../configurations/schema_configuration.py | 42 +- .../python/src/this_package/schemas.py | 380 ++-- .../python/src/this_package/server.py | 25 +- .../src/this_package/servers/server_0.py | 4 +- .../shared_imports/schema_imports.py | 1 + .../schema/additional_properties_class.md | 4 +- .../docs/components/schema/array_test.md | 8 +- .../docs/components/schema/nullable_class.md | 20 +- .../content/application_json/schema.py | 1 + .../headers/header_number_header/schema.py | 1 + .../headers/header_string_header/schema.py | 1 + .../parameter_path_user_name/schema.py | 1 + .../content/application_json/schema.py | 12 +- .../content/application_json/schema.py | 14 +- .../headers/header_some_header/schema.py | 1 + .../content/application_json/schema.py | 12 +- .../content/application_xml/schema.py | 12 +- .../components/schema/_200_response.py | 68 +- .../petstore_api/components/schema/_return.py | 60 +- .../schema/abstract_step_message.py | 73 +- .../schema/additional_properties_class.py | 581 +++--- .../schema/additional_properties_validator.py | 666 +++--- ...ditional_properties_with_array_of_enums.py | 85 +- .../petstore_api/components/schema/address.py | 14 +- .../petstore_api/components/schema/animal.py | 89 +- .../components/schema/animal_farm.py | 12 +- .../components/schema/any_type_and_format.py | 1423 +++++-------- .../components/schema/any_type_not_string.py | 47 +- .../components/schema/api_response.py | 61 +- .../petstore_api/components/schema/apple.py | 115 +- .../components/schema/apple_req.py | 42 +- .../schema/array_holding_any_type.py | 25 +- .../schema/array_of_array_of_number_only.py | 189 +- .../components/schema/array_of_enums.py | 12 +- .../components/schema/array_of_number_only.py | 118 +- .../components/schema/array_test.py | 416 ++-- .../schema/array_with_validations_in_items.py | 41 +- .../petstore_api/components/schema/banana.py | 51 +- .../components/schema/banana_req.py | 42 +- .../src/petstore_api/components/schema/bar.py | 10 +- .../components/schema/basque_pig.py | 88 +- .../petstore_api/components/schema/boolean.py | 1 + .../components/schema/boolean_enum.py | 18 +- .../components/schema/capitalization.py | 85 +- .../src/petstore_api/components/schema/cat.py | 209 +- .../components/schema/category.py | 82 +- .../components/schema/child_cat.py | 209 +- .../components/schema/class_model.py | 62 +- .../petstore_api/components/schema/client.py | 45 +- .../schema/complex_quadrilateral.py | 246 +-- ...d_any_of_different_types_no_validations.py | 243 +-- .../components/schema/composed_array.py | 25 +- .../components/schema/composed_bool.py | 20 +- .../components/schema/composed_none.py | 20 +- .../components/schema/composed_number.py | 20 +- .../components/schema/composed_object.py | 40 +- .../schema/composed_one_of_different_types.py | 320 ++- .../components/schema/composed_string.py | 20 +- .../components/schema/currency.py | 22 +- .../components/schema/danish_pig.py | 88 +- .../components/schema/date_time_test.py | 10 +- .../schema/date_time_with_validations.py | 16 +- .../schema/date_with_validations.py | 16 +- .../components/schema/decimal_payload.py | 1 + .../src/petstore_api/components/schema/dog.py | 209 +- .../petstore_api/components/schema/drawing.py | 230 +- .../components/schema/enum_arrays.py | 216 +- .../components/schema/enum_class.py | 36 +- .../components/schema/enum_test.py | 317 ++- .../components/schema/equilateral_triangle.py | 246 +-- .../petstore_api/components/schema/file.py | 45 +- .../schema/file_schema_test_class.py | 124 +- .../src/petstore_api/components/schema/foo.py | 43 +- .../components/schema/format_test.py | 539 +++-- .../components/schema/from_schema.py | 53 +- .../petstore_api/components/schema/fruit.py | 81 +- .../components/schema/fruit_req.py | 67 +- .../components/schema/gm_fruit.py | 81 +- .../components/schema/grandparent_animal.py | 58 +- .../components/schema/has_only_read_only.py | 53 +- .../components/schema/health_check_result.py | 135 +- .../components/schema/integer_enum.py | 28 +- .../components/schema/integer_enum_big.py | 28 +- .../schema/integer_enum_one_value.py | 20 +- .../schema/integer_enum_with_default_value.py | 30 +- .../components/schema/integer_max10.py | 12 +- .../components/schema/integer_min15.py | 12 +- .../components/schema/isosceles_triangle.py | 246 +-- .../petstore_api/components/schema/items.py | 14 +- .../components/schema/json_patch_request.py | 177 +- .../json_patch_request_add_replace_test.py | 122 +- .../schema/json_patch_request_move_copy.py | 97 +- .../schema/json_patch_request_remove.py | 81 +- .../petstore_api/components/schema/mammal.py | 76 +- .../components/schema/map_test.py | 400 ++-- ...perties_and_additional_properties_class.py | 136 +- .../petstore_api/components/schema/money.py | 57 +- .../petstore_api/components/schema/name.py | 80 +- .../schema/no_additional_properties.py | 42 +- .../components/schema/nullable_class.py | 1844 ++++++++--------- .../components/schema/nullable_shape.py | 67 +- .../components/schema/nullable_string.py | 9 +- .../petstore_api/components/schema/number.py | 1 + .../components/schema/number_only.py | 45 +- .../schema/number_with_validations.py | 12 +- .../schema/obj_with_required_props.py | 66 +- .../schema/obj_with_required_props_base.py | 51 +- .../components/schema/object_interface.py | 1 + ...ject_model_with_arg_and_args_properties.py | 61 +- .../schema/object_model_with_ref_props.py | 55 +- ..._with_req_test_prop_from_unset_add_prop.py | 289 ++- .../object_with_colliding_properties.py | 53 +- .../schema/object_with_decimal_properties.py | 57 +- .../object_with_difficultly_named_props.py | 59 +- ...object_with_inline_composition_property.py | 225 +- ...ect_with_invalid_named_refed_properties.py | 53 +- .../schema/object_with_optional_test_prop.py | 45 +- .../schema/object_with_validations.py | 29 +- .../petstore_api/components/schema/order.py | 165 +- .../components/schema/parent_pet.py | 49 +- .../src/petstore_api/components/schema/pet.py | 290 ++- .../src/petstore_api/components/schema/pig.py | 70 +- .../petstore_api/components/schema/player.py | 51 +- .../components/schema/quadrilateral.py | 70 +- .../schema/quadrilateral_interface.py | 111 +- .../components/schema/read_only_first.py | 53 +- .../req_props_from_explicit_add_props.py | 26 +- .../schema/req_props_from_true_add_props.py | 48 +- .../schema/req_props_from_unset_add_props.py | 31 +- .../components/schema/scalene_triangle.py | 246 +-- .../schema/self_referencing_array_model.py | 12 +- .../schema/self_referencing_object_model.py | 28 +- .../petstore_api/components/schema/shape.py | 70 +- .../components/schema/shape_or_null.py | 74 +- .../components/schema/simple_quadrilateral.py | 246 +-- .../components/schema/some_object.py | 57 +- .../components/schema/special_model_name.py | 45 +- .../petstore_api/components/schema/string.py | 1 + .../components/schema/string_boolean_map.py | 14 +- .../components/schema/string_enum.py | 43 +- .../schema/string_enum_with_default_value.py | 28 +- .../schema/string_with_validation.py | 10 +- .../src/petstore_api/components/schema/tag.py | 53 +- .../components/schema/triangle.py | 76 +- .../components/schema/triangle_interface.py | 111 +- .../petstore_api/components/schema/user.py | 426 ++-- .../components/schema/uuid_string.py | 12 +- .../petstore_api/components/schema/whale.py | 104 +- .../petstore_api/components/schema/zebra.py | 151 +- .../configurations/schema_configuration.py | 42 +- .../delete/parameters/parameter_0/schema.py | 1 + .../delete/parameters/parameter_1/schema.py | 22 +- .../delete/parameters/parameter_2/schema.py | 1 + .../delete/parameters/parameter_3/schema.py | 1 + .../delete/parameters/parameter_4/schema.py | 22 +- .../delete/parameters/parameter_5/schema.py | 1 + .../fake/get/parameters/parameter_0/schema.py | 63 +- .../fake/get/parameters/parameter_1/schema.py | 28 +- .../fake/get/parameters/parameter_2/schema.py | 63 +- .../fake/get/parameters/parameter_3/schema.py | 28 +- .../fake/get/parameters/parameter_4/schema.py | 24 +- .../fake/get/parameters/parameter_5/schema.py | 24 +- .../schema.py | 230 +- .../content/application_json/schema.py | 1 + .../schema.py | 396 ++-- .../put/parameters/parameter_0/schema.py | 1 + .../put/parameters/parameter_0/schema.py | 1 + .../put/parameters/parameter_1/schema.py | 1 + .../put/parameters/parameter_2/schema.py | 1 + .../delete/parameters/parameter_0/schema.py | 1 + .../content/application_json/schema.py | 14 +- .../post/parameters/parameter_0/schema.py | 78 +- .../post/parameters/parameter_1/schema.py | 225 +- .../content/application_json/schema.py | 78 +- .../content/multipart_form_data/schema.py | 225 +- .../content/application_json/schema.py | 78 +- .../content/multipart_form_data/schema.py | 225 +- .../schema.py | 61 +- .../application_json_charsetutf8/schema.py | 1 + .../application_json_charsetutf8/schema.py | 1 + .../content/application_json/schema.py | 1 + .../content/application_json/schema.py | 1 + .../content/application_json/schema.py | 1 + .../get/parameters/parameter_0/schema.py | 45 +- .../post/parameters/parameter_0/schema.py | 1 + .../post/parameters/parameter_1/schema.py | 1 + .../post/parameters/parameter_10/schema.py | 1 + .../post/parameters/parameter_11/schema.py | 1 + .../post/parameters/parameter_12/schema.py | 1 + .../post/parameters/parameter_13/schema.py | 1 + .../post/parameters/parameter_14/schema.py | 1 + .../post/parameters/parameter_15/schema.py | 1 + .../post/parameters/parameter_16/schema.py | 1 + .../post/parameters/parameter_17/schema.py | 1 + .../post/parameters/parameter_18/schema.py | 1 + .../post/parameters/parameter_2/schema.py | 1 + .../post/parameters/parameter_3/schema.py | 1 + .../post/parameters/parameter_4/schema.py | 1 + .../post/parameters/parameter_5/schema.py | 1 + .../post/parameters/parameter_6/schema.py | 1 + .../post/parameters/parameter_7/schema.py | 1 + .../post/parameters/parameter_8/schema.py | 1 + .../post/parameters/parameter_9/schema.py | 1 + .../content/application_json/schema.py | 1 + .../content/application_json/schema.py | 1 + .../post/parameters/parameter_0/schema.py | 1 + .../content/multipart_form_data/schema.py | 59 +- .../content/application_json/schema.py | 1 + .../content/application_json/schema.py | 1 + .../put/parameters/parameter_0/schema.py | 14 +- .../put/parameters/parameter_1/schema.py | 14 +- .../put/parameters/parameter_2/schema.py | 14 +- .../put/parameters/parameter_3/schema.py | 14 +- .../put/parameters/parameter_4/schema.py | 14 +- .../application_octet_stream/schema.py | 1 + .../application_octet_stream/schema.py | 1 + .../content/multipart_form_data/schema.py | 59 +- .../content/multipart_form_data/schema.py | 118 +- .../content/application_json/schema.py | 1 + .../content/application_json/schema.py | 1 + .../content/application_json/schema.py | 1 + .../content/application_json/schema.py | 1 + .../content/application_json/schema.py | 1 + .../content/application_json/schema.py | 1 + .../content/application_json/schema.py | 43 +- .../paths/foo/get/servers/server_0.py | 4 +- .../paths/foo/get/servers/server_1.py | 128 +- .../get/parameters/parameter_0/schema.py | 73 +- .../pet_find_by_status/servers/server_0.py | 4 +- .../pet_find_by_status/servers/server_1.py | 128 +- .../get/parameters/parameter_0/schema.py | 14 +- .../delete/parameters/parameter_0/schema.py | 1 + .../delete/parameters/parameter_1/schema.py | 1 + .../get/parameters/parameter_0/schema.py | 1 + .../post/parameters/parameter_0/schema.py | 1 + .../schema.py | 53 +- .../post/parameters/parameter_0/schema.py | 1 + .../content/multipart_form_data/schema.py | 53 +- .../delete/parameters/parameter_0/schema.py | 1 + .../get/parameters/parameter_0/schema.py | 14 +- .../get/parameters/parameter_0/schema.py | 1 + .../get/parameters/parameter_1/schema.py | 1 + .../content/application_json/schema.py | 1 + .../content/application_xml/schema.py | 1 + .../headers/header_x_expires_after/schema.py | 1 + .../content/application_json/schema.py | 1 + .../python/src/petstore_api/schemas.py | 380 ++-- .../python/src/petstore_api/server.py | 25 +- .../src/petstore_api/servers/server_0.py | 196 +- .../src/petstore_api/servers/server_1.py | 128 +- .../src/petstore_api/servers/server_2.py | 4 +- .../shared_imports/schema_imports.py | 1 + .../test_additional_properties_validator.py | 4 +- .../python/tests_manual/test_animal.py | 20 +- .../tests_manual/test_any_type_schema.py | 108 +- .../python/tests_manual/test_configuration.py | 8 +- .../python/tests_manual/test_mammal.py | 2 +- .../test_obj_with_required_props.py | 12 +- ...ject_model_with_arg_and_args_properties.py | 9 +- .../test_object_model_with_ref_props.py | 10 +- ...object_with_inline_composition_property.py | 8 +- .../python/tests_manual/test_validate.py | 101 +- 409 files changed, 13691 insertions(+), 18415 deletions(-) create mode 100644 modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/model/ArrayListWithContext.java create mode 100644 modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/model/InlineContext.java create mode 100644 modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/model/LinkedHashMapWithContext.java create mode 100644 modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_allof_type.hbs create mode 100644 modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_anyof_type.hbs create mode 100644 modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_getschemas.hbs create mode 100644 modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_oneof_type.hbs create mode 100644 modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_properties_type.hbs delete mode 100644 modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_types_all_incl_schema_newline.hbs diff --git a/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/CodegenConfig.java b/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/CodegenConfig.java index 47f98400c6a..f045f54fe52 100644 --- a/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/CodegenConfig.java +++ b/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/CodegenConfig.java @@ -144,7 +144,7 @@ public interface CodegenConfig { CodegenOperation fromOperation(Operation operation, String jsonPath); - CodegenKey getKey(String key); + CodegenKey getKey(String key, String keyType); CodegenSecurityScheme fromSecurityScheme(SecurityScheme securityScheme, String jsonPath); @@ -156,7 +156,7 @@ public interface CodegenConfig { List fromServers(List servers, String jsonPath); - HashMap fromServerVariables(Map variables, String jsonPath); + CodegenSchema fromServerVariables(Map variables, String jsonPath); Map typeMapping(); diff --git a/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/DefaultCodegen.java b/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/DefaultCodegen.java index 06d4a8119f0..b2b3a53092a 100644 --- a/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/DefaultCodegen.java +++ b/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/DefaultCodegen.java @@ -43,6 +43,7 @@ import org.openapijsonschematools.codegen.meta.features.SchemaFeature; import org.openapijsonschematools.codegen.meta.features.SecurityFeature; import org.openapijsonschematools.codegen.meta.features.WireFormatFeature; +import org.openapijsonschematools.codegen.model.ArrayListWithContext; import org.openapijsonschematools.codegen.model.CodegenDiscriminator; import org.openapijsonschematools.codegen.model.CodegenEncoding; import org.openapijsonschematools.codegen.model.CodegenHeader; @@ -64,6 +65,7 @@ import org.openapijsonschematools.codegen.model.CodegenTag; import org.openapijsonschematools.codegen.model.CodegenXml; import org.openapijsonschematools.codegen.model.EnumValue; +import org.openapijsonschematools.codegen.model.LinkedHashMapWithContext; import org.openapijsonschematools.codegen.model.PairCacheKey; import org.openapijsonschematools.codegen.model.SchemaTestCase; import org.openapijsonschematools.codegen.serializer.SerializerUtils; @@ -487,7 +489,7 @@ protected Map getModelNameToSchemaCache() { if (modelNameToSchemaCache == null) { // Create a cache to efficiently lookup schema based on model name. Map m = new HashMap<>(); - ModelUtils.getSchemas(openAPI).forEach((key, schema) -> m.put(toModelName(key, null), schema)); + ModelUtils.getSchemas(openAPI).forEach((key, schema) -> m.put(toModelName(key, "#/components/schemas/"+key), schema)); modelNameToSchemaCache = Collections.unmodifiableMap(m); } return modelNameToSchemaCache; @@ -1556,6 +1558,7 @@ public String toModelName(final String name, String jsonPath) { Map codegenSecurityRequirementCache = new HashMap<>(); Map codegenParameterCache = new HashMap<>(); + HashMap> sourceJsonPathToKeyToQty = new HashMap<>(); Map codegenTagCache = new HashMap<>(); private final CodegenSchema requiredAddPropUnsetSchema = fromSchema(new Schema(), null, null); @@ -1998,7 +2001,7 @@ protected CodegenDiscriminator createDiscriminator(String schemaName, Schema sch return null; } String discPropName = sourceDiscriminator.getPropertyName(); - CodegenKey propertyName = getKey(discPropName); + CodegenKey propertyName = getKey(discPropName, "misc"); Map mapping = sourceDiscriminator.getMapping(); TreeSet mappedModels = new TreeSet<>(); @@ -2208,9 +2211,9 @@ public CodegenSchema fromSchema(Schema p, String sourceJsonPath, String currentJ PairCacheKey ck = new PairCacheKey(sourceJsonPath, currentJsonPath); CodegenSchema property = codegenSchemaCache.computeIfAbsent(ck, s -> new CodegenSchema()); + property.instanceType = "schema"; String ref = p.get$ref(); - setSchemaLocationInfo(ref, sourceJsonPath, currentJsonPath, property); // put toExampleValue in a try-catch block to log the error as example values are not critical try { property.example = toExampleValue(p); @@ -2220,6 +2223,7 @@ public CodegenSchema fromSchema(Schema p, String sourceJsonPath, String currentJ property.example = "ERROR_TO_EXAMPLE_VALUE"; } if (ref != null) { + setSchemaLocationInfo(ref, sourceJsonPath, currentJsonPath, property); if (addSchemaImportsFromV3SpecLocations && sourceJsonPath != null && sourceJsonPath.equals(currentJsonPath)) { // import from $ref property.imports = new TreeSet<>(); @@ -2243,6 +2247,47 @@ public CodegenSchema fromSchema(Schema p, String sourceJsonPath, String currentJ property.format = p.getFormat(); property.externalDocumentation = p.getExternalDocs(); + /* + Order of assigning properties must reverse the order in + CodegenSchema.getSchemaa + so that jsonPathPiece.camelCase names can be assigned correctly + with the root schema having an unmodified jsonPathPiece.className + --> + (self) + properties + oneOf + not + items + anyOf + allOf + additionalProperties + */ + setSchemaLocationInfo(null, sourceJsonPath, currentJsonPath, property); + HashMap requiredAndOptionalProperties = new HashMap<>(); + property.properties = getProperties(((Schema) p).getProperties(), sourceJsonPath, currentJsonPath, requiredAndOptionalProperties); + List oneOfs = ((Schema) p).getOneOf(); + if (oneOfs != null && !oneOfs.isEmpty()) { + property.oneOf = getComposedProperties(oneOfs, "oneOf", sourceJsonPath, currentJsonPath); + } + Schema notSchema = p.getNot(); + if (notSchema != null) { + property.not = fromSchema(notSchema, sourceJsonPath, currentJsonPath + "/not"); + } + if (p.getItems() != null) { + property.items = fromSchema( + p.getItems(), sourceJsonPath, currentJsonPath + "/items"); + } + List anyOfs = ((Schema) p).getAnyOf(); + if (anyOfs != null && !anyOfs.isEmpty()) { + property.anyOf = getComposedProperties(anyOfs, "anyOf", sourceJsonPath, currentJsonPath); + } + List allOfs = ((Schema) p).getAllOf(); + if (allOfs != null && !allOfs.isEmpty()) { + property.allOf = getComposedProperties(allOfs, "allOf", sourceJsonPath, currentJsonPath); + } + property.additionalProperties = getAdditionalProperties(p, sourceJsonPath, currentJsonPath); + // end of properties that need to be ordered to set correct camelCase jsonPathPieces + if (currentJsonPath != null) { String[] pathPieces = currentJsonPath.split("/"); if (pathPieces.length >= 4) { @@ -2258,12 +2303,9 @@ public CodegenSchema fromSchema(Schema p, String sourceJsonPath, String currentJ property.schemaIsFromAdditionalProperties = true; } } - } else { + } else if (currentJsonPath.startsWith("#/components/schemas/")) { // component schema use case - // TODO set discriminator on any schema instances in the future not just these - if (!currentJsonPath.startsWith("#/components/schemas/")) { - throw new RuntimeException("Invalid currentJsonPath "+ currentJsonPath); - } + // TODO set discriminator on any schema instances in the future not just component schemas property.discriminator = createDiscriminator(usedName, p, this.openAPI, currentJsonPath); if (p instanceof ComposedSchema) { @@ -2302,22 +2344,6 @@ public CodegenSchema fromSchema(Schema p, String sourceJsonPath, String currentJ property.vendorExtensions = ((Schema) p).getExtensions(); } - Schema notSchema = p.getNot(); - if (notSchema != null) { - property.not = fromSchema(notSchema, sourceJsonPath, currentJsonPath + "/not"); - } - List allOfs = ((Schema) p).getAllOf(); - if (allOfs != null && !allOfs.isEmpty()) { - property.allOf = getComposedProperties(allOfs, "allOf", sourceJsonPath, currentJsonPath); - } - List anyOfs = ((Schema) p).getAnyOf(); - if (anyOfs != null && !anyOfs.isEmpty()) { - property.anyOf = getComposedProperties(anyOfs, "anyOf", sourceJsonPath, currentJsonPath); - } - List oneOfs = ((Schema) p).getOneOf(); - if (oneOfs != null && !oneOfs.isEmpty()) { - property.oneOf = getComposedProperties(oneOfs, "oneOf", sourceJsonPath, currentJsonPath); - } if (ModelUtils.isAnyType(p)) { // The 'null' value is allowed when the OAS schema is 'any type'. // See https://github.com/OAI/OpenAPI-Specification/issues/1389 @@ -2326,17 +2352,10 @@ public CodegenSchema fromSchema(Schema p, String sourceJsonPath, String currentJ } } property.patternInfo = getPatternInfo(p.getPattern()); - // handle inner property - if (p.getItems() != null) { - property.items = fromSchema( - p.getItems(), sourceJsonPath, currentJsonPath + "/items"); - } - property.additionalProperties = getAdditionalProperties(p, sourceJsonPath, currentJsonPath); - property.properties = getProperties(((Schema) p).getProperties(), sourceJsonPath, currentJsonPath); LinkedHashSet required = p.getRequired() == null ? new LinkedHashSet<>() : new LinkedHashSet<>(((Schema) p).getRequired()); property.optionalProperties = getOptionalProperties(property.properties, required); - property.requiredProperties = getRequiredProperties(required, property.properties, p.getAdditionalProperties(), property.additionalProperties); + property.requiredProperties = getRequiredProperties(required, property.properties, property.additionalProperties, requiredAndOptionalProperties); property.example = toExampleValue(p); if (addSchemaImportsFromV3SpecLocations && sourceJsonPath != null && sourceJsonPath.equals(currentJsonPath)) { @@ -2618,7 +2637,7 @@ else if (one.required) List> security = fromSecurity(operation.getSecurity(), jsonPath + "/security"); ExternalDocumentation externalDocs = operation.getExternalDocs(); - CodegenKey jsonPathPiece = getKey(pathPieces[pathPieces.length-1]); + CodegenKey jsonPathPiece = getKey(pathPieces[pathPieces.length-1], "verb"); return new CodegenOperation( deprecated, hasErrorResponseObject, @@ -2714,13 +2733,10 @@ public CodegenResponse fromResponse(ApiResponse response, String sourceJsonPath) imports = new TreeSet<>(); imports.add(getImport(refInfo)); } - CodegenKey jsonPathPiece = getJsonPathPiece(expectedComponentType, sourceJsonPath); + CodegenKey jsonPathPiece = getJsonPathPiece(expectedComponentType, sourceJsonPath, sourceJsonPath); String[] pathPieces = sourceJsonPath.split("/"); // #/components/responses/A - boolean componentModule = false; - if (pathPieces.length == 4 && sourceJsonPath.startsWith("#/components/"+expectedComponentType+"/")) { - componentModule = true; - } + boolean componentModule = pathPieces.length == 4 && sourceJsonPath.startsWith("#/components/" + expectedComponentType + "/"); Map finalHeaders = headers; Map finalVendorExtensions = vendorExtensions; @@ -2823,13 +2839,10 @@ public CodegenHeader fromHeader(Header header, String sourceJsonPath) { imports = new TreeSet<>(); imports.add(getImport(refInfo)); } - CodegenKey jsonPathPiece = getJsonPathPiece(expectedComponentType, sourceJsonPath); + CodegenKey jsonPathPiece = getJsonPathPiece(expectedComponentType, sourceJsonPath, sourceJsonPath); String[] pathPieces = sourceJsonPath.split("/"); // #/components/headers/A - boolean componentModule = false; - if (pathPieces.length == 4 && sourceJsonPath.startsWith("#/components/"+expectedComponentType+"/")) { - componentModule = true; - } + boolean componentModule = pathPieces.length == 4 && sourceJsonPath.startsWith("#/components/" + expectedComponentType + "/"); String description = escapeText(header.getDescription()); String unescapedDescription = header.getDescription(); @@ -2907,13 +2920,10 @@ public CodegenParameter fromParameter(Parameter parameter, String sourceJsonPath imports = new TreeSet<>(); imports.add(getImport(refInfo)); } - CodegenKey jsonPathPiece = getJsonPathPiece(expectedComponentType, sourceJsonPath); + CodegenKey jsonPathPiece = getJsonPathPiece(expectedComponentType, sourceJsonPath, sourceJsonPath); String[] pathPieces = sourceJsonPath.split("/"); // #/components/parameters/A - boolean componentModule = false; - if (pathPieces.length == 4 && sourceJsonPath.startsWith("#/components/"+expectedComponentType+"/")) { - componentModule = true; - } + boolean componentModule = pathPieces.length == 4 && sourceJsonPath.startsWith("#/components/" + expectedComponentType + "/"); String description = escapeText(parameter.getDescription()); String unescapedDescription = parameter.getDescription(); @@ -3099,13 +3109,10 @@ public CodegenSecurityScheme fromSecurityScheme(SecurityScheme securityScheme, S flowsVendorExtensions ); } - CodegenKey jsonPathPiece = getJsonPathPiece(expectedComponentType, jsonPath); + CodegenKey jsonPathPiece = getJsonPathPiece(expectedComponentType, jsonPath, jsonPath); String[] pathPieces = jsonPath.split("/"); // #/components/requestBodies/A - boolean componentModule = false; - if (pathPieces.length == 4 && jsonPath.startsWith("#/components/"+expectedComponentType+"/")) { - componentModule = true; - } + boolean componentModule = pathPieces.length == 4 && jsonPath.startsWith("#/components/" + expectedComponentType + "/"); String type = securityScheme.getType().toString(); String description = securityScheme.getDescription(); @@ -3249,28 +3256,35 @@ protected boolean shouldAddImport(String type) { * @param currentJsonPath the current json path * @return the properties */ - protected LinkedHashMap getProperties(Map properties, String sourceJsonPath, String currentJsonPath) { + protected LinkedHashMapWithContext getProperties(Map properties, String sourceJsonPath, String currentJsonPath, HashMap requiredAndOptionalProperties) { if (properties == null || properties.isEmpty()) { return null; } - LinkedHashMap propertiesMap = new LinkedHashMap<>(); + LinkedHashMapWithContext propertiesMap = new LinkedHashMapWithContext<>(); + boolean allAreInline = true; for (Map.Entry entry : properties.entrySet()) { final String propertyName = entry.getKey(); final Schema prop = entry.getValue(); if (prop == null) { LOGGER.warn("Please report the issue. There shouldn't be null property for {}", propertyName); } else { + if (prop.get$ref() != null) { + allAreInline = false; + } final CodegenSchema cp; String propertyJsonPath = currentJsonPath + "/properties/" + ModelUtils.encodeSlashes(propertyName); cp = fromSchema(prop, sourceJsonPath, propertyJsonPath); + requiredAndOptionalProperties.put(propertyName, cp.jsonPathPiece); - CodegenKey key = getKey(propertyName); - propertiesMap.put(key, cp); + propertiesMap.put(cp.jsonPathPiece, cp); } } + propertiesMap.setAllAreInline(allAreInline); + CodegenKey jsonPathPiece = getKey("properties", "schemaProperty", sourceJsonPath); + propertiesMap.setJsonPathPiece(jsonPathPiece); return propertiesMap; } @@ -3278,24 +3292,24 @@ protected LinkedHashMap getProperties(Map getOptionalProperties(LinkedHashMap properties, Set mandatory) { + protected LinkedHashMap getOptionalProperties(LinkedHashMap properties, Set required) { if (properties == null) { return null; } - if (mandatory.size() == properties.size()) { + if (required.size() == properties.size()) { return null; } - if (mandatory.isEmpty()) { + if (required.isEmpty()) { return properties; } LinkedHashMap optionalProperties = new LinkedHashMap<>(); for (Map.Entry entry : properties.entrySet()) { final CodegenKey key = entry.getKey(); - if (mandatory.contains(key.original)) { + if (required.contains(key.original)) { continue; } final CodegenSchema prop = entry.getValue(); @@ -3350,7 +3364,7 @@ private void updateComponentsFilepath(String[] pathPieces) { pathPieces[2] = null; if (pathPieces.length == 4) { // #/components/schemas/SomeSchema - pathPieces[3] = getKey(pathPieces[3]).snakeCase; + pathPieces[3] = getKey(pathPieces[3], "schemas").snakeCase; } return; } else if (pathPieces[2].equals("requestBodies")) { @@ -3366,21 +3380,21 @@ private void updateComponentsFilepath(String[] pathPieces) { if (pathPieces.length >= 6 && pathPieces[4].equals("content")) { // #/components/headers/someHeader/content/application-json -> length 6 String contentType = ModelUtils.decodeSlashes(pathPieces[5]); - pathPieces[5] = getKey(contentType).snakeCase; + pathPieces[5] = toModelFilename(contentType, null); } } else if (pathPieces[2].equals("parameters")) { pathPieces[3] = toParameterFilename(pathPieces[3], null); if (pathPieces.length >= 6 && pathPieces[4].equals("content")) { // #/components/parameters/someParam/content/application-json -> length 6 String contentType = ModelUtils.decodeSlashes(pathPieces[5]); - pathPieces[5] = getKey(contentType).snakeCase; + pathPieces[5] = toModelFilename(contentType, null); } } else if (pathPieces[2].equals(requestBodiesIdentifier)) { pathPieces[3] = toRequestBodyFilename(pathPieces[3]); if (pathPieces.length >= 6 && pathPieces[4].equals("content")) { // #/components/requestBodies/someBody/content/application-json -> length 6 String contentType = ModelUtils.decodeSlashes(pathPieces[5]); - pathPieces[5] = getKey(contentType).snakeCase; + pathPieces[5] = toModelFilename(contentType, null); } } else if (pathPieces[2].equals("responses")) { // #/components/responses/SuccessWithJsonApiResponse/headers @@ -3396,12 +3410,12 @@ private void updateComponentsFilepath(String[] pathPieces) { if (pathPieces.length >= 8 && pathPieces[6].equals("content")) { // #/components/responses/someResponse/headers/SomeHeader/content/application-json -> length 8 String contentType = ModelUtils.decodeSlashes(pathPieces[7]); - pathPieces[7] = getKey(contentType).snakeCase; + pathPieces[7] = toModelFilename(contentType, null); } } else if (pathPieces[4].equals("content")) { // #/components/responses/someResponse/content/application-json -> length 6 String contentType = ModelUtils.decodeSlashes(pathPieces[5]); - pathPieces[5] = getKey(contentType).snakeCase; + pathPieces[5] = toModelFilename(contentType, null); } } else if (pathPieces[2].equals(securitySchemesIdentifier)) { pathPieces[3] = toSecuritySchemeFilename(pathPieces[3], null); @@ -3449,7 +3463,7 @@ private void updatePathsFilepath(String[] pathPieces) { if (pathPieces[6].equals("content")) { // #/paths/somePath/get/responses/200/content/application-json -> length 8 String contentType = ModelUtils.decodeSlashes(pathPieces[7]); - pathPieces[7] = getKey(contentType).snakeCase; + pathPieces[7] = toModelFilename(contentType, null); } else if (pathPieces[6].equals("headers")) { // #/paths/somePath/get/responses/200/headers/someHeader -> length 8 pathPieces[7] = toHeaderFilename(pathPieces[7], null); @@ -3457,7 +3471,7 @@ private void updatePathsFilepath(String[] pathPieces) { if (pathPieces.length >= 10 && pathPieces[8].equals("content")) { // #/paths/somePath/get/responses/200/headers/someHeader/content/application-json -> length 10 String contentType = ModelUtils.decodeSlashes(pathPieces[9]); - pathPieces[9] = getKey(contentType).snakeCase; + pathPieces[9] = toModelFilename(contentType, null); } } } else if (pathPieces[4].equals("parameters")) { @@ -3467,13 +3481,13 @@ private void updatePathsFilepath(String[] pathPieces) { if (pathPieces.length >= 8 && pathPieces[6].equals("content")) { // #/paths/somePath/get/parameters/1/content/application-json -> length 8 String contentType = ModelUtils.decodeSlashes(pathPieces[7]); - pathPieces[7] = getKey(contentType).snakeCase; + pathPieces[7] = toModelFilename(contentType, null); } } else if (pathPieces[4].equals(requestBodyIdentifier)) { if (pathPieces.length >= 7 && pathPieces[5].equals("content")) { // #/paths/somePath/get/requestBody/content/application-json -> length 7 String contentType = ModelUtils.decodeSlashes(pathPieces[6]); - pathPieces[6] = getKey(contentType).snakeCase; + pathPieces[6] = toModelFilename(contentType, null); } } } @@ -4132,7 +4146,7 @@ protected LinkedHashMap getContent(Content content } CodegenMediaType codegenMt = new CodegenMediaType(schemaProp, ceMap, schemaTestCases); - CodegenKey ck = getKey(contentType); + CodegenKey ck = getKey(contentType, "misc"); cmtContent.put(ck, codegenMt); } return cmtContent; @@ -4175,21 +4189,24 @@ protected String toRefModule(String ref, String sourceJsonPath, String expectedC // property is of type self return null; } - return getKey(refPieces[3]).snakeCase; + String usedKey = handleSpecialCharacters(refPieces[3]); + return toModelFilename(usedKey, ref); case "securitySchemes": return toSecuritySchemeFilename(refPieces[3], ref); } return null; } - private CodegenKey getJsonPathPiece(String expectedComponentType, String currentJsonPath) { + private CodegenKey getJsonPathPiece(String expectedComponentType, String currentJsonPath, String sourceJsonPathPiece) { // last fragment info // requestBody -> requestBody // headers -> headerName // parameters/i -> i // components/parameters/someParam -> someParam + // components/securitySchemes/blah -> Blah + // schema names String usedName = currentJsonPath.substring(currentJsonPath.lastIndexOf("/") + 1); - return getKey(usedName, expectedComponentType, currentJsonPath); + return getKey(usedName, expectedComponentType, sourceJsonPathPiece); } private void setSchemaLocationInfo(String ref, String sourceJsonPath, String currentJsonPath, CodegenSchema instance) { @@ -4204,7 +4221,7 @@ private void setSchemaLocationInfo(String ref, String sourceJsonPath, String cur if (currentJsonPath == null) { return; } - instance.jsonPathPiece = getJsonPathPiece(expectedComponentType, currentJsonPath); + instance.jsonPathPiece = getJsonPathPiece(expectedComponentType, currentJsonPath, sourceJsonPath); String[] pathPieces = currentJsonPath.split("/"); // #/components/schemas/A if (pathPieces.length == 4 && currentJsonPath.startsWith("#/components/"+expectedComponentType+"/")) { @@ -4236,13 +4253,10 @@ public CodegenRequestBody fromRequestBody(RequestBody requestBody, String source imports = new TreeSet<>(); imports.add(getImport(refInfo)); } - CodegenKey jsonPathPiece = getJsonPathPiece(expectedComponentType, sourceJsonPath); + CodegenKey jsonPathPiece = getJsonPathPiece(expectedComponentType, sourceJsonPath, sourceJsonPath); String[] pathPieces = sourceJsonPath.split("/"); // #/components/requestBodies/A - boolean componentModule = false; - if (pathPieces.length == 4 && sourceJsonPath.startsWith("#/components/"+expectedComponentType+"/")) { - componentModule = true; - } + boolean componentModule = pathPieces.length == 4 && sourceJsonPath.startsWith("#/components/" + expectedComponentType + "/"); String description = escapeText(requestBody.getDescription()); String unescapedDescription = requestBody.getDescription(); @@ -4265,43 +4279,64 @@ public CodegenRequestBody fromRequestBody(RequestBody requestBody, String source return codegenRequestBody; } + @Override public CodegenKey getKey(String key, String expectedComponentType) { return getKey(key, expectedComponentType, null); } - public CodegenKey getKey(String key, String expectedComponentType, String jsonPath) { + public CodegenKey getKey(String key, String keyType, String sourceJsonPath) { String usedKey = handleSpecialCharacters(key); boolean isValid = isValid(usedKey); String snakeCaseName = null; String camelCaseName = null; String anchorPiece = null; - switch (expectedComponentType) { + switch (keyType) { + case "schemaProperty": case "schemas": - snakeCaseName = toModelFilename(usedKey, jsonPath); - camelCaseName = toModelName(usedKey, jsonPath); + String suffix = ""; + if (sourceJsonPath != null) { + HashMap keyToQty = sourceJsonPathToKeyToQty.getOrDefault(sourceJsonPath, new HashMap<>()); + if (!sourceJsonPathToKeyToQty.containsKey(sourceJsonPath)) { + sourceJsonPathToKeyToQty.put(sourceJsonPath, keyToQty); + } + Integer qty = keyToQty.getOrDefault(usedKey, 0); + qty += 1; + keyToQty.put(usedKey, qty); + if (qty > 1) { + suffix = qty.toString(); + } + } + snakeCaseName = toModelFilename(usedKey, sourceJsonPath); + camelCaseName = toModelName(usedKey + suffix, sourceJsonPath); + break; + case "misc": + case "paths": + case "verb": + snakeCaseName = toModelFilename(usedKey, sourceJsonPath); + camelCaseName = toModelName(usedKey, sourceJsonPath); break; case "parameters": - snakeCaseName = toParameterFilename(usedKey, jsonPath); + snakeCaseName = toParameterFilename(usedKey, sourceJsonPath); camelCaseName = getCamelCaseParameter(usedKey); break; case "requestBodies": snakeCaseName = toRequestBodyFilename(usedKey); - camelCaseName = toModelName(usedKey, jsonPath); + camelCaseName = toModelName(usedKey, sourceJsonPath); break; case "headers": - snakeCaseName = toHeaderFilename(usedKey, jsonPath); - camelCaseName = toModelName(usedKey, jsonPath); + snakeCaseName = toHeaderFilename(usedKey, sourceJsonPath); + camelCaseName = toModelName(usedKey, sourceJsonPath); break; case "responses": - snakeCaseName = toResponseModuleName(usedKey, jsonPath); + snakeCaseName = toResponseModuleName(usedKey, sourceJsonPath); camelCaseName = getCamelCaseResponse(usedKey); break; case "securitySchemes": - snakeCaseName = toSecuritySchemeFilename(usedKey, jsonPath); - camelCaseName = toModelName(usedKey, jsonPath); + snakeCaseName = toSecuritySchemeFilename(usedKey, sourceJsonPath); + camelCaseName = toModelName(usedKey, sourceJsonPath); break; case "servers": - snakeCaseName = toServerFilename(usedKey, jsonPath); + snakeCaseName = toServerFilename(usedKey, sourceJsonPath); camelCaseName = getCamelCaseServer(usedKey); break; } @@ -4317,22 +4352,7 @@ public CodegenKey getKey(String key, String expectedComponentType, String jsonPa ); } - @Override - public CodegenKey getKey(String key) { - String usedKey = handleSpecialCharacters(key); - boolean isValid = isValid(usedKey); - String camelCase = toModelName(usedKey, null); - String anchorPiece = camelCase.toLowerCase(Locale.ROOT); - return new CodegenKey( - usedKey, - isValid, - toModelFilename(usedKey, null), - camelCase, - anchorPiece - ); - } - - protected LinkedHashMap getRequiredProperties(LinkedHashSet required, LinkedHashMap properties, Object schemaAdditionalProperties, CodegenSchema additionalProperties) { + protected LinkedHashMap getRequiredProperties(LinkedHashSet required, LinkedHashMap properties, CodegenSchema additionalProperties, HashMap requiredAndOptionalProperties) { if (required.isEmpty()) { return null; } @@ -4346,8 +4366,8 @@ protected LinkedHashMap getRequiredProperties(LinkedH LinkedHashMap requiredProperties = new LinkedHashMap<>(); for (String requiredPropertyName: required) { // required property is defined in properties, value is that CodegenSchema - CodegenKey key = getKey(requiredPropertyName); - if (properties != null && properties.containsKey(key)) { + if (properties != null && requiredAndOptionalProperties.containsKey(requiredPropertyName)) { + CodegenKey key = requiredAndOptionalProperties.get(requiredPropertyName); // get cp from property CodegenSchema prop = properties.get(key); if (prop != null) { @@ -4355,26 +4375,29 @@ protected LinkedHashMap getRequiredProperties(LinkedH } else { throw new RuntimeException("Property " + requiredPropertyName + " is missing from getVars"); } - } else if (schemaAdditionalProperties instanceof Boolean && Boolean.FALSE.equals(schemaAdditionalProperties)) { + } else if (additionalProperties != null && additionalProperties.isBooleanSchemaFalse) { // required property is not defined in properties, and additionalProperties is false, value is null + CodegenKey key = getKey(requiredPropertyName, "schemas"); requiredProperties.put(key, null); + requiredAndOptionalProperties.put(requiredPropertyName, key); } else { - // required property is not defined in properties, and additionalProperties is true or unset value is CodegenSchema made from empty schema - // required property is not defined in properties, and additionalProperties is schema, value is CodegenSchema made from schema + // required property is not defined in properties if (supportsAdditionalPropertiesWithComposedSchema && !disallowAdditionalPropertiesIfNotPresent) { CodegenSchema prop; - if (schemaAdditionalProperties == null) { + if (additionalProperties == null) { // additionalProperties is null // there is NO schema definition for this so the json paths are null prop = requiredAddPropUnsetSchema; - } else if (schemaAdditionalProperties instanceof Boolean && Boolean.TRUE.equals(schemaAdditionalProperties)) { + } else if (additionalProperties.isBooleanSchemaTrue) { // additionalProperties is True prop = additionalProperties; } else { // additionalProperties is schema prop = additionalProperties; } + CodegenKey key = getKey(requiredPropertyName, "schemas"); requiredProperties.put(key, prop); + requiredAndOptionalProperties.put(requiredPropertyName, key); } } } @@ -4426,7 +4449,7 @@ public TreeMap fromPaths(Paths paths){ PathItem pathItem = entry.getValue(); String pathItemJsonPath = jsonPath + ModelUtils.encodeSlashes(path); CodegenPathItem codegenPathItem = fromPathItem(pathItem, pathItemJsonPath); - CodegenKey pathKey = getKey(path); + CodegenKey pathKey = getKey(path, "paths"); codegenPaths.put(pathKey, codegenPathItem); } // sort them @@ -4442,44 +4465,44 @@ public CodegenPathItem fromPathItem(PathItem pathItem, String jsonPath) { Operation specOperation = pathItem.getGet(); String httpMethod = "get"; if (specOperation != null) { - operations.put(getKey(httpMethod), fromOperation(specOperation, jsonPath + "/" + httpMethod)); + operations.put(getKey(httpMethod, "verb"), fromOperation(specOperation, jsonPath + "/" + httpMethod)); } specOperation = pathItem.getPut(); httpMethod = "put"; if (specOperation != null) { - operations.put(getKey(httpMethod), fromOperation(specOperation, jsonPath + "/" + httpMethod)); + operations.put(getKey(httpMethod, "verb"), fromOperation(specOperation, jsonPath + "/" + httpMethod)); } specOperation = pathItem.getPost(); httpMethod = "post"; if (specOperation != null) { - operations.put(getKey(httpMethod), fromOperation(specOperation, jsonPath + "/" + httpMethod)); + operations.put(getKey(httpMethod, "verb"), fromOperation(specOperation, jsonPath + "/" + httpMethod)); } specOperation = pathItem.getDelete(); httpMethod = "delete"; if (specOperation != null) { - operations.put(getKey(httpMethod), fromOperation(specOperation, jsonPath + "/" + httpMethod)); + operations.put(getKey(httpMethod, "verb"), fromOperation(specOperation, jsonPath + "/" + httpMethod)); } specOperation = pathItem.getOptions(); httpMethod = "options"; if (specOperation != null) { - operations.put(getKey(httpMethod), fromOperation(specOperation, jsonPath + "/" + httpMethod)); + operations.put(getKey(httpMethod, "verb"), fromOperation(specOperation, jsonPath + "/" + httpMethod)); } specOperation = pathItem.getHead(); httpMethod = "head"; if (specOperation != null) { - operations.put(getKey(httpMethod), fromOperation(specOperation, jsonPath + "/" + httpMethod)); + operations.put(getKey(httpMethod, "verb"), fromOperation(specOperation, jsonPath + "/" + httpMethod)); } specOperation = pathItem.getPatch(); httpMethod = "patch"; if (specOperation != null) { - operations.put(getKey(httpMethod), fromOperation(specOperation, jsonPath + "/" + httpMethod)); + operations.put(getKey(httpMethod, "verb"), fromOperation(specOperation, jsonPath + "/" + httpMethod)); } specOperation = pathItem.getTrace(); httpMethod = "trace"; if (specOperation != null) { - operations.put(getKey(httpMethod), fromOperation(specOperation, jsonPath + "/" + httpMethod)); + operations.put(getKey(httpMethod, "verb"), fromOperation(specOperation, jsonPath + "/" + httpMethod)); } - if (operations != null) + if (!operations.isEmpty()) // sort them operations = new TreeMap<>(operations); List specServers = pathItem.getServers(); @@ -4519,14 +4542,16 @@ public List fromServers(List servers, String jsonPath) { } @Override - public LinkedHashMap fromServerVariables(Map serverVariables, String jsonPath) { + public CodegenSchema fromServerVariables(Map serverVariables, String jsonPath) { if (serverVariables == null) { return null; } - LinkedHashMap variables = new LinkedHashMap<>(); + LinkedHashMap properties = new LinkedHashMap<>(); + ArrayList required = new ArrayList<>(); for (Entry entry: serverVariables.entrySet()) { String variableName = entry.getKey(); + required.add(variableName); ServerVariable variable = entry.getValue(); StringSchema schema = new StringSchema(); if (variable.getDescription() != null) { @@ -4536,12 +4561,14 @@ public LinkedHashMap fromServerVariables(Map getComposedProperties(List xOfCollection, String collectionName, String sourceJsonPath, String currentJsonPath) { + private ArrayListWithContext getComposedProperties(List xOfCollection, String collectionName, String sourceJsonPath, String currentJsonPath) { if (xOfCollection == null) { return null; } - List xOf = new ArrayList<>(); + ArrayListWithContext xOf = new ArrayListWithContext<>(); int i = 0; + boolean allAreInline = true; for (Schema xOfSchema : xOfCollection) { + if (xOfSchema.get$ref() != null) { + allAreInline = false; + } CodegenSchema cp = fromSchema(xOfSchema, sourceJsonPath, currentJsonPath + "/" + collectionName + "/" + i); xOf.add(cp); i += 1; } + xOf.setAllAreInline(allAreInline); + CodegenKey jsonPathPiece = getKey(collectionName, "schemaProperty"); + xOf.setJsonPathPiece(jsonPathPiece); return xOf; } diff --git a/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/languages/PythonClientCodegen.java b/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/languages/PythonClientCodegen.java index 4a9c627bd6e..f789a687c0d 100644 --- a/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/languages/PythonClientCodegen.java +++ b/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/languages/PythonClientCodegen.java @@ -765,8 +765,13 @@ public String toModuleFilename(String name, String jsonPath) { return underscore(dropDots(toModelName(name, jsonPath))); } + /* + This method requires jsonPath to be passed in + It handles responses and schemas + */ @Override public String toModelName(String name, String jsonPath) { + boolean rootEntity = (jsonPath != null && jsonPath.endsWith(name)); PairCacheKey key = new PairCacheKey(name, jsonPath); if (modelNameCache.containsKey(key)) { return modelNameCache.get(key); @@ -809,8 +814,8 @@ public String toModelName(String name, String jsonPath) { // model name cannot use reserved keyword, e.g. return if (isReservedWord(camelizedName)) { String modelName = "_" + camelizedName; // e.g. return => ModelReturn (after camelize) - if (isComponent) { - LOGGER.warn("{} (reserved word) cannot be used as component name. Renamed to {}", camelizedName, modelName); + if (isComponent && rootEntity) { + LOGGER.warn("{} (reserved word) cannot be used as name. Renamed to {}", camelizedName, modelName); } modelNameCache.put(key, modelName); return modelName; @@ -820,7 +825,7 @@ public String toModelName(String name, String jsonPath) { // model name starts with number if (camelizedName.matches("^\\d.*")) { String modelName = "_" + camelizedName; // e.g. return => ModelReturn (after camelize) - if (isComponent) { + if (isComponent && rootEntity) { LOGGER.warn("{} (component name starts with number) cannot be used as name. Renamed to {}", camelizedName, modelName); } modelNameCache.put(key, modelName); @@ -1356,7 +1361,7 @@ private String toExampleValueRecursive(String modelName, Schema schema, Object o String schemaName = getSchemaName(mm.modelName); Schema modelSchema = getModelNameToSchemaCache().get(schemaName); CodegenSchema cp = new CodegenSchema(); - cp.jsonPathPiece = getKey(disc.propertyName.original); + cp.jsonPathPiece = getKey(disc.propertyName.original, "misc"); cp.example = discPropNameValue; return exampleForObjectModel(modelSchema, fullPrefix, closeChars, cp, indentationLevel, exampleLine, closingIndentation, includedSchemas); } @@ -1523,7 +1528,7 @@ private String toExampleValueRecursive(String modelName, Schema schema, Object o String schemaName = getSchemaName(mm.modelName); Schema modelSchema = getModelNameToSchemaCache().get(schemaName); CodegenSchema cp = new CodegenSchema(); - cp.jsonPathPiece = getKey(disc.propertyName.original); + cp.jsonPathPiece = getKey(disc.propertyName.original, "misc"); cp.example = discPropNameValue; return exampleForObjectModel(modelSchema, fullPrefix, closeChars, cp, indentationLevel, exampleLine, closingIndentation, includedSchemas); } diff --git a/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/model/ArrayListWithContext.java b/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/model/ArrayListWithContext.java new file mode 100644 index 00000000000..3445a12d3e8 --- /dev/null +++ b/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/model/ArrayListWithContext.java @@ -0,0 +1,26 @@ +package org.openapijsonschematools.codegen.model; + +import java.util.ArrayList; + +/** + * A class to store inline codegenschema definitions + */ +public class ArrayListWithContext extends ArrayList implements InlineContext { + private boolean internalallAreInline = false; + private CodegenKey internalJsonPathPiece = null; + public boolean allAreInline() { + return internalallAreInline; + } + + public void setAllAreInline(boolean allAreInline) { + this.internalallAreInline = allAreInline; + } + + public CodegenKey jsonPathPiece() { + return internalJsonPathPiece; + } + + public void setJsonPathPiece(CodegenKey jsonPathPiece) { + this.internalJsonPathPiece = jsonPathPiece; + } +} diff --git a/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/model/CodegenKey.java b/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/model/CodegenKey.java index ce0d460ae62..fdaee566130 100644 --- a/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/model/CodegenKey.java +++ b/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/model/CodegenKey.java @@ -29,6 +29,18 @@ public boolean equals(Object o) { Objects.equals(anchorPiece, that.anchorPiece); } + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("CodegenKey{"); + sb.append("original=").append(original); + sb.append(", isValid=").append(isValid); + sb.append(", snakeCase=").append(snakeCase); + sb.append(", camelCase=").append(camelCase); + sb.append(", anchorPiece=").append(anchorPiece); + sb.append('}'); + return sb.toString(); + } + @Override public int hashCode() { return Objects.hash(original, isValid, snakeCase, camelCase, anchorPiece); diff --git a/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/model/CodegenSchema.java b/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/model/CodegenSchema.java index e1ee503fe62..73abe3441cd 100644 --- a/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/model/CodegenSchema.java +++ b/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/model/CodegenSchema.java @@ -19,6 +19,7 @@ import io.swagger.v3.oas.models.ExternalDocumentation; +import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.LinkedHashSet; @@ -46,12 +47,12 @@ public class CodegenSchema { public LinkedHashMap requiredProperties; // used to store required info public LinkedHashMap enumValueToName; // enum info public String type; - public List allOf = null; - public List anyOf = null; - public List oneOf = null; + public ArrayListWithContext allOf = null; + public ArrayListWithContext anyOf = null; + public ArrayListWithContext oneOf = null; public CodegenSchema not = null; public CodegenSchema items; - public LinkedHashMap properties; + public LinkedHashMapWithContext properties; public CodegenSchema additionalProperties; public String description; public String format; @@ -86,6 +87,12 @@ public class CodegenSchema { public LinkedHashMap optionalProperties; public boolean schemaIsFromAdditionalProperties; public HashMap testCases = new HashMap<>(); + /** + * schema/allOfType/anyOfType/oneOfType/propertiesType/importsType + * used in getAllSchemas to write type definitions for allOfType/anyOfType/oneOfType/propertiesType + */ + public String instanceType; + private ArrayList allSchemas = null; public boolean hasValidation() { return maxItems != null || minItems != null || minProperties != null || maxProperties != null || minLength != null || maxLength != null || multipleOf != null || patternInfo != null || minimum != null || maximum != null || exclusiveMinimum != null || exclusiveMaximum != null || uniqueItems != null; @@ -126,6 +133,118 @@ public CodegenSchema getSelfOrDeepestRef() { return refObject; } + /** + * Returns all schemas in post order traversal, used by templates to write schema classes + * @param schemasBeforeImports the input list that stores this and all required schemas + * @return the list that stores this and all required schemas + */ + private void getAllSchemas(ArrayList schemasBeforeImports, ArrayList schemasAfterImports, int level) { + /* + post order traversal using alphabetic json schema keywords as the order + keywords with schemas: + additionalProperties + allOf + anyOf + items + not + oneOf + properties + (self) + + excluded: + discriminator (not actually applicable because all values would be refs and do not need to be defined) + $ref (because it is an import) + */ + if (isBooleanSchemaFalse) { + // return early for isBooleanSchemaFalse so not_ will not be written + schemasBeforeImports.add(this); + return; + } + if (additionalProperties != null) { + additionalProperties.getAllSchemas(schemasBeforeImports, schemasAfterImports, level + 1); + } + if (allOf != null) { + for (CodegenSchema someSchema: allOf) { + someSchema.getAllSchemas(schemasBeforeImports, schemasAfterImports, level + 1); + } + CodegenSchema extraSchema = new CodegenSchema(); + extraSchema.instanceType = "allOfType"; + extraSchema.allOf = allOf; + if (allOf.allAreInline()) { + schemasBeforeImports.add(extraSchema); + } else { + schemasAfterImports.add(extraSchema); + } + } + if (anyOf != null) { + for (CodegenSchema someSchema: anyOf) { + someSchema.getAllSchemas(schemasBeforeImports, schemasAfterImports,level + 1); + } + CodegenSchema extraSchema = new CodegenSchema(); + extraSchema.instanceType = "anyOfType"; + extraSchema.anyOf = anyOf; + if (anyOf.allAreInline()) { + schemasBeforeImports.add(extraSchema); + } else { + schemasAfterImports.add(extraSchema); + } + } + if (items != null) { + items.getAllSchemas(schemasBeforeImports, schemasAfterImports, level + 1); + } + if (not != null) { + not.getAllSchemas(schemasBeforeImports, schemasAfterImports, level + 1); + } + if (oneOf != null) { + for (CodegenSchema someSchema: oneOf) { + someSchema.getAllSchemas(schemasBeforeImports, schemasAfterImports, level + 1); + } + CodegenSchema extraSchema = new CodegenSchema(); + extraSchema.instanceType = "oneOfType"; + extraSchema.oneOf = oneOf; + if (oneOf.allAreInline()) { + schemasBeforeImports.add(extraSchema); + } else { + schemasAfterImports.add(extraSchema); + } + } + if (properties != null) { + for (CodegenSchema someSchema: properties.values()) { + someSchema.getAllSchemas(schemasBeforeImports, schemasAfterImports, level + 1); + } + CodegenSchema extraSchema = new CodegenSchema(); + extraSchema.instanceType = "propertiesType"; + extraSchema.properties = properties; + if (properties.allAreInline()) { + schemasBeforeImports.add(extraSchema); + } else { + schemasAfterImports.add(extraSchema); + } + } + if (refInfo != null && level > 0) { + // do not add ref to schemas + return; + } + schemasBeforeImports.add(this); + if (level == 0 && imports != null && !imports.isEmpty()) { + CodegenSchema extraSchema = new CodegenSchema(); + extraSchema.instanceType = "importsType"; + extraSchema.imports = imports; + schemasBeforeImports.add(extraSchema); + } + } + + public ArrayList getSchemas() { + if (allSchemas == null) { + ArrayList schemasBeforeImports = new ArrayList<>(); + ArrayList schemasAfterImports = new ArrayList<>(); + getAllSchemas(schemasBeforeImports, schemasAfterImports, 0); + schemasBeforeImports.addAll(schemasAfterImports); + allSchemas = schemasBeforeImports; + } + return allSchemas; + } + public boolean isComplicated() { // used by templates @@ -137,7 +256,7 @@ public boolean isComplicated() { protected void addInstanceInfo(StringBuilder sb) { sb.append(", description='").append(description).append('\''); - sb.append(", name='").append(jsonPathPiece).append('\''); + sb.append(", jsonPathPiece='").append(jsonPathPiece).append('\''); sb.append(", defaultValue='").append(defaultValue).append('\''); sb.append(", title='").append(title).append('\''); sb.append(", unescapedDescription='").append(unescapedDescription).append('\''); @@ -186,6 +305,7 @@ protected void addInstanceInfo(StringBuilder sb) { sb.append(", imports=").append(imports); sb.append(", componentModule=").append(componentModule); sb.append(", testCases=").append(testCases); + sb.append(", instanceType=").append(instanceType); } @Override diff --git a/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/model/CodegenServer.java b/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/model/CodegenServer.java index bb738454c82..47ccd98eaf0 100644 --- a/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/model/CodegenServer.java +++ b/modules/openapi-json-schema-generator/src/main/java/org/openapijsonschematools/codegen/model/CodegenServer.java @@ -7,11 +7,11 @@ public class CodegenServer { public final String url; public final String defaultUrl; public final String description; - public final LinkedHashMap variables; + public final CodegenSchema variables; public final CodegenKey jsonPathPiece; public final boolean rootServer; - public CodegenServer(String url, String description, LinkedHashMap variables, CodegenKey jsonPathPiece, boolean rootServer) { + public CodegenServer(String url, String description, CodegenSchema variables, CodegenKey jsonPathPiece, boolean rootServer) { this.url = url; this.description = description; this.variables = variables; @@ -21,7 +21,7 @@ public CodegenServer(String url, String description, LinkedHashMap extends LinkedHashMap implements InlineContext { + private boolean internalallAreInline = false; + private CodegenKey internalJsonPathPiece = null; + public boolean allAreInline() { + return internalallAreInline; + } + + public void setAllAreInline(boolean allAreInline) { + this.internalallAreInline = allAreInline; + } + + public CodegenKey jsonPathPiece() { + return internalJsonPathPiece; + } + + public void setJsonPathPiece(CodegenKey jsonPathPiece) { + this.internalJsonPathPiece = jsonPathPiece; + } +} diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/_helper_types_all_incl_schema.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/_helper_types_all_incl_schema.hbs index a4bb03bfb60..50a4fc35002 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/_helper_types_all_incl_schema.hbs +++ b/modules/openapi-json-schema-generator/src/main/resources/python/_helper_types_all_incl_schema.hbs @@ -14,4 +14,4 @@ None, bytes, io.FileIO, io.BufferedReader, -'Schema', \ No newline at end of file +'Schema', diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_allof_type.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_allof_type.hbs new file mode 100644 index 00000000000..a4e2f2a50d6 --- /dev/null +++ b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_allof_type.hbs @@ -0,0 +1,9 @@ +{{allOf.jsonPathPiece.camelCase}} = typing.Tuple[ + {{#each allOf}} + {{#if refInfo.refClass}} + typing.Type[{{#if refInfo.refModule}}{{refInfo.refModule}}.{{/if}}{{refInfo.refClass}}], + {{else}} + typing.Type[{{jsonPathPiece.camelCase}}[schemas.U]], + {{/if}} + {{/each}} +] diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_anyof_type.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_anyof_type.hbs new file mode 100644 index 00000000000..7c945d05449 --- /dev/null +++ b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_anyof_type.hbs @@ -0,0 +1,9 @@ +{{anyOf.jsonPathPiece.camelCase}} = typing.Tuple[ + {{#each anyOf}} + {{#if refInfo.refClass}} + typing.Type[{{#if refInfo.refModule}}{{refInfo.refModule}}.{{/if}}{{refInfo.refClass}}], + {{else}} + typing.Type[{{jsonPathPiece.camelCase}}[schemas.U]], + {{/if}} + {{/each}} +] diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_composed_schemas.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_composed_schemas.hbs index 67ebdfaf191..60960fe30b5 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_composed_schemas.hbs +++ b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_composed_schemas.hbs @@ -1,73 +1,14 @@ {{#if allOf}} - -class AllOf: -{{#each allOf}} -{{#if refInfo.refClass}} - - {{> components/schemas/_helper_refclass_staticmethod }} -{{else}} - {{> components/schemas/_helper_schema_switch_case identifierPieces=(append identifierPieces "AllOf" jsonPathPiece) }} -{{/if}} -{{/each}} - classes = [ -{{#each allOf}} - {{#if refInfo.refClass}} - {{jsonPathPiece.snakeCase}}, - {{else}} - {{jsonPathPiece.camelCase}}, - {{/if}} -{{/each}} - ] -{{/if}} -{{#if oneOf}} - -class OneOf: -{{#each oneOf}} -{{#if refInfo.refClass}} - - {{> components/schemas/_helper_refclass_staticmethod }} -{{else}} - {{> components/schemas/_helper_schema_switch_case identifierPieces=(append identifierPieces "OneOf" jsonPathPiece) }} -{{/if}} -{{/each}} - classes = [ -{{#each oneOf}} - {{#if refInfo.refClass}} - {{jsonPathPiece.snakeCase}}, - {{else}} - {{jsonPathPiece.camelCase}}, - {{/if}} -{{/each}} - ] +all_of: {{allOf.jsonPathPiece.camelCase}} = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance({{allOf.jsonPathPiece.camelCase}})) # type: ignore {{/if}} {{#if anyOf}} - -class AnyOf: -{{#each anyOf}} -{{#if refInfo.refClass}} - - {{> components/schemas/_helper_refclass_staticmethod }} -{{else}} - {{> components/schemas/_helper_schema_switch_case identifierPieces=(append identifierPieces "AnyOf" jsonPathPiece) }} +any_of: {{anyOf.jsonPathPiece.camelCase}} = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance({{anyOf.jsonPathPiece.camelCase}})) # type: ignore {{/if}} -{{/each}} - classes = [ -{{#each anyOf}} - {{#if refInfo.refClass}} - {{jsonPathPiece.snakeCase}}, - {{else}} - {{jsonPathPiece.camelCase}}, - {{/if}} -{{/each}} - ] +{{#if oneOf}} +one_of: {{oneOf.jsonPathPiece.camelCase}} = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance({{oneOf.jsonPathPiece.camelCase}})) # type: ignore {{/if}} {{#if not}} {{#with not}} -{{#if refInfo.refClass}} - -{{> components/schemas/_helper_refclass_staticmethod }} -{{else}} -{{> components/schemas/_helper_schema_switch_case identifierPieces=(append identifierPieces jsonPathPiece) }} -{{/if}} +not_: typing.Type[{{#if refInfo.refClass}}{{#if refInfo.refModule}}{{refInfo.refModule}}.{{/if}}{{refInfo.refClass}}{{else}}{{jsonPathPiece.camelCase}}{{/if}}] = dataclasses.field(default_factory=lambda: {{#if refInfo.refClass}}{{#if refInfo.refModule}}{{refInfo.refModule}}.{{/if}}{{refInfo.refClass}}{{else}}{{jsonPathPiece.camelCase}}{{/if}}) # type: ignore {{/with}} {{/if}} diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_dict_partial.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_dict_partial.hbs index 51f0557904c..c92594bf59e 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_dict_partial.hbs +++ b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_dict_partial.hbs @@ -1,54 +1,26 @@ {{#if requiredProperties}} -required = { +required: typing.FrozenSet[str] = frozenset({ {{#each requiredProperties}} "{{{@key.original}}}", {{/each}} -} +}) {{/if}} {{#if hasDiscriminatorWithNonEmptyMapping}} -{{#with discriminator}} -{{#each mappedModels}} -{{#if @first}} - -@staticmethod -def discriminator(): - return { + {{#with discriminator}} +discriminator: typing.Mapping[str, typing.Mapping[str, typing.Type[schemas.Schema]]] = dataclasses.field( + default_factory=lambda: { '{{{propertyName.original}}}': { -{{/if}} + {{#each mappedModels}} '{{mappingName}}': {{{modelName}}}, -{{#if @last}} + {{/each}} } } -{{/if}} -{{/each}} -{{/with}} +) + {{/with}} {{/if}} {{#if properties}} - -class Properties: -{{#each properties}} -{{#if refInfo.refClass}} - - {{> components/schemas/_helper_refclass_staticmethod }} -{{else}} - {{> components/schemas/_helper_schema_switch_case identifierPieces=(append identifierPieces "Properties" jsonPathPiece.camelCase) }} -{{/if}} -{{/each}} - __annotations__ = { -{{#each properties}} -{{#if refInfo.refClass}} - "{{{@key.original}}}": {{jsonPathPiece.snakeCase}}, -{{else}} - "{{{@key.original}}}": {{jsonPathPiece.camelCase}}, -{{/if}} -{{/each}} - } +properties: {{properties.jsonPathPiece.camelCase}} = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance({{properties.jsonPathPiece.camelCase}})) # type: ignore {{/if}} {{#with additionalProperties}} -{{#if refInfo.refClass}} - -{{> components/schemas/_helper_refclass_staticmethod }} -{{else}} -{{> components/schemas/_helper_schema_switch_case identifierPieces=(append identifierPieces jsonPathPiece) }} -{{/if}} +additional_properties: typing.Type[{{#if refInfo.refClass}}{{#if refInfo.refModule}}{{refInfo.refModule}}.{{/if}}{{refInfo.refClass}}{{else}}{{jsonPathPiece.camelCase}}{{/if}}] = dataclasses.field(default_factory=lambda: {{#if refInfo.refClass}}{{#if refInfo.refModule}}{{refInfo.refModule}}.{{/if}}{{refInfo.refClass}}{{else}}{{jsonPathPiece.camelCase}}{{/if}}) # type: ignore {{/with}} diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_enums.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_enums.hbs index 78d2719c973..c4d53186cc4 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_enums.hbs +++ b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_enums.hbs @@ -2,17 +2,20 @@ {{#each enumValueToName}} @schemas.classproperty -def {{this}}(cls): {{#eq @key.type "string"}} +def {{this}}(cls) -> {{jsonPathPiece.camelCase}}[str]: return cls("{{{@key.value}}}") # type: ignore {{/eq}} {{#eq @key.type "number"}} +def {{this}}(cls) -> {{jsonPathPiece.camelCase}}[decimal.Decimal]: return cls({{{@key.value}}}) # type: ignore {{/eq}} {{#eq @key.type "integer"}} +def {{this}}(cls) -> {{jsonPathPiece.camelCase}}[decimal.Decimal]: return cls({{{@key.value}}}) # type: ignore {{/eq}} {{#eq @key.type "boolean"}} +def {{this}}(cls) -> {{jsonPathPiece.camelCase}}[schemas.BoolClass]: {{#if @key.value}} return cls(True) # type: ignore {{else}} @@ -20,6 +23,7 @@ def {{this}}(cls): {{/if}} {{/eq}} {{#eq @key.type "null"}} +def {{this}}(cls) -> {{jsonPathPiece.camelCase}}[schemas.NoneClass]: return cls(None) # type: ignore {{/eq}} {{/each}} diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_getitem_property.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_getitem_property.hbs index afe0a0a3c64..4b8f5efba5d 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_getitem_property.hbs +++ b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_getitem_property.hbs @@ -1,13 +1,13 @@ {{#if types}} {{#eq types.size 1}} -def __getitem__(self, name: {{#if literal}}typing_extensions.Literal["{{{key}}}"]{{else}}{{key}}{{/if}}) -> Schema_{{propertyClass}}.{{jsonPathPiece.camelCase}}[{{> components/schemas/_helper_schema_python_base_types }}]:{{#if overload}} ...{{/if}} +def __getitem__(self, name: {{#if literal}}typing_extensions.Literal["{{{key}}}"]{{else}}{{key}}{{/if}}) -> {{jsonPathPiece.camelCase}}[{{> components/schemas/_helper_schema_python_base_types }}]:{{#if overload}} ...{{/if}} {{else}} -def __getitem__(self, name: {{#if literal}}typing_extensions.Literal["{{{key}}}"]{{else}}{{key}}{{/if}}) -> Schema_{{propertyClass}}.{{jsonPathPiece.camelCase}}[typing.Union[ +def __getitem__(self, name: {{#if literal}}typing_extensions.Literal["{{{key}}}"]{{else}}{{key}}{{/if}}) -> {{jsonPathPiece.camelCase}}[typing.Union[ {{> components/schemas/_helper_schema_python_base_types_newline }} ]]:{{#if overload}} ...{{/if}} {{/eq}} {{else}} -def __getitem__(self, name: {{#if literal}}typing_extensions.Literal["{{{key}}}"]{{else}}{{key}}{{/if}}) -> Schema_{{propertyClass}}.{{jsonPathPiece.camelCase}}[typing.Union[ +def __getitem__(self, name: {{#if literal}}typing_extensions.Literal["{{{key}}}"]{{else}}{{key}}{{/if}}) -> {{jsonPathPiece.camelCase}}[typing.Union[ {{> components/schemas/_helper_schema_python_base_types_newline }} ]]:{{#if overload}} ...{{/if}} {{/if}} \ No newline at end of file diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_getitems.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_getitems.hbs index 8b2a8cda36e..9e012bd0eeb 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_getitems.hbs +++ b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_getitems.hbs @@ -8,9 +8,9 @@ {{else}} {{#if jsonPathPiece}} {{#if schemaIsFromAdditionalProperties}} -{{> components/schemas/_helper_getitem_property propertyClass="" literal=true key=@key.original overload=true }} +{{> components/schemas/_helper_getitem_property literal=true key=@key.original overload=true }} {{else}} -{{> components/schemas/_helper_getitem_property propertyClass=".Properties" literal=true key=@key.original overload=true }} +{{> components/schemas/_helper_getitem_property literal=true key=@key.original overload=true }} {{/if}} {{else}} {{! for when additionalProperties is unset, use schemas.AnyTypeSchema because val is not always schemas.UnsetAnyTypeSchema }} @@ -29,7 +29,7 @@ def __getitem__(self, name: typing_extensions.Literal["{{{@key.original}}}"]) -> {{#if refInfo.refClass}} {{> components/schemas/_helper_getitem_refclass literal=true key=@key.original overload=true }} {{else}} -{{> components/schemas/_helper_getitem_property propertyClass=".Properties" literal=true key=@key.original overload=true }} +{{> components/schemas/_helper_getitem_property literal=true key=@key.original overload=true }} {{/if}} {{/each}} {{/if}} @@ -41,7 +41,7 @@ def __getitem__(self, name: typing_extensions.Literal["{{{@key.original}}}"]) -> {{#if refInfo.refClass}} {{> components/schemas/_helper_getitem_refclass literal=false key="str" overload=true }} {{else}} -{{> components/schemas/_helper_getitem_property propertyClass="" literal=false key="str" overload=true }} +{{> components/schemas/_helper_getitem_property literal=false key="str" overload=true }} {{/if}} {{/unless}} {{else}} @@ -90,7 +90,7 @@ def __getitem__( {{#if refInfo.refClass}} {{> components/schemas/_helper_getitem_refclass literal=false key="str" overload=false }} {{else}} -{{> components/schemas/_helper_getitem_property propertyClass="" literal=false key="str" overload=false }} +{{> components/schemas/_helper_getitem_property literal=false key="str" overload=false }} {{/if}} # dict_instance[name] accessor return super().__getitem__(name) diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_getschemas.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_getschemas.hbs new file mode 100644 index 00000000000..bdd628ed31f --- /dev/null +++ b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_getschemas.hbs @@ -0,0 +1,27 @@ +{{#each getSchemas}} + {{! generate all schemas in post order traversal }} + {{#eq instanceType "schema" }} +{{> components/schemas/_helper_schema_switch_case identifierPieces=(append identifierPieces jsonPathPiece) }} + {{else}} + {{#eq instanceType "allOfType" }} +{{> components/schemas/_helper_allof_type }} + {{else}} + {{#eq instanceType "anyOfType" }} +{{> components/schemas/_helper_anyof_type }} + {{else}} + {{#eq instanceType "oneOfType" }} +{{> components/schemas/_helper_oneof_type }} + {{else}} + {{#eq instanceType "propertiesType" }} +{{> components/schemas/_helper_properties_type }} + {{else}} + {{#eq instanceType "importsType" }} + +{{> _helper_imports }} + {{/eq}} + {{/eq}} + {{/eq}} + {{/eq}} + {{/eq}} + {{/eq}} +{{/each}} \ No newline at end of file diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_list_partial.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_list_partial.hbs index b935f94d181..70c0cbbf8ba 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_list_partial.hbs +++ b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_list_partial.hbs @@ -1,8 +1,3 @@ {{#with items}} -{{#if refInfo.refClass}} - -{{> components/schemas/_helper_refclass_staticmethod }} -{{else}} -{{> components/schemas/_helper_schema_switch_case identifierPieces=(append identifierPieces jsonPathPiece) }} -{{/if}} +items: typing.Type[{{#if refInfo.refClass}}{{#if refInfo.refModule}}{{refInfo.refModule}}.{{/if}}{{refInfo.refClass}}{{else}}{{jsonPathPiece.camelCase}}{{/if}}] = dataclasses.field(default_factory=lambda: {{#if refInfo.refClass}}{{#if refInfo.refModule}}{{refInfo.refModule}}.{{/if}}{{refInfo.refClass}}{{else}}{{jsonPathPiece.camelCase}}{{/if}}) # type: ignore {{/with}} diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_new.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_new.hbs index 5f8b5fe0bd9..98fa170b55d 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_new.hbs +++ b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_new.hbs @@ -11,7 +11,7 @@ def __new__( ] {{else}} typing.Union[ - {{> components/schemas/_helper_new_property_value_type propertyClass=null optional=false }} + {{> components/schemas/_helper_new_property_value_type optional=false }} ] {{/if}} {{/with}} @@ -47,9 +47,7 @@ def __new__( {{/contains}} {{/eq}} {{else}} - *args_: typing.Union[ - {{> _helper_schema_python_types_newline }} - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, {{/if}} {{#if types}} {{#eq types.size 1}} @@ -65,11 +63,11 @@ def __new__( {{#if jsonPathPiece}} {{#if schemaIsFromAdditionalProperties}} {{@key.original}}: typing.Union[ - {{> components/schemas/_helper_new_property_value_type propertyClass=null optional=false }} + {{> components/schemas/_helper_new_property_value_type optional=false }} ], {{else}} {{@key.original}}: typing.Union[ - {{> components/schemas/_helper_new_property_value_type propertyClass="Properties" optional=false }} + {{> components/schemas/_helper_new_property_value_type optional=false }} ], {{/if}} {{else}} @@ -95,7 +93,7 @@ def __new__( ] = schemas.unset, {{else}} {{@key.original}}: typing.Union[ - {{> components/schemas/_helper_new_property_value_type propertyClass="Properties" optional=true }} + {{> components/schemas/_helper_new_property_value_type optional=true }} ] = schemas.unset, {{/if}} {{/if}} @@ -109,35 +107,31 @@ def __new__( ], {{else}} **kwargs: typing.Union[ - {{> components/schemas/_helper_new_property_value_type propertyClass=null optional=false }} + {{> components/schemas/_helper_new_property_value_type optional=false }} ], {{/if}} {{/unless}} {{else}} {{#eq types null}} - **kwargs: typing.Union[ - {{> components/schemas/_helper_types_all_incl_schema_newline }} - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA {{else}} {{#contains types "object"}} - **kwargs: typing.Union[ - {{> components/schemas/_helper_types_all_incl_schema_newline }} - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA {{/contains}} {{/eq}} {{/with}} {{#if types}} {{#eq types.size 1}} -) -> {{#each identifierPieces}}{{#if this.camelCase}}{{this.camelCase}}{{else}}{{this}}{{/if}}{{#unless @last}}.{{/unless}}{{/each}}[{{> components/schemas/_helper_schema_python_base_types }}]: +) -> {{jsonPathPiece.camelCase}}[{{> components/schemas/_helper_schema_python_base_types }}]: {{else}} -) -> {{#each identifierPieces}}{{#if this.camelCase}}{{this.camelCase}}{{else}}{{this}}{{/if}}{{#unless @last}}.{{/unless}}{{/each}}[ +) -> {{jsonPathPiece.camelCase}}[ typing.Union[ {{> components/schemas/_helper_schema_python_base_types_newline }} ] ]: {{/eq}} {{else}} -) -> {{#each identifierPieces}}{{#if this.camelCase}}{{this.camelCase}}{{else}}{{this}}{{/if}}{{#unless @last}}.{{/unless}}{{/each}}[ +) -> {{jsonPathPiece.camelCase}}[ typing.Union[ {{> components/schemas/_helper_schema_python_base_types_newline }} ] @@ -190,16 +184,16 @@ def __new__( inst = typing.cast( {{#if types}} {{#eq types.size 1}} - {{#each identifierPieces}}{{#if this.camelCase}}{{this.camelCase}}{{else}}{{this}}{{/if}}{{#unless @last}}.{{/unless}}{{/each}}[{{> components/schemas/_helper_schema_python_base_types }}], + {{jsonPathPiece.camelCase}}[{{> components/schemas/_helper_schema_python_base_types }}], {{else}} - {{#each identifierPieces}}{{#if this.camelCase}}{{this.camelCase}}{{else}}{{this}}{{/if}}{{#unless @last}}.{{/unless}}{{/each}}[ + {{jsonPathPiece.camelCase}}[ typing.Union[ {{> components/schemas/_helper_schema_python_base_types_newline }} ] ], {{/eq}} {{else}} - {{#each identifierPieces}}{{#if this.camelCase}}{{this.camelCase}}{{else}}{{this}}{{/if}}{{#unless @last}}.{{/unless}}{{/each}}[ + {{jsonPathPiece.camelCase}}[ typing.Union[ {{> components/schemas/_helper_schema_python_base_types_newline }} ] diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_new_property_value_type.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_new_property_value_type.hbs index 392d4d1c513..b6855e91c8e 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_new_property_value_type.hbs +++ b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_new_property_value_type.hbs @@ -1,15 +1,15 @@ {{#if types}} {{#eq types.size 1}} -Schema_.{{#if propertyClass}}{{propertyClass}}.{{/if}}{{jsonPathPiece.camelCase}}[{{> components/schemas/_helper_schema_python_base_types }}], +{{jsonPathPiece.camelCase}}[{{> components/schemas/_helper_schema_python_base_types }}], {{else}} -Schema_.{{#if propertyClass}}{{propertyClass}}.{{/if}}{{jsonPathPiece.camelCase}}[typing.Union[ +{{jsonPathPiece.camelCase}}[typing.Union[ {{> components/schemas/_helper_schema_python_base_types_newline }} ]], {{/eq}} {{else}} -Schema_.{{#if propertyClass}}{{propertyClass}}.{{/if}}{{jsonPathPiece.camelCase}}[typing.Union[ - {{> components/schemas/_helper_schema_python_base_types_newline }} -]], +{{jsonPathPiece.camelCase}}[ + schemas.INPUT_BASE_TYPES +], {{/if}} {{#if optional}} schemas.Unset, diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_new_ref_property_value_type.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_new_ref_property_value_type.hbs index 63badb8fd41..83da4060c0a 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_new_ref_property_value_type.hbs +++ b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_new_ref_property_value_type.hbs @@ -8,9 +8,9 @@ ]], {{/eq}} {{else}} -{{#if ../refInfo.refModule}}{{../refInfo.refModule}}.{{/if}}{{../refInfo.refClass}}[typing.Union[ - {{> components/schemas/_helper_schema_python_base_types_newline }} -]], +{{#if ../refInfo.refModule}}{{../refInfo.refModule}}.{{/if}}{{../refInfo.refClass}}[ + schemas.INPUT_BASE_TYPES +], {{/if}} {{#if optional}} schemas.Unset, diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_oneof_type.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_oneof_type.hbs new file mode 100644 index 00000000000..847cdd8dfd7 --- /dev/null +++ b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_oneof_type.hbs @@ -0,0 +1,9 @@ +{{oneOf.jsonPathPiece.camelCase}} = typing.Tuple[ + {{#each oneOf}} + {{#if refInfo.refClass}} + typing.Type[{{#if refInfo.refModule}}{{refInfo.refModule}}.{{/if}}{{refInfo.refClass}}], + {{else}} + typing.Type[{{jsonPathPiece.camelCase}}[schemas.U]], + {{/if}} + {{/each}} +] diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_properties_type.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_properties_type.hbs new file mode 100644 index 00000000000..566d4d5de91 --- /dev/null +++ b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_properties_type.hbs @@ -0,0 +1,12 @@ +{{properties.jsonPathPiece.camelCase}} = typing_extensions.TypedDict( + '{{properties.jsonPathPiece.camelCase}}', + { + {{#each properties}} + {{#if refInfo.refClass}} + "{{{@key.original}}}": typing.Type[{{#if refInfo.refModule}}{{refInfo.refModule}}.{{/if}}{{refInfo.refClass}}], + {{else}} + "{{{@key.original}}}": typing.Type[{{jsonPathPiece.camelCase}}], + {{/if}} + {{/each}} + } +) diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_property_type_hints.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_property_type_hints.hbs index 35555c32e5a..0ac48dd0b9b 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_property_type_hints.hbs +++ b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_property_type_hints.hbs @@ -34,12 +34,12 @@ def {{@key.original}}(self) -> {{#if ../refInfo.refModule}}{{../refInfo.refModul {{#eq types.size 1}} @property -def {{@key.original}}(self) -> Schema_.{{jsonPathPiece.camelCase}}[{{> components/schemas/_helper_schema_python_base_types }}]: +def {{@key.original}}(self) -> {{jsonPathPiece.camelCase}}[{{> components/schemas/_helper_schema_python_base_types }}]: return self.__getitem__("{{{@key.original}}}") {{else}} @property -def {{@key.original}}(self) -> Schema_.{{jsonPathPiece.camelCase}}[typing.Union[ +def {{@key.original}}(self) -> {{jsonPathPiece.camelCase}}[typing.Union[ {{> components/schemas/_helper_schema_python_base_types_newline }} ]]: return self.__getitem__("{{{@key.original}}}") @@ -47,7 +47,7 @@ def {{@key.original}}(self) -> Schema_.{{jsonPathPiece.camelCase}}[typing.Union[ {{else}} @property -def {{@key.original}}(self) -> Schema_.{{jsonPathPiece.camelCase}}[typing.Union[ +def {{@key.original}}(self) -> {{jsonPathPiece.camelCase}}[typing.Union[ {{> components/schemas/_helper_schema_python_base_types_newline }} ]]: return self.__getitem__("{{{@key.original}}}") @@ -57,12 +57,12 @@ def {{@key.original}}(self) -> Schema_.{{jsonPathPiece.camelCase}}[typing.Union[ {{#eq types.size 1}} @property -def {{@key.original}}(self) -> Schema_.Properties.{{jsonPathPiece.camelCase}}[{{> components/schemas/_helper_schema_python_base_types }}]: +def {{@key.original}}(self) -> {{jsonPathPiece.camelCase}}[{{> components/schemas/_helper_schema_python_base_types }}]: return self.__getitem__("{{{@key.original}}}") {{else}} @property -def {{@key.original}}(self) -> Schema_.Properties.{{jsonPathPiece.camelCase}}[typing.Union[ +def {{@key.original}}(self) -> {{jsonPathPiece.camelCase}}[typing.Union[ {{> components/schemas/_helper_schema_python_base_types_newline }} ]]: return self.__getitem__("{{{@key.original}}}") @@ -70,7 +70,7 @@ def {{@key.original}}(self) -> Schema_.Properties.{{jsonPathPiece.camelCase}}[ty {{else}} @property -def {{@key.original}}(self) -> Schema_.Properties.{{jsonPathPiece.camelCase}}[typing.Union[ +def {{@key.original}}(self) -> {{jsonPathPiece.camelCase}}[typing.Union[ {{> components/schemas/_helper_schema_python_base_types_newline }} ]]: return self.__getitem__("{{{@key.original}}}") diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_schema_composed_or_anytype.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_schema_composed_or_anytype.hbs index 9d624ea08ce..f04ba30f664 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_schema_composed_or_anytype.hbs +++ b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_schema_composed_or_anytype.hbs @@ -38,13 +38,14 @@ class {{jsonPathPiece.camelCase}}( {{/if}} - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): {{#eq types null}} # any type {{/eq}} {{> components/schemas/_helper_types }} {{#if format}} - format = '{{format}}' + format: str = '{{format}}' {{/if}} {{#if enumValueToName}} {{> components/schemas/_helper_schema_enum }} @@ -68,3 +69,4 @@ class {{jsonPathPiece.camelCase}}( {{> components/schemas/_helper_property_type_hints }} {{> components/schemas/_helper_new }} + diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_schema_dict.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_schema_dict.hbs index 48583f3abda..fdc92dcfb8e 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_schema_dict.hbs +++ b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_schema_dict.hbs @@ -17,11 +17,13 @@ class {{jsonPathPiece.camelCase}}( {{#or additionalProperties requiredProperties hasDiscriminatorWithNonEmptyMapping properties hasValidation}} - class Schema_: - types = {frozendict.frozendict} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) {{> components/schemas/_helper_dict_partial identifierPieces=(append identifierPieces "Schema_") }} {{> components/schemas/_helper_validations }} {{/or}} {{> components/schemas/_helper_property_type_hints }} {{> components/schemas/_helper_new }} + diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_schema_enum.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_schema_enum.hbs index 4cdebbc7e4c..41af6d8c300 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_schema_enum.hbs +++ b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_schema_enum.hbs @@ -1,23 +1,25 @@ -enum_value_to_name = { +enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { {{#each enumValueToName}} {{#eq @key.type "string"}} - "{{{@key.value}}}": "{{this}}", + "{{{@key.value}}}": "{{this}}", {{/eq}} {{#eq @key.type "number"}} - {{{@key.value}}}: "{{this}}", + {{{@key.value}}}: "{{this}}", {{/eq}} {{#eq @key.type "integer"}} - {{{@key.value}}}: "{{this}}", + {{{@key.value}}}: "{{this}}", {{/eq}} {{#eq @key.type "boolean"}} {{#if @key.value}} - schemas.BoolClass.TRUE: "{{this}}", + schemas.BoolClass.TRUE: "{{this}}", {{else}} - schemas.BoolClass.FALSE: "{{this}}", + schemas.BoolClass.FALSE: "{{this}}", {{/if}} {{/eq}} {{#eq @key.type "null"}} - schemas.NoneClass.NONE: "{{this}}", + schemas.NoneClass.NONE: "{{this}}", {{/eq}} {{/each}} -} + } +) diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_schema_list.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_schema_list.hbs index 9d0af06be38..9b42dea68fd 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_schema_list.hbs +++ b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_schema_list.hbs @@ -17,8 +17,9 @@ class {{jsonPathPiece.camelCase}}( {{#or items hasValidation}} - class Schema_: - types = {tuple} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) {{#if hasValidation}} {{> components/schemas/_helper_validations }} {{/if}} @@ -31,7 +32,8 @@ class {{jsonPathPiece.camelCase}}( {{#if refInfo.refClass}} {{> components/schemas/_helper_getitem_refclass literal=false key="int" overload=false }} {{else}} - {{> components/schemas/_helper_getitem_property propertyClass="" literal=false key="int" overload=false }} + {{> components/schemas/_helper_getitem_property literal=false key="int" overload=false }} {{/if}} return super().__getitem__(name) -{{/with}} \ No newline at end of file +{{/with}} + diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_schema_simple.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_schema_simple.hbs index 3860cd857d5..94ef43bfd1a 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_schema_simple.hbs +++ b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_schema_simple.hbs @@ -21,35 +21,36 @@ class {{jsonPathPiece.camelCase}}( {{#or hasValidation enumValueToName format defaultValue}} - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): {{#eq types null}} # any type {{/eq}} {{> components/schemas/_helper_types }} {{#if format}} - format = '{{format}}' + format: str = '{{format}}' {{/if}} {{> components/schemas/_helper_validations }} {{#if defaultValue}} {{#with defaultValue}} {{#eq type "string"}} - default = "{{{value}}}" + default: str = "{{{value}}}" {{/eq}} {{#eq type "number"}} - default = {{{value}}} + default: typing.Union[int, float] = {{{value}}} {{/eq}} {{#eq type "integer"}} - default = {{{value}}} + default: int = {{{value}}} {{/eq}} {{#eq type "boolean"}} {{#if value}} - default = schemas.BoolClass.TRUE + default: schemas.BoolClass = schemas.BoolClass.TRUE {{else}} - default = schemas.BoolClass.FALSE + default: schemas.BoolClass = schemas.BoolClass.FALSE {{/if}} {{/eq}} {{#eq type "null"}} - default = schemas.NoneClass.NONE + default: schemas.NoneClass = schemas.NoneClass.NONE {{/eq}} {{/with}} {{/if}} diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_types.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_types.hbs index 8961be085fb..6fe2bda9dfb 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_types.hbs +++ b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_types.hbs @@ -1,5 +1,5 @@ {{#if types}} -types = { +types: typing.FrozenSet[typing.Type] = frozenset({ {{#each types}} {{#eq this "null"}} schemas.NoneClass, @@ -28,5 +28,5 @@ types = { schemas.BoolClass, {{/eq}} {{/each}} -} +}) {{/if}} \ No newline at end of file diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_types_all_incl_schema_newline.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_types_all_incl_schema_newline.hbs deleted file mode 100644 index a8fb6567b13..00000000000 --- a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_types_all_incl_schema_newline.hbs +++ /dev/null @@ -1,17 +0,0 @@ -dict, -frozendict.frozendict, -list, -tuple, -decimal.Decimal, -float, -int, -str, -datetime.date, -datetime.datetime, -uuid.UUID, -bool, -None, -bytes, -io.FileIO, -io.BufferedReader, -schemas.Schema diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_validations.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_validations.hbs index 894c5ec9b96..d107c0e61fa 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_validations.hbs +++ b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/_helper_validations.hbs @@ -1,39 +1,39 @@ {{#neq uniqueItems null}} -unique_items = {{#if uniqueItems}}True{{else}}False{{/if}} +unique_items: bool = {{#if uniqueItems}}True{{else}}False{{/if}} {{/neq}} {{#neq maxLength null}} -max_length = {{maxLength}} +max_length: int = {{maxLength}} {{/neq}} {{#neq minLength null}} -min_length = {{minLength}} +min_length: int = {{minLength}} {{/neq}} {{#neq maxItems null}} -max_items = {{maxItems}} +max_items: int = {{maxItems}} {{/neq}} {{#neq minItems null}} -min_items = {{minItems}} +min_items: int = {{minItems}} {{/neq}} {{#neq maxProperties null }} -max_properties = {{maxProperties}} +max_properties: int = {{maxProperties}} {{/neq}} {{#neq minProperties null}} -min_properties = {{minProperties}} +min_properties: int = {{minProperties}} {{/neq}} {{#neq maximum null}} -{{#if exclusiveMaximum}}exclusive_maximum{{/if}}inclusive_maximum{{#unless exclusiveMaximum}}{{/unless}} = {{maximum}} +{{#if exclusiveMaximum}}exclusive_maximum{{/if}}inclusive_maximum{{#unless exclusiveMaximum}}{{/unless}}: typing.Union[int, float] = {{maximum}} {{/neq}} {{#neq minimum null}} -{{#if exclusiveMinimum}}exclusive_minimum{{/if}}inclusive_minimum{{#unless exclusiveMinimum}}{{/unless}} = {{minimum}} +{{#if exclusiveMinimum}}exclusive_minimum{{/if}}inclusive_minimum{{#unless exclusiveMinimum}}{{/unless}}: typing.Union[int, float] = {{minimum}} {{/neq}} {{#neq patternInfo null}} -regex={ +pattern: schemas.PatternInfo = schemas.PatternInfo( {{#with patternInfo}} - 'pattern': r'{{{pattern}}}', # noqa: E501 + pattern=r'{{{pattern}}}'{{#if flags}},{{/if}} # noqa: E501 {{#if flags}} {{#eq flags.size 1}} - 'flags': {{#each flags}}re.{{#eq this "i"}}I{{/eq}}{{#eq this "m"}}M{{/eq}}{{#eq this "s"}}S{{/eq}}{{#eq this "u"}}U{{/eq}}{{/each}}, + flags={{#each flags}}re.{{#eq this "i"}}I{{/eq}}{{#eq this "m"}}M{{/eq}}{{#eq this "s"}}S{{/eq}}{{#eq this "u"}}U{{/eq}}{{/each}}, {{else}} - 'flags': ( + flags=( {{#each flags}} {{#eq this "i"}} re.I{{#unless @last}} |{{/unless}} @@ -52,8 +52,8 @@ regex={ {{/eq}} {{/if}} {{/with}} -} +) {{/neq}} {{#neq multipleOf null}} -multiple_of = {{multipleOf}} +multiple_of: typing.Union[int, float] = {{multipleOf}} {{/neq}} diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/schema.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/schema.hbs index 3f72670bb1a..b0aa80c42a2 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/schema.hbs +++ b/modules/openapi-json-schema-generator/src/main/resources/python/components/schemas/schema.hbs @@ -13,10 +13,7 @@ from {{packageName}}.shared_imports.schema_imports import * {{else}} from __future__ import annotations from {{packageName}}.shared_imports.schema_imports import * -{{> components/schemas/_helper_schema_switch_case identifierPieces=(append identifierPieces jsonPathPiece) }} - {{#if imports}} - {{/if}} -{{> _helper_imports }} +{{> components/schemas/_helper_getschemas }} {{/if}} {{/with}} \ No newline at end of file diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/configurations/schema_configuration.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/configurations/schema_configuration.hbs index 02be0546760..f47b3262c7f 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/configurations/schema_configuration.hbs +++ b/modules/openapi-json-schema-generator/src/main/resources/python/configurations/schema_configuration.hbs @@ -8,34 +8,32 @@ from {{packageName}} import exceptions PYTHON_KEYWORD_TO_JSON_SCHEMA_KEYWORD = { - 'types': 'type', + 'additional_properties': 'additionalProperties', + 'all_of': 'allOf', + 'any_of': 'anyOf', + 'discriminator': 'discriminator', + # default omitted because it has no validation impact 'enum_value_to_name': 'enum', - 'unique_items': 'uniqueItems', - 'min_items': 'minItems', + 'exclusive_maximum': 'exclusiveMaximum', + 'exclusive_minimum': 'exclusiveMinimum', + 'format': 'format', + 'inclusive_maximum': 'maximum', + 'inclusive_minimum': 'minimum', + 'items': 'items', 'max_items': 'maxItems', - 'min_properties': 'minProperties', + 'max_length': 'maxLength', 'max_properties': 'maxProperties', + 'min_items': 'minItems', 'min_length': 'minLength', - 'max_length': 'maxLength', - 'inclusive_minimum': 'minimum', - 'exclusive_minimum': 'exclusiveMinimum', - 'inclusive_maximum': 'maximum', - 'exclusive_maximum': 'exclusiveMaximum', + 'min_properties': 'minProperties', 'multiple_of': 'multipleOf', - 'regex': 'pattern', - 'format': 'format', + 'not_': 'not', + 'one_of': 'oneOf', + 'pattern': 'pattern', + 'properties': 'properties', 'required': 'required', - 'items': 'items', - 'Items': 'items', - 'Properties': 'properties', - 'additional_properties': 'additionalProperties', - 'additionalProperties': 'additionalProperties', - 'OneOf': 'oneOf', - 'AnyOf': 'anyOf', - 'AllOf': 'allOf', - '_not': 'not', - '_Not': 'not', - 'discriminator': 'discriminator' + 'types': 'type', + 'unique_items': 'uniqueItems' } class SchemaConfiguration: diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/schemas.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/schemas.hbs index d62a13b607c..640cb5365b7 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/schemas.hbs +++ b/modules/openapi-json-schema-generator/src/main/resources/python/schemas.hbs @@ -8,6 +8,7 @@ import datetime import dataclasses import functools import decimal +import inspect import io import re import types @@ -106,6 +107,20 @@ def add_deeper_validated_schemas(validation_metadata: ValidationMetadata, path_t update(path_to_schemas, other_path_to_schemas) +class SingletonMeta(type): + """ + A singleton class for schemas + Schemas are frozen classes that are never instantiated with init args + All args come from defaults + """ + _instances = {} + + def __call__(cls, *args, **kwargs): + if cls not in cls._instances: + cls._instances[cls] = super().__call__(*args, **kwargs) + return cls._instances[cls] + + class Singleton: """ Enums and singletons are the same @@ -142,14 +157,18 @@ class Singleton: return f'<{self.__class__.__name__}: False>' return f'<{self.__class__.__name__}: {super().__repr__()}>' +T = typing.TypeVar('T') -class classproperty: - def __init__(self, fget): - self.fget = fget +class classproperty(typing.Generic[T]): + def __init__(self, method: typing.Callable[..., T]): + self.__method = method + functools.update_wrapper(self, method) # type: ignore - def __get__(self, owner_self, owner_cls): - return self.fget(owner_cls) + def __get__(self, obj, cls=None) -> T: + if cls is None: + cls = type(obj) + return self.__method(cls) class NoneClass(Singleton): @@ -178,32 +197,40 @@ class BoolClass(Singleton): raise ValueError('Unable to find the boolean value of this instance') +@dataclasses.dataclass(frozen=True) +class PatternInfo: + pattern: str + flags: typing.Optional[re.RegexFlag] = None + + class SchemaTyped: - types: typing.Optional[typing.Set[typing.Type]] + additional_properties: typing.Type[Schema] + all_of: typing.Tuple[typing.Type[Schema], ...] + any_of: typing.Tuple[typing.Type[Schema], ...] + discriminator: typing.Mapping[str, typing.Mapping[str, typing.Type[Schema]]] + default: typing.Union[str, int, float, BoolClass, NoneClass] + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, BoolClass, NoneClass], str] exclusive_maximum: typing.Union[int, float] - inclusive_maximum: typing.Union[int, float] exclusive_minimum: typing.Union[int, float] + format: str + inclusive_maximum: typing.Union[int, float] inclusive_minimum: typing.Union[int, float] + items: typing.Type[Schema] max_items: int - min_items: int - discriminator: typing.Dict[str, typing.Dict[str, typing.Type['Schema']]] - default: typing.Union[str, int, BoolClass] - - - class Properties: - # to hold object properties - pass - - additionalProperties: typing.Optional[typing.Type['Schema']] - max_properties: int - min_properties: int - AllOf: typing.List[typing.Type['Schema']] - OneOf: typing.List[typing.Type['Schema']] - AnyOf: typing.List[typing.Type['Schema']] - _not: typing.Type['Schema'] max_length: int + max_properties: int + min_items: int min_length: int - items: typing.Type['Schema'] + min_properties: int + multiple_of: typing.Union[int, float] + not_: typing.Type[Schema] + one_of: typing.Tuple[typing.Type[Schema], ...] + pattern: PatternInfo + properties: typing.Mapping[str, typing.Type[Schema]] + required: typing.FrozenSet[str] + types: typing.FrozenSet[typing.Type] + unique_items: bool + PathToSchemasType = typing.Dict[ typing.Tuple[typing.Union[str, int], ...], @@ -567,9 +594,9 @@ def validate_multiple_of( return None -def validate_regex( +def validate_pattern( arg: typing.Any, - regex_dict: typing.Dict, + pattern_info: PatternInfo, cls: typing.Type, validation_metadata: ValidationMetadata, {{#if nonCompliantUseDiscriminatorIfCompositionFails}} @@ -578,22 +605,22 @@ def validate_regex( ) -> None: if not isinstance(arg, str): return None - flags = regex_dict.get('flags', 0) - if not re.search(regex_dict['pattern'], arg, flags=flags): + flags = pattern_info.flags if pattern_info.flags is not None else 0 + if not re.search(pattern_info.pattern, arg, flags=flags): if flags != 0: # Don't print the regex flags if the flags are not # specified in the OAS document. _raise_validation_error_message( value=arg, constraint_msg="must match regular expression", - constraint_value=regex_dict['pattern'], + constraint_value=pattern_info.pattern, path_to_item=validation_metadata.path_to_item, additional_txt=" with flags=`{}`".format(flags) ) _raise_validation_error_message( value=arg, constraint_msg="must match regular expression", - constraint_value=regex_dict['pattern'], + constraint_value=pattern_info.pattern, path_to_item=validation_metadata.path_to_item ) return None @@ -689,8 +716,8 @@ class CustomIsoparser(parser.isoparser): def __parse_isotime(self, dt_str: str) -> typing.Tuple[int, int, int, int, typing.Optional[typing.Union[tz.tzutc, tz.tzoffset]]]: dt_str_ascii = self.__get_ascii_bytes(dt_str) values = self._parse_isotime(dt_str_ascii) # type: ignore - components: typing.Tuple[int, int, int, int, typing.Optional[typing.Union[tz.tzutc, tz.tzoffset]]] = tuple(values) - return tuple(components) + components: typing.Tuple[int, int, int, int, typing.Optional[typing.Union[tz.tzutc, tz.tzoffset]]] = tuple(values) # type: ignore + return components def parse_isodatetime(self, dt_str: str) -> datetime.datetime: components, pos = self.__parse_isodate(dt_str) @@ -832,12 +859,14 @@ def _get_class(item_cls: typing.Union[types.FunctionType, staticmethod, typing.T elif isinstance(item_cls, staticmethod): # referenced schema return item_cls.__func__() - return item_cls + elif isinstance(item_cls, type): + return item_cls + raise ValueError('invalid class value passed in') def validate_items( arg: typing.Any, - item_cls: typing.Type, + item_cls: typing.Type[Schema], cls: typing.Type, validation_metadata: ValidationMetadata, {{#if nonCompliantUseDiscriminatorIfCompositionFails}} @@ -846,6 +875,7 @@ def validate_items( ) -> typing.Optional[PathToSchemasType]: if not isinstance(arg, tuple): return None + schema = _get_class(additional_properties_cls) item_cls = _get_class(item_cls) path_to_schemas = {} for i, value in enumerate(arg): @@ -865,7 +895,7 @@ def validate_items( def validate_properties( arg: typing.Any, - properties: typing.Type, + properties: typing.Mapping[str, typing.Type[Schema]], cls: typing.Type, validation_metadata: ValidationMetadata, {{#if nonCompliantUseDiscriminatorIfCompositionFails}} @@ -875,10 +905,10 @@ def validate_properties( if not isinstance(arg, frozendict.frozendict): return None path_to_schemas = {} - present_properties = {k: v for k, v, in arg.items() if k in properties.__annotations__} + present_properties = {k: v for k, v, in arg.items() if k in properties} for property_name, value in present_properties.items(): path_to_item = validation_metadata.path_to_item + (property_name,) - schema = properties.__annotations__[property_name] + schema = properties[property_name] schema = _get_class(schema) arg_validation_metadata = ValidationMetadata( path_to_item=path_to_item, @@ -895,7 +925,7 @@ def validate_properties( def validate_additional_properties( arg: typing.Any, - additional_properties_schema: typing.Type, + additional_properties_cls: typing.Type[Schema], cls: typing.Type, validation_metadata: ValidationMetadata, {{#if nonCompliantUseDiscriminatorIfCompositionFails}} @@ -904,10 +934,11 @@ def validate_additional_properties( ) -> typing.Optional[PathToSchemasType]: if not isinstance(arg, frozendict.frozendict): return None - schema = _get_class(additional_properties_schema) + schema = _get_class(additional_properties_cls) path_to_schemas = {} - properties_annotations = cls.Schema_.Properties.__annotations__ if hasattr(cls.Schema_, 'Properties') else {} - present_additional_properties = {k: v for k, v, in arg.items() if k not in properties_annotations} + cls_schema = cls.Schema_() + properties = cls_schema.properties if hasattr(cls_schema, 'properties') else {} + present_additional_properties = {k: v for k, v, in arg.items() if k not in properties} for property_name, value in present_additional_properties.items(): path_to_item = validation_metadata.path_to_item + (property_name,) arg_validation_metadata = ValidationMetadata( @@ -925,7 +956,7 @@ def validate_additional_properties( def validate_one_of( arg: typing.Any, - one_of_container_cls: typing.Type, + classes: typing.Tuple[typing.Type[Schema], ...], cls: 'Schema', validation_metadata: ValidationMetadata, {{#if nonCompliantUseDiscriminatorIfCompositionFails}} @@ -935,8 +966,8 @@ def validate_one_of( ) -> PathToSchemasType: oneof_classes = [] path_to_schemas = collections.defaultdict(set) - for one_of_cls in one_of_container_cls.classes: - schema = _get_class(one_of_cls) + for schema in classes: + schema = _get_class(schema) if schema in path_to_schemas[validation_metadata.path_to_item]: oneof_classes.append(schema) continue @@ -989,7 +1020,7 @@ def validate_one_of( def validate_any_of( arg: typing.Any, - any_of_container_cls: typing.Type, + classes: typing.Tuple[typing.Type[Schema], ...], cls: 'Schema', validation_metadata: ValidationMetadata, {{#if nonCompliantUseDiscriminatorIfCompositionFails}} @@ -999,8 +1030,8 @@ def validate_any_of( ) -> PathToSchemasType: anyof_classes = [] path_to_schemas = collections.defaultdict(set) - for any_of_cls in any_of_container_cls.classes: - schema = _get_class(any_of_cls) + for schema in classes: + schema = _get_class(schema) if schema is cls: """ optimistically assume that cls schema will pass validation @@ -1038,7 +1069,7 @@ def validate_any_of( def validate_all_of( arg: typing.Any, - all_of_cls: typing.Type, + classes: typing.Tuple[typing.Type[Schema], ...], cls: typing.Type, validation_metadata: ValidationMetadata, {{#if nonCompliantUseDiscriminatorIfCompositionFails}} @@ -1046,8 +1077,8 @@ def validate_all_of( {{/if}} ) -> PathToSchemasType: path_to_schemas = collections.defaultdict(set) - for allof_cls in all_of_cls.classes: - schema = _get_class(allof_cls) + for schema in classes: + schema = _get_class(schema) if schema is cls: """ optimistically assume that cls schema will pass validation @@ -1064,7 +1095,7 @@ def validate_all_of( def validate_not( arg: typing.Any, - not_cls: typing.Type, + not_cls: typing.Type[Schema], cls: typing.Type, validation_metadata: ValidationMetadata, {{#if nonCompliantUseDiscriminatorIfCompositionFails}} @@ -1109,38 +1140,36 @@ def __get_discriminated_class(cls, disc_property_name: str, disc_payload_value: """ Used in schemas with discriminators """ - if not hasattr(cls.Schema_, 'discriminator'): + cls_schema = cls.Schema_() + if not hasattr(cls_schema, 'discriminator'): return None - disc = cls.Schema_.discriminator() + disc = cls_schema.discriminator if disc_property_name not in disc: return None discriminated_cls = disc[disc_property_name].get(disc_payload_value) if discriminated_cls is not None: return discriminated_cls if not ( - hasattr(cls.Schema_, 'AllOf') or - hasattr(cls.Schema_, 'OneOf') or - hasattr(cls.Schema_, 'AnyOf') + hasattr(cls_schema, 'all_of') or + hasattr(cls_schema, 'one_of') or + hasattr(cls_schema, 'any_of') ): return None # TODO stop traveling if a cycle is hit - if hasattr(cls.Schema_, 'AllOf'): - for allof_cls in cls.Schema_.AllOf.classes: - allof_cls = _get_class(allof_cls) + if hasattr(cls_schema, 'all_of'): + for allof_cls in cls_schema.all_of: discriminated_cls = __get_discriminated_class( allof_cls, disc_property_name=disc_property_name, disc_payload_value=disc_payload_value) if discriminated_cls is not None: return discriminated_cls - if hasattr(cls.Schema_, 'OneOf'): - for oneof_cls in cls.Schema_.OneOf.classes: - oneof_cls = _get_class(oneof_cls) + if hasattr(cls_schema, 'one_of'): + for oneof_cls in cls_schema.one_of: discriminated_cls = __get_discriminated_class( oneof_cls, disc_property_name=disc_property_name, disc_payload_value=disc_payload_value) if discriminated_cls is not None: return discriminated_cls - if hasattr(cls.Schema_, 'AnyOf'): - for anyof_cls in cls.Schema_.AnyOf.classes: - anyof_cls = _get_class(anyof_cls) + if hasattr(cls_schema, 'any_of'): + for anyof_cls in cls_schema.any_of: discriminated_cls = __get_discriminated_class( anyof_cls, disc_property_name=disc_property_name, disc_payload_value=disc_payload_value) if discriminated_cls is not None: @@ -1155,7 +1184,7 @@ def _get_discriminated_class_and_exception( ) -> typing.Tuple[typing.Optional['Schema'], typing.Optional[Exception]]: if not isinstance(arg, frozendict.frozendict): return None, None - discriminator = cls.Schema_.discriminator() + discriminator = cls_schema().discriminator() disc_prop_name = list(discriminator.keys())[0] try: __ensure_discriminator_value_present(disc_prop_name, validation_metadata, arg) @@ -1172,7 +1201,7 @@ def _get_discriminated_class_and_exception( def validate_discriminator( arg: typing.Any, - discriminator_fn: typing.Type, + discriminator: typing.Mapping[str, typing.Mapping[str, typing.Type[Schema]]], cls: typing.Type, validation_metadata: ValidationMetadata, {{#if nonCompliantUseDiscriminatorIfCompositionFails}} @@ -1182,7 +1211,6 @@ def validate_discriminator( ) -> typing.Optional[PathToSchemasType]: if not isinstance(arg, frozendict.frozendict): return None - discriminator = discriminator_fn.__func__() disc_prop_name = list(discriminator.keys())[0] {{#if nonCompliantUseDiscriminatorIfCompositionFails}} if ensure_discriminator_value_present_exc: @@ -1236,24 +1264,19 @@ json_schema_keyword_to_validator = { 'inclusive_maximum': validate_inclusive_maximum, 'exclusive_maximum': validate_exclusive_maximum, 'multiple_of': validate_multiple_of, - 'regex': validate_regex, + 'pattern': validate_pattern, 'format': validate_format, 'required': validate_required, 'items': validate_items, - 'Items': validate_items, - 'Properties': validate_properties, - 'AdditionalProperties': validate_additional_properties, + 'properties': validate_properties, 'additional_properties': validate_additional_properties, - 'OneOf': validate_one_of, - 'AnyOf': validate_any_of, - 'AllOf': validate_all_of, - '_not': validate_not, - '_Not': validate_not, - 'ModelNot': validate_not, + 'one_of': validate_one_of, + 'any_of': validate_any_of, + 'all_of': validate_all_of, + 'not_': validate_not, 'discriminator': validate_discriminator } -T = typing.TypeVar('T') U = typing.TypeVar('U') class Schema(typing.Generic[T]): @@ -1282,14 +1305,16 @@ class Schema(typing.Generic[T]): All keyword validation except for type checking was done in calling stack frames If those validations passed, the validated classes are collected in path_to_schemas """ + cls_schema = cls.Schema_() json_schema_data = { k: v - for k, v in vars(cls.Schema_).items() + for k, v in vars(cls_schema).items() if k not in cls.__excluded_cls_properties and k not in validation_metadata.configuration.disabled_json_schema_python_keywords } {{#if nonCompliantUseDiscriminatorIfCompositionFails}} + print(f'json_schema_data {json_schema_data}') kwargs = {} if 'discriminator' in json_schema_data: discriminated_cls, ensure_discriminator_value_present_exc = _get_discriminated_class_and_exception( @@ -1416,7 +1441,7 @@ class Schema(typing.Generic[T]): """ cls._process_schema_classes(schema_classes) enum_schema = any( - issubclass(this_cls, Schema) and hasattr(this_cls.Schema_, "enum_value_to_name") + issubclass(this_cls, Schema) and hasattr(this_cls.Schema_(), "enum_value_to_name") for this_cls in schema_classes ) inheritable_primitive_type = schema_classes.intersection(cls.__inheritable_primitive_types_set) @@ -1524,8 +1549,8 @@ class Schema(typing.Generic[T]): ], configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None, **kwargs: typing.Union[ + Unset, {{> _helper_types_all_incl_schema }} - Unset ] ): """ @@ -2189,8 +2214,9 @@ class ListSchema( Schema[T], TupleMixin ): - class Schema_: - types = {tuple} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) @classmethod def from_openapi_data_(cls, arg: typing.Sequence[typing.Any], configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2205,8 +2231,9 @@ class NoneSchema( Schema[T], NoneMixin ): - class Schema_: - types = {NoneClass} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({NoneClass}) @classmethod def from_openapi_data_(cls, arg: None, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2225,8 +2252,9 @@ class NumberSchema( This is used for type: number with no format Both integers AND floats are accepted """ - class Schema_: - types = {decimal.Decimal} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) @classmethod def from_openapi_data_(cls, arg: typing.Union[int, float], configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2249,9 +2277,10 @@ class IntBase: class IntSchema(IntBase, NumberSchema[T]): - class Schema_: - types = {decimal.Decimal} - format = 'int' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) + format: str = 'int' @classmethod def from_openapi_data_(cls, arg: int, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2265,9 +2294,10 @@ class IntSchema(IntBase, NumberSchema[T]): class Int32Schema( IntSchema[T] ): - class Schema_: - types = {decimal.Decimal} - format = 'int32' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) + format: str = 'int32' def __new__(cls, arg_: typing.Union[decimal.Decimal, int], **kwargs: schema_configuration.SchemaConfiguration) -> Int32Schema[decimal.Decimal]: inst = super().__new__(cls, arg_, **kwargs) @@ -2277,9 +2307,10 @@ class Int32Schema( class Int64Schema( IntSchema[T] ): - class Schema_: - types = {decimal.Decimal} - format = 'int64' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) + format: str = 'int64' def __new__(cls, arg_: typing.Union[decimal.Decimal, int], **kwargs: schema_configuration.SchemaConfiguration) -> Int64Schema[decimal.Decimal]: inst = super().__new__(cls, arg_, **kwargs) @@ -2289,9 +2320,10 @@ class Int64Schema( class Float32Schema( NumberSchema[T] ): - class Schema_: - types = {decimal.Decimal} - format = 'float' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) + format: str = 'float' @classmethod def from_openapi_data_(cls, arg: float, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2305,9 +2337,10 @@ class Float32Schema( class Float64Schema( NumberSchema[T] ): - class Schema_: - types = {decimal.Decimal} - format = 'double' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) + format: str = 'double' @classmethod def from_openapi_data_(cls, arg: float, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2329,8 +2362,9 @@ class StrSchema( - type: string (format unset) - type: string, format: date """ - class Schema_: - types = {str} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({str}) @classmethod def from_openapi_data_(cls, arg: str, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None) -> StrSchema[str]: @@ -2341,9 +2375,10 @@ class StrSchema( class UUIDSchema(UUIDBase, StrSchema[T]): - class Schema_: - types = {str} - format = 'uuid' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({str}) + format: str = 'uuid' def __new__(cls, arg_: typing.Union[str, uuid.UUID], **kwargs: schema_configuration.SchemaConfiguration) -> UUIDSchema[str]: inst = super().__new__(cls, arg_, **kwargs) @@ -2351,9 +2386,10 @@ class UUIDSchema(UUIDBase, StrSchema[T]): class DateSchema(DateBase, StrSchema[T]): - class Schema_: - types = {str} - format = 'date' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({str}) + format: str = 'date' def __new__(cls, arg_: typing.Union[str, datetime.date], **kwargs: schema_configuration.SchemaConfiguration) -> DateSchema[str]: inst = super().__new__(cls, arg_, **kwargs) @@ -2361,9 +2397,10 @@ class DateSchema(DateBase, StrSchema[T]): class DateTimeSchema(DateTimeBase, StrSchema[T]): - class Schema_: - types = {str} - format = 'date-time' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({str}) + format: str = 'date-time' def __new__(cls, arg_: typing.Union[str, datetime.datetime], **kwargs: schema_configuration.SchemaConfiguration) -> DateTimeSchema[str]: inst = super().__new__(cls, arg_, **kwargs) @@ -2371,9 +2408,10 @@ class DateTimeSchema(DateTimeBase, StrSchema[T]): class DecimalSchema(DecimalBase, StrSchema[T]): - class Schema_: - types = {str} - format = 'number' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({str}) + format: str = 'number' def __new__(cls, arg_: str, **kwargs: schema_configuration.SchemaConfiguration) -> DecimalSchema[str]: """ @@ -2395,8 +2433,9 @@ class BytesSchema( """ this class will subclass bytes and is immutable """ - class Schema_: - types = {bytes} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({bytes}) def __new__(cls, arg_: bytes, **kwargs: schema_configuration.SchemaConfiguration) -> BytesSchema[bytes]: super_cls: typing.Type = super(Schema, cls) @@ -2423,8 +2462,9 @@ class FileSchema( - to allow file reading and writing to disk - to be able to preserve file name info """ - class Schema_: - types = {FileIO} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({FileIO}) def __new__(cls, arg_: typing.Union[io.FileIO, io.BufferedReader], **kwargs: schema_configuration.SchemaConfiguration) -> FileSchema[FileIO]: super_cls: typing.Type = super(Schema, cls) @@ -2435,15 +2475,15 @@ class BinarySchema( Schema[T], BinaryMixin ): - class Schema_: - types = {FileIO, bytes} - format = 'binary' - - class OneOf: - classes = [ - BytesSchema, - FileSchema, - ] + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({FileIO, bytes}) + format: str = 'binary' + + one_of: typing.Tuple[typing.Type[Schema], ...] = ( + BytesSchema, + FileSchema, + ) def __new__(cls, arg_: typing.Union[io.FileIO, io.BufferedReader, bytes], **kwargs: schema_configuration.SchemaConfiguration) -> BinarySchema[typing.Union[FileIO, bytes]]: return super().__new__(cls, arg_) @@ -2454,8 +2494,9 @@ class BoolSchema( Schema[T], BoolMixin ): - class Schema_: - types = {BoolClass} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({BoolClass}) @classmethod def from_openapi_data_(cls, arg: bool, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2476,7 +2517,8 @@ class AnyTypeSchema( NoneFrozenDictTupleStrDecimalBoolFileBytesMixin ): # Python representation of a schema defined as true or {} - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): pass def __new__( @@ -2516,7 +2558,8 @@ class AnyTypeSchema( Schema, bytes, io.FileIO, - io.BufferedReader + io.BufferedReader, + Unset ] ) -> AnyTypeSchema[typing.Union[ NoneClass, @@ -2586,9 +2629,9 @@ class NotAnyTypeSchema(AnyTypeSchema[T]): Does not allow inputs in of AnyType Note: validations on this class are never run because the code knows that no inputs will ever validate """ - - class Schema_: - _not = AnyTypeSchema[U] + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + not_: typing.Type[Schema] = AnyTypeSchema def __new__( cls, @@ -2604,8 +2647,9 @@ class DictSchema( Schema[T], FrozenDictMixin ): - class Schema_: - types = {frozendict.frozendict} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) @classmethod def from_openapi_data_(cls, arg: typing.Dict[str, typing.Any], configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2641,3 +2685,57 @@ LOG_CACHE_USAGE = False def log_cache_usage(cache_fn): if LOG_CACHE_USAGE: print(cache_fn.__name__, cache_fn.cache_info()) + + +W = typing.TypeVar('W', bound=typing_extensions.TypedDict) + +def typed_dict_to_instance(t_dict: typing.Type[W]) -> W: + res = {} + for key, val in t_dict.__annotations__.items(): + if isinstance(val, typing._GenericAlias): # type: ignore + # typing.Type[W] -> W + val_cls = typing_extensions.get_args(val)[0] + res[key] = val_cls + return res # type: ignore + +X = typing.TypeVar('X', bound=typing.Tuple) + +def tuple_to_instance(tup: typing.Type[X]) -> X: + res = [] + for arg in typing_extensions.get_args(tup): + if isinstance(arg, typing._GenericAlias): # type: ignore + # typing.Type[Schema] -> Schema + arg_cls = typing_extensions.get_args(arg)[0] + res.append(arg_cls) + return tuple(res) # type: ignore + +INPUT_TYPES_ALL_INCL_SCHEMA = typing.Union[ + dict, + frozendict.frozendict, + list, + tuple, + decimal.Decimal, + float, + int, + str, + datetime.date, + datetime.datetime, + uuid.UUID, + bool, + None, + bytes, + io.FileIO, + io.BufferedReader, + Schema +] + +INPUT_BASE_TYPES = typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + BoolClass, + NoneClass, + tuple, + bytes, + FileIO +] \ No newline at end of file diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/server.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/server.hbs index 2eb057ae6c9..4f791f8a21a 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/server.hbs +++ b/modules/openapi-json-schema-generator/src/main/resources/python/server.hbs @@ -1,30 +1,29 @@ # coding: utf-8 {{> _helper_header }} +from __future__ import annotations import abc import dataclasses import typing @dataclasses.dataclass -class Server(abc.ABC): +class ServerWithoutVariables(abc.ABC): + url: str + + +@dataclasses.dataclass +class ServerWithVariables(abc.ABC): _url: str - variables: typing.Optional[typing.Dict[str, str]] = None - variable_schemas: typing.Optional[typing.Dict[str, typing.Type['schemas.Schema']]] = None + variables: schemas.DictSchema + variables_cls: typing.Type[schemas.DictSchema] url: str = dataclasses.field(init=False) def __post_init__(self): - if not self.variable_schemas: - self.url = self._url - return url = self._url - for (key, schema) in self.variable_schemas.items(): - if self.variables and key in self.variables: - value = self.variables[key] - cast_value = schema(value) - else: - cast_value = schema.Schema_.default - cast_value = typing.cast(str, cast_value) + assert isinstance (self.variables, self.variables_cls) + for (key, value) in self.variables.items(): + cast_value = typing.cast(str, value) url = url.replace("{" + key + "}", cast_value) self.url = url diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/servers/server.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/servers/server.hbs index b449c6e01c3..18435f062fc 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/servers/server.hbs +++ b/modules/openapi-json-schema-generator/src/main/resources/python/servers/server.hbs @@ -1,59 +1,37 @@ # coding: utf-8 {{> _helper_header }} -from {{packageName}}.shared_imports.server_imports import * {{#with server}} {{#if variables}} - - -class _Variables: - {{#each variables}} - {{> components/schemas/_helper_schema_switch_case identifierPieces=(append identifierPieces "_Variables" jsonPathPiece.camelCase) }} - {{/each}} - -_VariablesSchemas = typing_extensions.TypedDict( - '_VariablesSchemas', - { - {{#each variables}} - "{{{@key.original}}}": typing.Type[_Variables.{{jsonPathPiece.camelCase}}], - {{/each}} - }, - total=False -) - -Variables = typing_extensions.TypedDict( - 'Variables', - { - {{#each variables}} - "{{{@key.original}}}": {{#unless enumValueToName}}typing_extensions.Literal["{{defaultValue.value}}"],{{else}}typing_extensions.Literal[ - {{#each enumValueToName}} - "{{{@key.value}}}", - {{/each}} - ],{{/unless}} - {{/each}} - }, - total=False -) - -def _default_variable_schemas() -> _VariablesSchemas: - return { - {{#each variables}} - "{{{@key.original}}}": _Variables.{{jsonPathPiece.camelCase}}, - {{/each}} - } +from __future__ import annotations +from {{packageName}}.shared_imports.schema_imports import * + {{/if}} +from {{packageName}}.shared_imports.server_imports import * + {{#if variables}} + {{#with variables}} +{{> components/schemas/_helper_getschemas identifierPieces=(append identifierPieces jsonPathPiece.camelCase) }} + {{/with}} {{/if}} @dataclasses.dataclass -class {{jsonPathPiece.camelCase}}(server.Server): +class {{jsonPathPiece.camelCase}}(server.Server{{#if variables}}With{{else}}Without{{/if}}Variables): {{#if description}} ''' {{description}} ''' {{/if}} {{#if variables}} - variables: typing.Optional[Variables] = None - variable_schemas: _VariablesSchemas = dataclasses.field(default_factory=_default_variable_schemas) - {{/if}} + variables: Variables[frozendict.frozendict] = Variables.from_openapi_data_({ + {{#with variables}} + {{#each properties}} + "{{{@key.original}}}": {{jsonPathPiece.camelCase}}.Schema_.default, + {{/each}} + {{/with}} + }) + variables_cls: typing.Type[Variables] = Variables _url: str = "{{url}}" + {{else}} + url: str = "{{url}}" + {{/if}} {{/with}} \ No newline at end of file diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/servers/server_doc.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/servers/server_doc.hbs index b3c962d24d1..b0f9cd373a7 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/servers/server_doc.hbs +++ b/modules/openapi-json-schema-generator/src/main/resources/python/servers/server_doc.hbs @@ -25,9 +25,11 @@ {{headerSize}}# Variables Key | Type | Description | Notes --- | ---- | ----------- | ------ - {{#each variables}} + {{#with variables}} + {{#each properties}} **{{@key.original}}** | {{> _helper_schema_python_types }} | {{#if description}}{{description}}{{/if}} | {{> components/schemas/_helper_notes_msg defaultUser="client" }} - {{/each}} + {{/each}} + {{/with}} {{/if}} {{/if}} {{#if rootServer}} diff --git a/modules/openapi-json-schema-generator/src/main/resources/python/shared_imports/schema_imports.hbs b/modules/openapi-json-schema-generator/src/main/resources/python/shared_imports/schema_imports.hbs index b624bed0115..34b8c318910 100644 --- a/modules/openapi-json-schema-generator/src/main/resources/python/shared_imports/schema_imports.hbs +++ b/modules/openapi-json-schema-generator/src/main/resources/python/shared_imports/schema_imports.hbs @@ -1,3 +1,4 @@ +import dataclasses import datetime import decimal import io diff --git a/modules/openapi-json-schema-generator/src/test/java/org/openapijsonschematools/codegen/DefaultCodegenTest.java b/modules/openapi-json-schema-generator/src/test/java/org/openapijsonschematools/codegen/DefaultCodegenTest.java index b53e4b3d058..544ca2107c1 100644 --- a/modules/openapi-json-schema-generator/src/test/java/org/openapijsonschematools/codegen/DefaultCodegenTest.java +++ b/modules/openapi-json-schema-generator/src/test/java/org/openapijsonschematools/codegen/DefaultCodegenTest.java @@ -197,7 +197,7 @@ public void testGetConsumesInfoAndGetProducesInfo() throws Exception { CodegenOperation coUpdate = codegen.fromOperation(updateOperationWithRef, getOperationPath("somepath", "post")); Assert.assertTrue(!coUpdate.requestBody.content.isEmpty()); Assert.assertEquals(coUpdate.requestBody.content.size(), 2); - CodegenKey ck = codegen.getKey("application/json"); + CodegenKey ck = codegen.getKey("application/json", "misc"); Assert.assertTrue(coUpdate.requestBody.content.containsKey(ck)); Assert.assertTrue(!coUpdate.produces.isEmpty()); Assert.assertEquals(coUpdate.produces.size(), 1); @@ -268,10 +268,10 @@ public void testDateTimeFormParameterHasDefaultValue() { RequestBody reqBody = openAPI.getPaths().get("/thingy/{date}").getPost().getRequestBody(); CodegenRequestBody codegenParameter = codegen.fromRequestBody(reqBody, "#/paths/~1thingy~1{date}/post/requestBody"); - CodegenKey ck = codegen.getKey("application/x-www-form-urlencoded"); + CodegenKey ck = codegen.getKey("application/x-www-form-urlencoded", "misc"); Assert.assertNull(codegenParameter.content.get(ck).schema.refInfo); - CodegenKey propertyKey = codegen.getKey("visitDate"); + CodegenKey propertyKey = codegen.getKey("visitDate", "misc"); assertEquals(codegenParameter.content.get(ck).schema.properties.get(propertyKey).defaultValue.value.toString(), "1971-12-19T03:39:57-08:00"); } @@ -645,7 +645,7 @@ public void testDiscriminator() { mappedModels.add(new CodegenDiscriminator.MappedModel("Cat", "Cat")); mappedModels.add(new CodegenDiscriminator.MappedModel("Dog", "Dog")); - CodegenKey ck = codegen.getKey(propertyName); + CodegenKey ck = codegen.getKey(propertyName, "misc"); CodegenDiscriminator expectedDiscriminator = new CodegenDiscriminator(ck, null, mappedModels); Assert.assertEquals(discriminator, expectedDiscriminator); assertEquals(animalModel.hasDiscriminatorWithNonEmptyMapping(), true); @@ -695,7 +695,7 @@ public void testComposedSchemaAllOfDiscriminatorMap() { String propertyName = "petType"; String propertyBaseName = propertyName; - CodegenKey ck = codegen.getKey(propertyName); + CodegenKey ck = codegen.getKey(propertyName, "misc"); CodegenDiscriminator emptyMapDisc = new CodegenDiscriminator(ck, null, new TreeSet<>()); // all leaf Schemas have discriminators with PropertyName/BaseName + empty discriminator maps @@ -718,7 +718,7 @@ public void testComposedSchemaAllOfDiscriminatorMap() { } hs.add(new CodegenDiscriminator.MappedModel("Reptile", codegen.toModelName("Reptile", null))); - CodegenKey petDiscPropName = codegen.getKey(propertyName); + CodegenKey petDiscPropName = codegen.getKey(propertyName, "misc"); CodegenDiscriminator petDisc = new CodegenDiscriminator(petDiscPropName, null, hs); modelName = "Pet"; sc = openAPI.getComponents().getSchemas().get(modelName); @@ -736,7 +736,7 @@ public void testComposedSchemaAllOfDiscriminatorMap() { for (String reptileModelName : reptileModelNames) { hs.add(new CodegenDiscriminator.MappedModel(reptileModelName, codegen.toModelName(reptileModelName, null))); } - CodegenKey reptileDiscPropName = codegen.getKey(propertyName); + CodegenKey reptileDiscPropName = codegen.getKey(propertyName, "misc"); CodegenDiscriminator reptileDisc = new CodegenDiscriminator(reptileDiscPropName, null, hs); modelName = "Reptile"; sc = openAPI.getComponents().getSchemas().get(modelName); @@ -754,7 +754,7 @@ public void testComposedSchemaAllOfDiscriminatorMap() { for (String myPetName : myPetNames) { hs.add(new CodegenDiscriminator.MappedModel(myPetName, codegen.toModelName(myPetName, null))); } - CodegenKey myPetDiscPropName = codegen.getKey(propertyName); + CodegenKey myPetDiscPropName = codegen.getKey(propertyName, "misc"); CodegenDiscriminator myPetDisc = new CodegenDiscriminator(myPetDiscPropName, null, hs); modelName = "MyPets"; sc = openAPI.getComponents().getSchemas().get(modelName); @@ -833,7 +833,7 @@ public void testComposedSchemaAllOfDiscriminatorMapLegacy() { String propertyName = "petType"; String propertyBaseName = propertyName; - CodegenKey ck = codegen.getKey(propertyName); + CodegenKey ck = codegen.getKey(propertyName, "misc"); CodegenDiscriminator emptyMapDisc = new CodegenDiscriminator(ck, null, null); // all leaf Schemas have discriminators with PropertyName/BaseName + empty discriminator maps @@ -854,7 +854,7 @@ public void testComposedSchemaAllOfDiscriminatorMapLegacy() { hs.add(new CodegenDiscriminator.MappedModel(leafModelName, codegen.toModelName(leafModelName, null))); } hs.add(new CodegenDiscriminator.MappedModel("Reptile", codegen.toModelName("Reptile", null))); - CodegenKey petDiscPropName = codegen.getKey(propertyName); + CodegenKey petDiscPropName = codegen.getKey(propertyName, "misc"); CodegenDiscriminator petDisc = new CodegenDiscriminator(petDiscPropName, null, hs); modelName = "Pet"; sc = openAPI.getComponents().getSchemas().get(modelName); @@ -871,7 +871,7 @@ public void testComposedSchemaAllOfDiscriminatorMapLegacy() { for (String reptileModelName : reptileModelNames) { hs.add(new CodegenDiscriminator.MappedModel(reptileModelName, codegen.toModelName(reptileModelName, null))); } - CodegenKey reptileDiscPropName = codegen.getKey(propertyName); + CodegenKey reptileDiscPropName = codegen.getKey(propertyName, "misc"); CodegenDiscriminator reptileDisc = new CodegenDiscriminator(reptileDiscPropName, null, hs); modelName = "Reptile"; sc = openAPI.getComponents().getSchemas().get(modelName); @@ -883,7 +883,7 @@ public void testComposedSchemaAllOfDiscriminatorMapLegacy() { Assert.assertNull(reptile.discriminator); // the MyPets discriminator contains Cat and Lizard - CodegenKey myPetDiscPropName = codegen.getKey(propertyName); + CodegenKey myPetDiscPropName = codegen.getKey(propertyName, "misc"); CodegenDiscriminator myPetDisc = new CodegenDiscriminator(myPetDiscPropName, null, hs); hs.clear(); modelName = "MyPets"; @@ -1275,7 +1275,7 @@ private void verifyLizardDiscriminator(CodegenDiscriminator discriminator) { String propertyBaseName = prop; Map mapping = null; TreeSet mappedModels = new TreeSet<>(); - CodegenKey testPropName = new DefaultCodegen().getKey(propertyName); + CodegenKey testPropName = new DefaultCodegen().getKey(propertyName, "misc"); CodegenDiscriminator test = new CodegenDiscriminator(testPropName, mapping, mappedModels); assertEquals(discriminator, test); } @@ -1288,7 +1288,7 @@ private void verifyReptileDiscriminator(CodegenDiscriminator discriminator) { TreeSet mappedModels = new TreeSet<>(); mappedModels.add(new CodegenDiscriminator.MappedModel("Lizard", "Lizard")); mappedModels.add(new CodegenDiscriminator.MappedModel("Snake", "Snake")); - CodegenKey expectedDiscriminatorPropName = new DefaultCodegen().getKey(propertyName); + CodegenKey expectedDiscriminatorPropName = new DefaultCodegen().getKey(propertyName, "misc"); CodegenDiscriminator expectedDiscriminator = new CodegenDiscriminator(expectedDiscriminatorPropName, mapping, mappedModels); assertEquals(discriminator, expectedDiscriminator); } @@ -1301,7 +1301,7 @@ private void verifyMyPetsDiscriminator(CodegenDiscriminator discriminator) { TreeSet mappedModels = new TreeSet<>(); mappedModels.add(new CodegenDiscriminator.MappedModel("Cat", "Cat")); mappedModels.add(new CodegenDiscriminator.MappedModel("Lizard", "Lizard")); - CodegenKey expectedDiscriminatorPropName = new DefaultCodegen().getKey(propertyName); + CodegenKey expectedDiscriminatorPropName = new DefaultCodegen().getKey(propertyName, "misc"); CodegenDiscriminator expectedDiscriminator = new CodegenDiscriminator(expectedDiscriminatorPropName, mapping, mappedModels); assertEquals(discriminator, expectedDiscriminator); } @@ -1340,7 +1340,7 @@ public void verifyXDiscriminatorValue() { mappedModels.add(new CodegenDiscriminator.MappedModel("DailySubObj", "DailySubObj")); mappedModels.add(new CodegenDiscriminator.MappedModel("sub-obj", "SubObj")); mappedModels.add(new CodegenDiscriminator.MappedModel("SubObj", "SubObj")); - CodegenKey expectedDiscriminatorPropName = new DefaultCodegen().getKey(propertyName); + CodegenKey expectedDiscriminatorPropName = new DefaultCodegen().getKey(propertyName, "misc"); CodegenDiscriminator expectedDiscriminator = new CodegenDiscriminator(expectedDiscriminatorPropName, mapping, mappedModels); assertEquals(cm.discriminator, expectedDiscriminator); } @@ -1411,9 +1411,9 @@ public void testLeadingSlashIsAddedIfMissing() { codegen.setOpenAPI(openAPI); TreeMap paths = codegen.fromPaths(openAPI.getPaths()); - CodegenKey path1 = codegen.getKey("/here"); + CodegenKey path1 = codegen.getKey("/here", "paths"); Assert.assertTrue(paths.containsKey(path1)); - CodegenKey path2 = codegen.getKey("/some/path"); + CodegenKey path2 = codegen.getKey("/some/path", "paths"); Assert.assertTrue(paths.containsKey(path2)); } @@ -1465,7 +1465,7 @@ public void testNullableProperty() { "#/components/schemas/User", "#/components/schemas/User" ); - CodegenKey key = codegen.getKey("address"); + CodegenKey key = codegen.getKey("address", "misc"); Assert.assertTrue(userModel.properties.get(key).nullable); } @@ -1723,7 +1723,7 @@ private void verifyPersonDiscriminator(CodegenDiscriminator discriminator) { mappedModels.add(new CodegenDiscriminator.MappedModel("c", "Child")); mappedModels.add(new CodegenDiscriminator.MappedModel("Adult", "Adult")); mappedModels.add(new CodegenDiscriminator.MappedModel("Child", "Child")); - CodegenKey expectedDiscriminatorPropName = new DefaultCodegen().getKey(propertyName); + CodegenKey expectedDiscriminatorPropName = new DefaultCodegen().getKey(propertyName, "misc"); CodegenDiscriminator expectedDiscriminator = new CodegenDiscriminator(expectedDiscriminatorPropName, mapping, mappedModels); Assert.assertEquals(discriminator, expectedDiscriminator); } @@ -1807,7 +1807,7 @@ public void schemaMapping() { assertEquals(codegenModel.properties.size(), 1); - Assert.assertEquals(codegenModel.properties.get(codegen.getKey("typeAlias")).refInfo.refClass, "TypeAlias"); + Assert.assertEquals(codegenModel.properties.get(codegen.getKey("typeAlias", "misc")).refInfo.refClass, "TypeAlias"); } @Test @@ -1856,7 +1856,7 @@ public void arrayInnerReferencedSchemaMarkedAsModel_30() { CodegenRequestBody codegenParameter = codegen.fromRequestBody(body, "#/paths/~1examples/post/requestBody"); - CodegenKey ck = codegen.getKey("application/json"); + CodegenKey ck = codegen.getKey("application/json", "misc"); Assert.assertTrue(codegenParameter.content.get(ck).schema.types.contains("array")); Assert.assertTrue(codegenParameter.content.get(ck).schema.items.refInfo != null); Assert.assertTrue(codegenParameter.content.get(ck).schema.items.refInfo.refClass != null); @@ -2047,7 +2047,7 @@ public void testItemsPresent() { "#/components/schemas/" + modelName, "#/components/schemas/" + modelName ); - CodegenKey ck = codegen.getKey("arrayProp"); + CodegenKey ck = codegen.getKey("arrayProp", "misc"); assertEquals(cm.properties.get(ck).items.maximum, "7"); String path; @@ -2058,7 +2058,7 @@ public void testItemsPresent() { operation = openAPI.getPaths().get(path).getPost(); co = codegen.fromOperation(operation, getOperationPath(path, "post")); assertEquals(co.pathParams.get(0).schema.refInfo.ref.items.maximum, "7"); // disabled because refed - CodegenKey applicationJson = codegen.getKey("application/json"); + CodegenKey applicationJson = codegen.getKey("application/json", "misc"); assertEquals(co.requestBody.content.get(applicationJson).schema.refInfo.ref.items.maximum, "7"); // disabled because refed assertEquals(co.responses.get("200").content.get(applicationJson).schema.refInfo.ref.items.maximum, "7"); // disabled because refed @@ -2161,20 +2161,20 @@ public void testAdditionalPropertiesPresentInModelProperties() { "#/components/schemas/" + modelName, "#/components/schemas/" + modelName ); - CodegenKey ck = codegen.getKey("map_with_additional_properties_unset"); + CodegenKey ck = codegen.getKey("map_with_additional_properties_unset", "misc"); mapWithAddPropsUnset = cm.properties.get(ck); assertEquals(mapWithAddPropsUnset.additionalProperties, null); assertEquals(mapWithAddPropsUnset.refInfo.refClass, "AdditionalPropertiesUnset"); - mapWithAddPropsTrue = cm.properties.get(codegen.getKey("map_with_additional_properties_true")); + mapWithAddPropsTrue = cm.properties.get(codegen.getKey("map_with_additional_properties_true", "misc")); assertEquals(mapWithAddPropsTrue.additionalProperties, null); assertEquals(mapWithAddPropsTrue.refInfo.refClass, "AdditionalPropertiesTrue"); - mapWithAddPropsFalse = cm.properties.get(codegen.getKey("map_with_additional_properties_false")); + mapWithAddPropsFalse = cm.properties.get(codegen.getKey("map_with_additional_properties_false", "misc")); assertEquals(mapWithAddPropsFalse.additionalProperties, null); assertEquals(mapWithAddPropsFalse.refInfo.refClass, "AdditionalPropertiesFalse"); - mapWithAddPropsSchema = cm.properties.get(codegen.getKey("map_with_additional_properties_schema")); + mapWithAddPropsSchema = cm.properties.get(codegen.getKey("map_with_additional_properties_schema", "misc")); assertEquals(mapWithAddPropsSchema.additionalProperties, null); assertEquals(mapWithAddPropsSchema.refInfo.refClass, "AdditionalPropertiesSchema"); @@ -2186,18 +2186,18 @@ public void testAdditionalPropertiesPresentInModelProperties() { "#/components/schemas/" + modelName ); - mapWithAddPropsUnset = cm.properties.get(codegen.getKey("map_with_additional_properties_unset")); + mapWithAddPropsUnset = cm.properties.get(codegen.getKey("map_with_additional_properties_unset", "misc")); assertEquals(mapWithAddPropsUnset.additionalProperties, null); - mapWithAddPropsTrue = cm.properties.get(codegen.getKey("map_with_additional_properties_true")); - assertEquals(mapWithAddPropsTrue.additionalProperties, anyTypeSchema); + mapWithAddPropsTrue = cm.properties.get(codegen.getKey("map_with_additional_properties_true", "misc")); + assertNotNull(mapWithAddPropsTrue.additionalProperties); assertTrue(mapWithAddPropsTrue.additionalProperties.isBooleanSchemaTrue); - mapWithAddPropsFalse = cm.properties.get(codegen.getKey("map_with_additional_properties_false")); + mapWithAddPropsFalse = cm.properties.get(codegen.getKey("map_with_additional_properties_false", "misc")); assertNotNull(mapWithAddPropsFalse.additionalProperties); assertTrue(mapWithAddPropsFalse.additionalProperties.isBooleanSchemaFalse); - mapWithAddPropsSchema = cm.properties.get(codegen.getKey("map_with_additional_properties_schema")); + mapWithAddPropsSchema = cm.properties.get(codegen.getKey("map_with_additional_properties_schema", "misc")); assertEquals(mapWithAddPropsSchema.additionalProperties, stringCp); } @@ -2305,36 +2305,36 @@ public void testAdditionalPropertiesPresentInResponses() { operation = openAPI.getPaths().get(path).getPost(); co = codegen.fromOperation(operation, getOperationPath(path, "post")); mapWithAddPropsUnset = co.responses.get("200"); - CodegenKey ck = codegen.getKey("application/json"); + CodegenKey ck = codegen.getKey("application/json", "misc"); assertEquals(mapWithAddPropsUnset.content.get(ck).schema.refInfo.ref.additionalProperties, null); mapWithAddPropsTrue = co.responses.get("201"); - ck = codegen.getKey("application/xml"); + ck = codegen.getKey("application/xml", "misc"); assertNotNull(mapWithAddPropsTrue.content.get(ck).schema.refInfo.ref.additionalProperties); assertTrue(mapWithAddPropsTrue.content.get(ck).schema.refInfo.ref.additionalProperties.isBooleanSchemaTrue); mapWithAddPropsFalse = co.responses.get("202"); - ck = codegen.getKey("application/x-www-form-urlencoded"); + ck = codegen.getKey("application/x-www-form-urlencoded", "misc"); assertNotNull(mapWithAddPropsFalse.content.get(ck).schema.refInfo.ref.additionalProperties); assertTrue(mapWithAddPropsFalse.content.get(ck).schema.refInfo.ref.additionalProperties.isBooleanSchemaFalse); mapWithAddPropsSchema = co.responses.get("203"); - ck = codegen.getKey("application/*"); + ck = codegen.getKey("application/*", "misc"); assertNotNull(mapWithAddPropsSchema.content.get(ck).schema.refInfo); path = "/additional_properties/"; operation = openAPI.getPaths().get(path).getPost(); co = codegen.fromOperation(operation, getOperationPath(path, "post")); mapWithAddPropsUnset = co.responses.get("200"); - ck = codegen.getKey("application/json"); + ck = codegen.getKey("application/json", "misc"); assertEquals(mapWithAddPropsUnset.content.get(ck).schema.additionalProperties, null); mapWithAddPropsTrue = co.responses.get("201"); - ck = codegen.getKey("application/xml"); + ck = codegen.getKey("application/xml", "misc"); assertNotNull(mapWithAddPropsTrue.content.get(ck).schema.additionalProperties); assertTrue(mapWithAddPropsTrue.content.get(ck).schema.additionalProperties.isBooleanSchemaTrue); mapWithAddPropsFalse = co.responses.get("202"); - ck = codegen.getKey("application/x-www-form-urlencoded"); + ck = codegen.getKey("application/x-www-form-urlencoded", "misc"); assertNotNull(mapWithAddPropsFalse.content.get(ck).schema.additionalProperties); assertTrue(mapWithAddPropsFalse.content.get(ck).schema.additionalProperties.isBooleanSchemaFalse); mapWithAddPropsSchema = co.responses.get("203"); - ck = codegen.getKey("application/*"); + ck = codegen.getKey("application/*", "misc"); assertTrue(mapWithAddPropsSchema.content.get(ck).schema.additionalProperties.types.contains("string")); } @@ -2344,12 +2344,6 @@ public void testAdditionalPropertiesAnyType() { final DefaultCodegen codegen = new DefaultCodegen(); codegen.setOpenAPI(openAPI); - CodegenSchema anyTypeSchema = codegen.fromSchema( - new Schema(), - "#/components/schemas/AdditionalPropertiesTrue", - "#/components/schemas/AdditionalPropertiesTrue/properties/child/additionalProperties" - ); - Schema sc; CodegenSchema cm; @@ -2359,8 +2353,8 @@ public void testAdditionalPropertiesAnyType() { "#/components/schemas/AdditionalPropertiesTrue", "#/components/schemas/AdditionalPropertiesTrue" ); - CodegenKey ck = codegen.getKey("child"); - assertEquals(cm.properties.get(ck).additionalProperties, anyTypeSchema); + CodegenKey ck = codegen.getKey("child", "misc"); + CodegenSchema trueSchema = cm.properties.get(ck).additionalProperties; sc = openAPI.getComponents().getSchemas().get("AdditionalPropertiesAnyType"); cm = codegen.fromSchema( @@ -2368,7 +2362,10 @@ public void testAdditionalPropertiesAnyType() { "#/components/schemas/AdditionalPropertiesAnyType", "#/components/schemas/AdditionalPropertiesAnyType" ); - assertEquals(cm.properties.get(ck).additionalProperties, anyTypeSchema); + CodegenSchema anyTypeSchema = cm.properties.get(ck).additionalProperties; + assertEquals(anyTypeSchema, trueSchema); + assertTrue(anyTypeSchema.isBooleanSchemaTrue); + assertTrue(trueSchema.isBooleanSchemaTrue); } @Test @@ -2407,9 +2404,9 @@ public void testIsXPresence() { "#/components/schemas/" + modelName, "#/components/schemas/" + modelName ); - CodegenKey ck = codegen.getKey("nullProp"); + CodegenKey ck = codegen.getKey("nullProp", "misc"); assertTrue(cm.properties.get(ck).types.contains("null")); - assertTrue(cm.properties.get(codegen.getKey("listOfNulls")).items.types.contains("null")); + assertTrue(cm.properties.get(codegen.getKey("listOfNulls", "misc")).items.types.contains("null")); assertTrue(cm.additionalProperties.types.contains("null")); modelName = "ArrayOfNulls"; @@ -2428,7 +2425,7 @@ public void testIsXPresence() { "#/components/schemas/" + modelName, "#/components/schemas/" + modelName ); - ck = codegen.getKey("dateWithValidation"); + ck = codegen.getKey("dateWithValidation", "misc"); assertTrue(cm.properties.get(ck).types.contains("string")); assertEquals(cm.properties.get(ck).format, "date"); @@ -2441,7 +2438,7 @@ public void testIsXPresence() { co = codegen.fromOperation(operation, getOperationPath(path, "post")); assertTrue(co.pathParams.get(0).schema.refInfo.ref.types.contains("string")); assertEquals(co.pathParams.get(0).schema.refInfo.ref.format, "date"); - CodegenKey applicationJson = codegen.getKey("application/json"); + CodegenKey applicationJson = codegen.getKey("application/json", "misc"); assertTrue(co.requestBody.content.get(applicationJson).schema.refInfo.ref.types.contains("string")); assertEquals(co.requestBody.content.get(applicationJson).schema.refInfo.ref.format, "date"); assertTrue(co.responses.get("200").content.get(applicationJson).schema.refInfo.ref.types.contains("string")); @@ -2474,7 +2471,7 @@ public void testIsXPresence() { "#/components/schemas/" + modelName, "#/components/schemas/" + modelName ); - ck = codegen.getKey("dateWithValidation"); + ck = codegen.getKey("dateWithValidation", "misc"); assertTrue(cm.properties.get(ck).types.contains("string")); assertEquals(cm.properties.get(ck).format, "date-time"); @@ -2737,7 +2734,7 @@ public void testBodyAndResponseGetHasValidation() { path = "/" + modelName; operation = openAPI.getPaths().get(path).getPost(); co = codegen.fromOperation(operation, getOperationPath(path, "post")); - CodegenKey ck = codegen.getKey("application/json"); + CodegenKey ck = codegen.getKey("application/json", "misc"); assertTrue(co.requestBody.content.get(ck).schema.hasValidation()); assertTrue(co.responses.get("200").content.get(ck).schema.hasValidation()); } @@ -2773,7 +2770,7 @@ public void testVarsAndRequiredVarsPresent() { assertEquals(co.pathParams.get(0).schema.properties.size(), 3); assertEquals(co.pathParams.get(0).schema.requiredProperties.size(), 2); - CodegenKey applicationJson = codegen.getKey("application/json"); + CodegenKey applicationJson = codegen.getKey("application/json", "misc"); assertEquals(co.requestBody.content.get(applicationJson).schema.properties.size(), 3); assertEquals(co.requestBody.content.get(applicationJson).schema.requiredProperties.size(), 2); @@ -2788,7 +2785,7 @@ public void testVarsAndRequiredVarsPresent() { "#/components/schemas/" + modelName, "#/components/schemas/" + modelName ); - CodegenKey ck = codegen.getKey("a"); + CodegenKey ck = codegen.getKey("a", "misc"); CodegenSchema cp = cm.properties.get(ck); assertEquals(cp.properties.size(), 3); assertEquals(cp.requiredProperties.size(), 2); @@ -2869,7 +2866,7 @@ public void testHasVarsInProperty() { "#/components/schemas/" + modelName, "#/components/schemas/" + modelName ); - CodegenKey ck = codegen.getKey(hm.get(modelName)); + CodegenKey ck = codegen.getKey(hm.get(modelName), "misc"); assertTrue(cm.properties.get(ck).properties == null); } @@ -2908,7 +2905,7 @@ public void testHasVarsInParameter() { operation = openAPI.getPaths().get(path).getPost(); co = codegen.fromOperation(operation, getOperationPath(path, "post")); assertTrue(co.pathParams.get(0).schema.properties == null); - CodegenKey ck = codegen.getKey("application/json"); + CodegenKey ck = codegen.getKey("application/json", "misc"); assertTrue(co.requestBody.content.get(ck).schema.properties == null); path = "/object_with_optional_and_required_props/{objectData}"; @@ -2933,7 +2930,7 @@ public void testHasVarsInResponse() { path = "/additional_properties/"; operation = openAPI.getPaths().get(path).getPost(); co = codegen.fromOperation(operation, getOperationPath(path, "post")); - CodegenKey applicationJson = codegen.getKey("application/json"); + CodegenKey applicationJson = codegen.getKey("application/json", "misc"); assertTrue(co.responses.get("200").content.get(applicationJson).schema.properties == null); path = "/object_with_optional_and_required_props/{objectData}"; @@ -3110,7 +3107,7 @@ public void testHasRequiredInResponses() { "ComposedHasAllofReqPropNoPropertiesNoRequired", "ComposedHasAllofReqPropHasPropertiesNoRequired" )); - CodegenKey ck = codegen.getKey("application/json"); + CodegenKey ck = codegen.getKey("application/json", "misc"); for (CodegenResponse cr : co.responses.values()) { LinkedHashMap reqProps = cr.content.get(ck).schema.requiredProperties; if (modelNamesWithoutRequired.contains(cr.description)) { @@ -3173,17 +3170,17 @@ public void testBooleansSetForIntSchemas() { assertTrue(cm.types.contains("object")); CodegenSchema cp; - CodegenKey ck = codegen.getKey("UnboundedInteger"); + CodegenKey ck = codegen.getKey("UnboundedInteger", "misc"); cp = cm.properties.get(ck); assertTrue(cp.types.contains("integer")); assertNull(cp.format); - ck = codegen.getKey("Int32"); + ck = codegen.getKey("Int32", "misc"); cp = cm.properties.get(ck); assertTrue(cp.types.contains("integer")); assertEquals(cp.format, "int32"); - ck = codegen.getKey("Int64"); + ck = codegen.getKey("Int64", "misc"); cp = cm.properties.get(ck); assertTrue(cp.types.contains("integer")); assertEquals(cp.format, "int64"); @@ -3201,7 +3198,7 @@ public void testBooleansSetForIntSchemas() { assertTrue(cpa.schema.types.contains("integer")); assertNull(cpa.schema.format); CodegenRequestBody crb = co.requestBody; - ck = codegen.getKey("application/json"); + ck = codegen.getKey("application/json", "misc"); assertTrue(crb.content.get(ck).schema.types.contains("integer")); assertNull(crb.content.get(ck).schema.format); cr = co.responses.get("200"); @@ -3412,7 +3409,7 @@ public void testComposedResponseTypes() { path = "/ComposedObject"; co = codegen.fromOperation(openAPI.getPaths().get(path).getGet(), getOperationPath(path, "get")); cr = co.responses.get("200"); - CodegenKey ck = codegen.getKey("application/json"); + CodegenKey ck = codegen.getKey("application/json", "misc"); assertTrue(cr.content.get(ck).schema.types.contains("object")); path = "/ComposedNumber"; @@ -3463,7 +3460,7 @@ public void testComposedRequestBodyTypes() { path = "/ComposedObject"; co = codegen.fromOperation(openAPI.getPaths().get(path).getGet(), getOperationPath(path, "get")); crb = co.requestBody; - CodegenKey ck = codegen.getKey("application/json"); + CodegenKey ck = codegen.getKey("application/json", "misc"); assertTrue(crb.content.get(ck).schema.types.contains("object")); path = "/ComposedNumber"; @@ -3564,7 +3561,7 @@ public void testByteArrayTypeInSchemas() { path = "/TxRxByteArray"; co = codegen.fromOperation(openAPI.getPaths().get(path).getPost(), getOperationPath(path, "post")); crb = co.requestBody; - CodegenKey ck = codegen.getKey("application/json"); + CodegenKey ck = codegen.getKey("application/json", "misc"); assertTrue(crb.content.get(ck).schema.types.contains("string")); assertEquals(crb.content.get(ck).schema.format, "byte"); CodegenResponse cr = co.responses.get("200"); @@ -3577,7 +3574,7 @@ public void testByteArrayTypeInSchemas() { "#/components/schemas/" + modelName, "#/components/schemas/" + modelName ); - ck = codegen.getKey("byteArray"); + ck = codegen.getKey("byteArray", "misc"); CodegenSchema pr = m.properties.get(ck); assertTrue(pr.types.contains("string")); assertEquals(pr.format, "byte"); @@ -3600,10 +3597,10 @@ public void testResponses() { co = codegen.fromOperation(operation, getOperationPath(path, "get")); //assertTrue(co.hasErrorResponseObject); cr = co.responses.get("200"); - CodegenKey applicationJson = codegen.getKey("application/json"); + CodegenKey applicationJson = codegen.getKey("application/json", "misc"); assertTrue(cr.content.get(applicationJson).schema.refInfo.refClass != null); cr = co.responses.get("500"); - CodegenKey applicationApplication = codegen.getKey("application/application"); + CodegenKey applicationApplication = codegen.getKey("application/application", "misc"); assertTrue(cr.content.get(applicationApplication).schema.refInfo.refClass != null); path = "/pet"; @@ -3641,7 +3638,7 @@ public void testRequestParameterContent() { CodegenParameter coordinatesInlineSchema = co.queryParams.get(0); LinkedHashMap content = coordinatesInlineSchema.content; assertNotNull(content); - CodegenKey ck = codegen.getKey("application/json"); + CodegenKey ck = codegen.getKey("application/json", "misc"); assertEquals(content.keySet(), new HashSet<>(Arrays.asList(ck))); CodegenMediaType mt = content.get(ck); assertNull(mt.encoding); @@ -3673,8 +3670,8 @@ public void testRequestBodyContent() { CodegenRequestBody bodyParameter = co.requestBody; LinkedHashMap content = bodyParameter.content; assertNotNull(content); - CodegenKey jsonKey = codegen.getKey("application/json"); - CodegenKey textKey = codegen.getKey("text/plain"); + CodegenKey jsonKey = codegen.getKey("application/json", "misc"); + CodegenKey textKey = codegen.getKey("text/plain", "misc"); assertEquals(content.keySet(), new HashSet<>(Arrays.asList(jsonKey, textKey))); CodegenMediaType mt = content.get(jsonKey); assertNull(mt.encoding); @@ -3695,8 +3692,8 @@ public void testRequestBodyContent() { bodyParameter = co.requestBody; content = bodyParameter.content; assertNotNull(content); - CodegenKey applicationJson = codegen.getKey("application/json"); - CodegenKey textPlain = codegen.getKey("text/plain"); + CodegenKey applicationJson = codegen.getKey("application/json", "misc"); + CodegenKey textPlain = codegen.getKey("text/plain", "misc"); assertEquals(content.keySet(), new HashSet<>(Arrays.asList(applicationJson, textPlain))); mt = content.get(applicationJson); assertNull(mt.encoding); @@ -3724,7 +3721,7 @@ public void testRequestBodyContent() { path = "/requestBodyWithEncodingTypes"; co = codegen.fromOperation(openAPI.getPaths().get(path).getPost(), getOperationPath(path, "post")); - CodegenKey applicationXWwwFormUrlencoded = codegen.getKey("application/x-www-form-urlencoded"); + CodegenKey applicationXWwwFormUrlencoded = codegen.getKey("application/x-www-form-urlencoded", "misc"); CodegenSchema formSchema = co.requestBody.content.get(applicationXWwwFormUrlencoded).schema; assertEquals(formSchema.properties.size(), 6); @@ -3749,7 +3746,7 @@ public void testResponseContentAndHeader() { CodegenParameter coordinatesInlineSchema = co.queryParams.get(0); LinkedHashMap content = coordinatesInlineSchema.content; assertNotNull(content); - CodegenKey ck = codegen.getKey("application/json"); + CodegenKey ck = codegen.getKey("application/json", "misc"); assertEquals(content.keySet(), new HashSet<>(Arrays.asList(ck))); CodegenParameter schemaParam = co.queryParams.get(2); @@ -3772,8 +3769,8 @@ public void testResponseContentAndHeader() { assertEquals(header2.refInfo.ref.schema.jsonPathPiece.original, "schema"); content = cr.content; - CodegenKey applicationJson = codegen.getKey("application/json"); - CodegenKey textPlain = codegen.getKey("text/plain"); + CodegenKey applicationJson = codegen.getKey("application/json", "misc"); + CodegenKey textPlain = codegen.getKey("text/plain", "misc"); assertEquals(content.keySet(), new HashSet<>(Arrays.asList(applicationJson, textPlain))); CodegenMediaType mt = content.get(applicationJson); assertNull(mt.encoding); @@ -3837,7 +3834,7 @@ public void testUnalias() { RequestBody reqBody = openAPI.getPaths().get("/thingy/{date}").getPost().getRequestBody(); CodegenRequestBody codegenParameter = codegen.fromRequestBody(reqBody, "#/paths/~1thingy~1{date}/post/requestBody"); - CodegenKey ck = codegen.getKey("application/x-www-form-urlencoded"); + CodegenKey ck = codegen.getKey("application/x-www-form-urlencoded", "misc"); Assert.assertNotNull(codegenParameter.content.get(ck).schema.refInfo); } @@ -3862,7 +3859,7 @@ public void testFromPropertyRequiredAndOptional() { "#/components/schemas/" + modelName, "#/components/schemas/" + modelName ); - CodegenKey ck = codegen.getKey("foo"); + CodegenKey ck = codegen.getKey("foo", "misc"); Assert.assertEquals(fooRequired.properties.get(ck).jsonPathPiece.original, "foo"); assertEquals(fooRequired.requiredProperties.size(), 1); diff --git a/modules/openapi-json-schema-generator/src/test/java/org/openapijsonschematools/codegen/DefaultGeneratorTest.java b/modules/openapi-json-schema-generator/src/test/java/org/openapijsonschematools/codegen/DefaultGeneratorTest.java index 65625a286c4..5a36df943d0 100644 --- a/modules/openapi-json-schema-generator/src/test/java/org/openapijsonschematools/codegen/DefaultGeneratorTest.java +++ b/modules/openapi-json-schema-generator/src/test/java/org/openapijsonschematools/codegen/DefaultGeneratorTest.java @@ -305,11 +305,11 @@ public void testNonStrictFromPaths() throws Exception { generator.opts(opts); TreeMap paths = config.fromPaths(openAPI.getPaths()); Assert.assertEquals(paths.size(), 2); - CodegenKey firstPathKey = config.getKey("path1/"); - CodegenKey getKey = config.getKey("get"); + CodegenKey firstPathKey = config.getKey("path1/", "paths"); + CodegenKey getKey = config.getKey("get", "verb"); Assert.assertEquals(firstPathKey.original, "path1/"); Assert.assertEquals(paths.get(firstPathKey).operations.get(getKey).allParams.size(), 0); - CodegenKey secondPathKey = config.getKey("path2/"); + CodegenKey secondPathKey = config.getKey("path2/", "paths"); Assert.assertEquals(secondPathKey.original, "path2/"); Assert.assertEquals(paths.get(secondPathKey).operations.get(getKey).allParams.size(), 1); } @@ -393,7 +393,7 @@ public void testRefModelValidationProperties() { CodegenRequestBody codegenParameter = config.fromRequestBody( body, "#/paths/~1fake~1StringRegex/post/requestBody"); - CodegenKey ck = config.getKey("*/*"); + CodegenKey ck = config.getKey("*/*", "misc"); Assert.assertEquals(codegenParameter.content.get(ck).schema.refInfo.ref.patternInfo.pattern, escapedPattern); // Validate when converting to response diff --git a/samples/openapi3/client/3_0_3_unit_test/python/docs/components/schema/allof_combined_with_anyof_oneof.md b/samples/openapi3/client/3_0_3_unit_test/python/docs/components/schema/allof_combined_with_anyof_oneof.md index f4b70e3d923..a302df0a39f 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/docs/components/schema/allof_combined_with_anyof_oneof.md +++ b/samples/openapi3/client/3_0_3_unit_test/python/docs/components/schema/allof_combined_with_anyof_oneof.md @@ -10,24 +10,24 @@ dict, frozendict.frozendict, str, datetime.date, datetime.datetime, uuid.UUID, i ## allOf Class Name | Input Type | Accessed Type | Description | Notes ------------- | ------------- | ------------- | ------------- | ------------- -[_0](#allof-_0) | dict, frozendict.frozendict, str, datetime.date, datetime.datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader | frozendict.frozendict, str, decimal.Decimal, BoolClass, NoneClass, tuple, bytes, io.FileIO | | +[_0](#allof-_03) | dict, frozendict.frozendict, str, datetime.date, datetime.datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader | frozendict.frozendict, str, decimal.Decimal, BoolClass, NoneClass, tuple, bytes, io.FileIO | | ## anyOf Class Name | Input Type | Accessed Type | Description | Notes ------------- | ------------- | ------------- | ------------- | ------------- -[_0](#anyof-_0) | dict, frozendict.frozendict, str, datetime.date, datetime.datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader | frozendict.frozendict, str, decimal.Decimal, BoolClass, NoneClass, tuple, bytes, io.FileIO | | +[_0](#anyof-_02) | dict, frozendict.frozendict, str, datetime.date, datetime.datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader | frozendict.frozendict, str, decimal.Decimal, BoolClass, NoneClass, tuple, bytes, io.FileIO | | ## oneOf Class Name | Input Type | Accessed Type | Description | Notes ------------- | ------------- | ------------- | ------------- | ------------- [_0](#oneof-_0) | dict, frozendict.frozendict, str, datetime.date, datetime.datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader | frozendict.frozendict, str, decimal.Decimal, BoolClass, NoneClass, tuple, bytes, io.FileIO | | -# allof _0 +# allof _03 ## Type Info Input Type | Accessed Type | Description | Notes ------------ | ------------- | ------------- | ------------- dict, frozendict.frozendict, str, datetime.date, datetime.datetime, uuid.UUID, int, float, decimal.Decimal, bool, None, list, tuple, bytes, io.FileIO, io.BufferedReader | frozendict.frozendict, str, decimal.Decimal, BoolClass, NoneClass, tuple, bytes, io.FileIO | | -# anyof _0 +# anyof _02 ## Type Info Input Type | Accessed Type | Description | Notes diff --git a/samples/openapi3/client/3_0_3_unit_test/python/docs/components/schema/nested_allof_to_check_validation_semantics.md b/samples/openapi3/client/3_0_3_unit_test/python/docs/components/schema/nested_allof_to_check_validation_semantics.md index 4d3961f1e29..586ad0e840a 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/docs/components/schema/nested_allof_to_check_validation_semantics.md +++ b/samples/openapi3/client/3_0_3_unit_test/python/docs/components/schema/nested_allof_to_check_validation_semantics.md @@ -23,9 +23,9 @@ dict, frozendict.frozendict, str, datetime.date, datetime.datetime, uuid.UUID, i ## allOf Class Name | Input Type | Accessed Type | Description | Notes ------------- | ------------- | ------------- | ------------- | ------------- -[_0](#allof-_0-allof-_0) | None | NoneClass | | +[_0](#allof-_0-allof-_02) | None | NoneClass | | -# allof _0 allof _0 +# allof _0 allof _02 ## Type Info Input Type | Accessed Type | Description | Notes diff --git a/samples/openapi3/client/3_0_3_unit_test/python/docs/components/schema/nested_anyof_to_check_validation_semantics.md b/samples/openapi3/client/3_0_3_unit_test/python/docs/components/schema/nested_anyof_to_check_validation_semantics.md index d3a97d0066c..24eea1a6f7c 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/docs/components/schema/nested_anyof_to_check_validation_semantics.md +++ b/samples/openapi3/client/3_0_3_unit_test/python/docs/components/schema/nested_anyof_to_check_validation_semantics.md @@ -23,9 +23,9 @@ dict, frozendict.frozendict, str, datetime.date, datetime.datetime, uuid.UUID, i ## anyOf Class Name | Input Type | Accessed Type | Description | Notes ------------- | ------------- | ------------- | ------------- | ------------- -[_0](#anyof-_0-anyof-_0) | None | NoneClass | | +[_0](#anyof-_0-anyof-_02) | None | NoneClass | | -# anyof _0 anyof _0 +# anyof _0 anyof _02 ## Type Info Input Type | Accessed Type | Description | Notes diff --git a/samples/openapi3/client/3_0_3_unit_test/python/docs/components/schema/nested_items.md b/samples/openapi3/client/3_0_3_unit_test/python/docs/components/schema/nested_items.md index 59b1e59a269..e1600ba1b68 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/docs/components/schema/nested_items.md +++ b/samples/openapi3/client/3_0_3_unit_test/python/docs/components/schema/nested_items.md @@ -21,9 +21,9 @@ list, tuple | tuple | | ## List Items Class Name | Input Type | Accessed Type | Description | Notes ------------- | ------------- | ------------- | ------------- | ------------- -[items](#items-items) | list, tuple | tuple | | +[items](#items-items2) | list, tuple | tuple | | -# Items Items +# Items Items2 ## Type Info Input Type | Accessed Type | Description | Notes @@ -33,9 +33,9 @@ list, tuple | tuple | | ## List Items Class Name | Input Type | Accessed Type | Description | Notes ------------- | ------------- | ------------- | ------------- | ------------- -[items](#items-items-items) | list, tuple | tuple | | +[items](#items-items2-items3) | list, tuple | tuple | | -# Items Items Items +# Items Items2 Items3 ## Type Info Input Type | Accessed Type | Description | Notes diff --git a/samples/openapi3/client/3_0_3_unit_test/python/docs/components/schema/nested_oneof_to_check_validation_semantics.md b/samples/openapi3/client/3_0_3_unit_test/python/docs/components/schema/nested_oneof_to_check_validation_semantics.md index 5e43550dd9a..8bec2c67111 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/docs/components/schema/nested_oneof_to_check_validation_semantics.md +++ b/samples/openapi3/client/3_0_3_unit_test/python/docs/components/schema/nested_oneof_to_check_validation_semantics.md @@ -23,9 +23,9 @@ dict, frozendict.frozendict, str, datetime.date, datetime.datetime, uuid.UUID, i ## oneOf Class Name | Input Type | Accessed Type | Description | Notes ------------- | ------------- | ------------- | ------------- | ------------- -[_0](#oneof-_0-oneof-_0) | None | NoneClass | | +[_0](#oneof-_0-oneof-_02) | None | NoneClass | | -# oneof _0 oneof _0 +# oneof _0 oneof _02 ## Type Info Input Type | Accessed Type | Description | Notes diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/_not.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/_not.py index ef917ed0127..cf5f06288e1 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/_not.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/_not.py @@ -10,6 +10,8 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +_Not: typing_extensions.TypeAlias = schemas.IntSchema[U] + class _Not( schemas.AnyTypeSchema[schemas.T], @@ -21,51 +23,17 @@ class _Not( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - _Not: typing_extensions.TypeAlias = schemas.IntSchema[U] + not_: typing.Type[_Not] = dataclasses.field(default_factory=lambda: _Not) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> _Not[ typing.Union[ frozendict.frozendict, @@ -100,3 +68,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/additionalproperties_allows_a_schema_which_should_validate.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/additionalproperties_allows_a_schema_which_should_validate.py index 8e2e91e33fa..141c2c50833 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/additionalproperties_allows_a_schema_which_should_validate.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/additionalproperties_allows_a_schema_which_should_validate.py @@ -10,6 +10,17 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +AdditionalProperties: typing_extensions.TypeAlias = schemas.BoolSchema[U] +Foo: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] +Bar: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "foo": typing.Type[Foo], + "bar": typing.Type[Bar], + } +) + class AdditionalpropertiesAllowsASchemaWhichShouldValidate( schemas.DictSchema[schemas.T] @@ -21,20 +32,14 @@ class AdditionalpropertiesAllowsASchemaWhichShouldValidate( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - Foo: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - Bar: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - __annotations__ = { - "foo": Foo, - "bar": Bar, - } - AdditionalProperties: typing_extensions.TypeAlias = schemas.BoolSchema[U] + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Schema_.Properties.Foo[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Foo[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -46,7 +51,7 @@ def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Schema_.Propert ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["bar"]) -> Schema_.Properties.Bar[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["bar"]) -> Bar[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -58,7 +63,7 @@ def __getitem__(self, name: typing_extensions.Literal["bar"]) -> Schema_.Propert ]]: ... @typing.overload - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[schemas.BoolClass]: ... + def __getitem__(self, name: str) -> AdditionalProperties[schemas.BoolClass]: ... def __getitem__( self, @@ -75,16 +80,9 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], foo: typing.Union[ - Schema_.Properties.Foo[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + Foo[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -104,16 +102,9 @@ def __new__( io.BufferedReader ] = schemas.unset, bar: typing.Union[ - Schema_.Properties.Bar[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + Bar[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -134,7 +125,7 @@ def __new__( ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, **kwargs: typing.Union[ - Schema_.AdditionalProperties[schemas.BoolClass], + AdditionalProperties[schemas.BoolClass], bool ], ) -> AdditionalpropertiesAllowsASchemaWhichShouldValidate[frozendict.frozendict]: @@ -151,3 +142,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/additionalproperties_are_allowed_by_default.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/additionalproperties_are_allowed_by_default.py index 35e7c31e4db..3c9a5a69a48 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/additionalproperties_are_allowed_by_default.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/additionalproperties_are_allowed_by_default.py @@ -10,6 +10,16 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +Foo: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] +Bar: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "foo": typing.Type[Foo], + "bar": typing.Type[Bar], + } +) + class AdditionalpropertiesAreAllowedByDefault( schemas.AnyTypeSchema[schemas.T], @@ -21,20 +31,14 @@ class AdditionalpropertiesAreAllowedByDefault( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class Properties: - Foo: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - Bar: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - __annotations__ = { - "foo": Foo, - "bar": Bar, - } + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Schema_.Properties.Foo[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Foo[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -46,7 +50,7 @@ def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Schema_.Propert ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["bar"]) -> Schema_.Properties.Bar[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["bar"]) -> Bar[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -82,35 +86,11 @@ def __getitem__( def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, foo: typing.Union[ - Schema_.Properties.Foo[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + Foo[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -130,16 +110,9 @@ def __new__( io.BufferedReader ] = schemas.unset, bar: typing.Union[ - Schema_.Properties.Bar[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + Bar[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -159,25 +132,7 @@ def __new__( io.BufferedReader ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> AdditionalpropertiesAreAllowedByDefault[ typing.Union[ frozendict.frozendict, @@ -214,3 +169,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/additionalproperties_can_exist_by_itself.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/additionalproperties_can_exist_by_itself.py index 29d67307871..9ac63345f54 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/additionalproperties_can_exist_by_itself.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/additionalproperties_can_exist_by_itself.py @@ -10,6 +10,8 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +AdditionalProperties: typing_extensions.TypeAlias = schemas.BoolSchema[U] + class AdditionalpropertiesCanExistByItself( schemas.DictSchema[schemas.T] @@ -21,11 +23,12 @@ class AdditionalpropertiesCanExistByItself( """ - class Schema_: - types = {frozendict.frozendict} - AdditionalProperties: typing_extensions.TypeAlias = schemas.BoolSchema[U] + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[schemas.BoolClass]: + def __getitem__(self, name: str) -> AdditionalProperties[schemas.BoolClass]: # dict_instance[name] accessor return super().__getitem__(name) @@ -34,7 +37,7 @@ def __new__( *args_: typing.Union[dict, frozendict.frozendict], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, **kwargs: typing.Union[ - Schema_.AdditionalProperties[schemas.BoolClass], + AdditionalProperties[schemas.BoolClass], bool ], ) -> AdditionalpropertiesCanExistByItself[frozendict.frozendict]: @@ -49,3 +52,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/additionalproperties_should_not_look_in_applicators.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/additionalproperties_should_not_look_in_applicators.py index 3d63c358e4c..59b5fb746a2 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/additionalproperties_should_not_look_in_applicators.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/additionalproperties_should_not_look_in_applicators.py @@ -10,189 +10,69 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +AdditionalProperties: typing_extensions.TypeAlias = schemas.BoolSchema[U] +Foo: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "foo": typing.Type[Foo], + } +) -class AdditionalpropertiesShouldNotLookInApplicators( + +class _0( schemas.AnyTypeSchema[schemas.T], ): - """NOTE: This class is auto generated by OpenAPI JSON Schema Generator. - Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator - Do not edit the class manually. - """ - - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - AdditionalProperties: typing_extensions.TypeAlias = schemas.BoolSchema[U] - - class AllOf: - - - class _0( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - - class Properties: - Foo: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - __annotations__ = { - "foo": Foo, - } - - - @typing.overload - def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Schema_.Properties.Foo[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: ... - - @typing.overload - def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: ... - - def __getitem__( - self, - name: typing.Union[ - typing_extensions.Literal["foo"], - str - ] - ): - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - foo: typing.Union[ - Schema_.Properties.Foo[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], - schemas.Unset, - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ] = schemas.unset, - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> AdditionalpropertiesShouldNotLookInApplicators.Schema_.AllOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - foo=foo, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AdditionalpropertiesShouldNotLookInApplicators.Schema_.AllOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - classes = [ - _0, - ] + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[schemas.BoolClass]: + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Foo[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + @typing.overload + def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + def __getitem__( + self, + name: typing.Union[ + typing_extensions.Literal["foo"], + str + ] + ): # dict_instance[name] accessor return super().__getitem__(name) def __new__( cls, - *args_: typing.Union[ + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + foo: typing.Union[ + Foo[ + schemas.INPUT_BASE_TYPES + ], + schemas.Unset, dict, frozendict.frozendict, str, @@ -209,10 +89,77 @@ def __new__( bytes, io.FileIO, io.BufferedReader - ], + ] = schemas.unset, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _0[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + foo=foo, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _0[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + +AllOf = typing.Tuple[ + typing.Type[_0[schemas.U]], +] + + +class AdditionalpropertiesShouldNotLookInApplicators( + schemas.AnyTypeSchema[schemas.T], +): + """NOTE: This class is auto generated by OpenAPI JSON Schema Generator. + Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator + + Do not edit the class manually. + """ + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore + + + def __getitem__(self, name: str) -> AdditionalProperties[schemas.BoolClass]: + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, **kwargs: typing.Union[ - Schema_.AdditionalProperties[schemas.BoolClass], + AdditionalProperties[schemas.BoolClass], bool ], ) -> AdditionalpropertiesShouldNotLookInApplicators[ @@ -249,3 +196,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof.py index 4196dc94d37..6abfcd95011 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof.py @@ -10,50 +10,84 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +Bar: typing_extensions.TypeAlias = schemas.IntSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "bar": typing.Type[Bar], + } +) -class Allof( + +class _0( schemas.AnyTypeSchema[schemas.T], ): - """NOTE: This class is auto generated by OpenAPI JSON Schema Generator. - Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator - - Do not edit the class manually. - """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AllOf: - - - class _0( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - required = { - "bar", - } - - class Properties: - Bar: typing_extensions.TypeAlias = schemas.IntSchema[U] - __annotations__ = { - "bar": Bar, - } - - - @property - def bar(self) -> Schema_.Properties.Bar[decimal.Decimal]: - return self.__getitem__("bar") - - @typing.overload - def __getitem__(self, name: typing_extensions.Literal["bar"]) -> Schema_.Properties.Bar[decimal.Decimal]: ... - - @typing.overload - def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + required: typing.FrozenSet[str] = frozenset({ + "bar", + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + + + @property + def bar(self) -> Bar[decimal.Decimal]: + return self.__getitem__("bar") + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["bar"]) -> Bar[decimal.Decimal]: ... + + @typing.overload + def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + def __getitem__( + self, + name: typing.Union[ + typing_extensions.Literal["bar"], + str + ] + ): + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _0[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _0[ + typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -62,121 +96,90 @@ def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ tuple, bytes, schemas.FileIO - ]]: ... - - def __getitem__( - self, - name: typing.Union[ - typing_extensions.Literal["bar"], - str - ] - ): - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> Allof.Schema_.AllOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - Allof.Schema_.AllOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - - - class _1( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - required = { - "foo", - } - - class Properties: - Foo: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "foo": Foo, - } - - - @property - def foo(self) -> Schema_.Properties.Foo[str]: - return self.__getitem__("foo") - - @typing.overload - def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Schema_.Properties.Foo[str]: ... - - @typing.overload - def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + ] + ], + inst + ) + return inst + +Foo: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties2 = typing_extensions.TypedDict( + 'Properties2', + { + "foo": typing.Type[Foo], + } +) + + +class _1( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + required: typing.FrozenSet[str] = frozenset({ + "foo", + }) + properties: Properties2 = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties2)) # type: ignore + + + @property + def foo(self) -> Foo[str]: + return self.__getitem__("foo") + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Foo[str]: ... + + @typing.overload + def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + def __getitem__( + self, + name: typing.Union[ + typing_extensions.Literal["foo"], + str + ] + ): + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _1[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _1[ + typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -185,138 +188,39 @@ def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ tuple, bytes, schemas.FileIO - ]]: ... - - def __getitem__( - self, - name: typing.Union[ - typing_extensions.Literal["foo"], - str - ] - ): - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> Allof.Schema_.AllOf._1[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - Allof.Schema_.AllOf._1[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - classes = [ - _0, - _1, - ] + ] + ], + inst + ) + return inst + +AllOf = typing.Tuple[ + typing.Type[_0[schemas.U]], + typing.Type[_1[schemas.U]], +] + + +class Allof( + schemas.AnyTypeSchema[schemas.T], +): + """NOTE: This class is auto generated by OpenAPI JSON Schema Generator. + Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator + + Do not edit the class manually. + """ + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Allof[ typing.Union[ frozendict.frozendict, @@ -351,3 +255,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_combined_with_anyof_oneof.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_combined_with_anyof_oneof.py index fa046fecab0..bc30c9f4b8c 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_combined_with_anyof_oneof.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_combined_with_anyof_oneof.py @@ -11,333 +11,198 @@ from unit_test_api.shared_imports.schema_imports import * -class AllofCombinedWithAnyofOneof( + +class _03( schemas.AnyTypeSchema[schemas.T], ): - """NOTE: This class is auto generated by OpenAPI JSON Schema Generator. - Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator - - Do not edit the class manually. - """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AllOf: - - - class _0( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - multiple_of = 2 - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> AllofCombinedWithAnyofOneof.Schema_.AllOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AllofCombinedWithAnyofOneof.Schema_.AllOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - classes = [ - _0, - ] - - class OneOf: - - - class _0( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - multiple_of = 5 - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> AllofCombinedWithAnyofOneof.Schema_.OneOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AllofCombinedWithAnyofOneof.Schema_.OneOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - classes = [ - _0, - ] - - class AnyOf: - - - class _0( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - multiple_of = 3 - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> AllofCombinedWithAnyofOneof.Schema_.AnyOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AllofCombinedWithAnyofOneof.Schema_.AnyOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - classes = [ - _0, - ] + multiple_of: typing.Union[int, float] = 2 def __new__( cls, - *args_: typing.Union[ - dict, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _03[ + typing.Union[ frozendict.frozendict, str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, decimal.Decimal, - bool, - None, - list, + schemas.BoolClass, + schemas.NoneClass, tuple, bytes, - io.FileIO, - io.BufferedReader - ], + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _03[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + +AllOf = typing.Tuple[ + typing.Type[_03[schemas.U]], +] + + +class _02( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + multiple_of: typing.Union[int, float] = 3 + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _02[ + typing.Union[ frozendict.frozendict, - list, - tuple, + str, decimal.Decimal, - float, - int, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _02[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + +AnyOf = typing.Tuple[ + typing.Type[_02[schemas.U]], +] + + +class _0( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + multiple_of: typing.Union[int, float] = 5 + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _0[ + typing.Union[ + frozendict.frozendict, str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _0[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + +OneOf = typing.Tuple[ + typing.Type[_0[schemas.U]], +] + + +class AllofCombinedWithAnyofOneof( + schemas.AnyTypeSchema[schemas.T], +): + """NOTE: This class is auto generated by OpenAPI JSON Schema Generator. + Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator + + Do not edit the class manually. + """ + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore + any_of: AnyOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AnyOf)) # type: ignore + one_of: OneOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(OneOf)) # type: ignore + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> AllofCombinedWithAnyofOneof[ typing.Union[ frozendict.frozendict, @@ -372,3 +237,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_simple_types.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_simple_types.py index a2c80435df5..3861d8dd52a 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_simple_types.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_simple_types.py @@ -11,238 +11,138 @@ from unit_test_api.shared_imports.schema_imports import * -class AllofSimpleTypes( + +class _0( schemas.AnyTypeSchema[schemas.T], ): - """NOTE: This class is auto generated by OpenAPI JSON Schema Generator. - Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator - - Do not edit the class manually. - """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AllOf: - - - class _0( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - inclusive_maximum = 30 - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> AllofSimpleTypes.Schema_.AllOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AllofSimpleTypes.Schema_.AllOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - - - class _1( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - inclusive_minimum = 20 - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> AllofSimpleTypes.Schema_.AllOf._1[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AllofSimpleTypes.Schema_.AllOf._1[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - classes = [ - _0, - _1, - ] + inclusive_maximum: typing.Union[int, float] = 30 def __new__( cls, - *args_: typing.Union[ - dict, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _0[ + typing.Union[ frozendict.frozendict, str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, decimal.Decimal, - bool, - None, - list, + schemas.BoolClass, + schemas.NoneClass, tuple, bytes, - io.FileIO, - io.BufferedReader - ], + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _0[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + + + +class _1( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + inclusive_minimum: typing.Union[int, float] = 20 + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _1[ + typing.Union[ frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _1[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + +AllOf = typing.Tuple[ + typing.Type[_0[schemas.U]], + typing.Type[_1[schemas.U]], +] + + +class AllofSimpleTypes( + schemas.AnyTypeSchema[schemas.T], +): + """NOTE: This class is auto generated by OpenAPI JSON Schema Generator. + Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator + + Do not edit the class manually. + """ + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> AllofSimpleTypes[ typing.Union[ frozendict.frozendict, @@ -277,3 +177,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_with_base_schema.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_with_base_schema.py index 60ed150f91c..e66fd69a09e 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_with_base_schema.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_with_base_schema.py @@ -10,59 +10,84 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +Foo: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties2 = typing_extensions.TypedDict( + 'Properties2', + { + "foo": typing.Type[Foo], + } +) -class AllofWithBaseSchema( + +class _0( schemas.AnyTypeSchema[schemas.T], ): - """NOTE: This class is auto generated by OpenAPI JSON Schema Generator. - Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator - - Do not edit the class manually. - """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - required = { - "bar", - } - - class Properties: - Bar: typing_extensions.TypeAlias = schemas.IntSchema[U] - __annotations__ = { - "bar": Bar, - } - - class AllOf: - - - class _0( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - required = { - "foo", - } - - class Properties: - Foo: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "foo": Foo, - } - - - @property - def foo(self) -> Schema_.Properties.Foo[str]: - return self.__getitem__("foo") - - @typing.overload - def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Schema_.Properties.Foo[str]: ... - - @typing.overload - def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + required: typing.FrozenSet[str] = frozenset({ + "foo", + }) + properties: Properties2 = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties2)) # type: ignore + + + @property + def foo(self) -> Foo[str]: + return self.__getitem__("foo") + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Foo[str]: ... + + @typing.overload + def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + def __getitem__( + self, + name: typing.Union[ + typing_extensions.Literal["foo"], + str + ] + ): + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _0[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _0[ + typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -71,121 +96,90 @@ def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ tuple, bytes, schemas.FileIO - ]]: ... - - def __getitem__( - self, - name: typing.Union[ - typing_extensions.Literal["foo"], - str - ] - ): - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> AllofWithBaseSchema.Schema_.AllOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AllofWithBaseSchema.Schema_.AllOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - - - class _1( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - required = { - "baz", - } - - class Properties: - Baz: typing_extensions.TypeAlias = schemas.NoneSchema[U] - __annotations__ = { - "baz": Baz, - } - - - @property - def baz(self) -> Schema_.Properties.Baz[schemas.NoneClass]: - return self.__getitem__("baz") - - @typing.overload - def __getitem__(self, name: typing_extensions.Literal["baz"]) -> Schema_.Properties.Baz[schemas.NoneClass]: ... - - @typing.overload - def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + ] + ], + inst + ) + return inst + +Baz: typing_extensions.TypeAlias = schemas.NoneSchema[U] +Properties3 = typing_extensions.TypedDict( + 'Properties3', + { + "baz": typing.Type[Baz], + } +) + + +class _1( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + required: typing.FrozenSet[str] = frozenset({ + "baz", + }) + properties: Properties3 = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties3)) # type: ignore + + + @property + def baz(self) -> Baz[schemas.NoneClass]: + return self.__getitem__("baz") + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["baz"]) -> Baz[schemas.NoneClass]: ... + + @typing.overload + def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + def __getitem__( + self, + name: typing.Union[ + typing_extensions.Literal["baz"], + str + ] + ): + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _1[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _1[ + typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -194,104 +188,51 @@ def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ tuple, bytes, schemas.FileIO - ]]: ... - - def __getitem__( - self, - name: typing.Union[ - typing_extensions.Literal["baz"], - str - ] - ): - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> AllofWithBaseSchema.Schema_.AllOf._1[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AllofWithBaseSchema.Schema_.AllOf._1[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - classes = [ - _0, - _1, - ] + ] + ], + inst + ) + return inst + +AllOf = typing.Tuple[ + typing.Type[_0[schemas.U]], + typing.Type[_1[schemas.U]], +] +Bar: typing_extensions.TypeAlias = schemas.IntSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "bar": typing.Type[Bar], + } +) + + +class AllofWithBaseSchema( + schemas.AnyTypeSchema[schemas.T], +): + """NOTE: This class is auto generated by OpenAPI JSON Schema Generator. + Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator + + Do not edit the class manually. + """ + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + required: typing.FrozenSet[str] = frozenset({ + "bar", + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore @property - def bar(self) -> Schema_.Properties.Bar[decimal.Decimal]: + def bar(self) -> Bar[decimal.Decimal]: return self.__getitem__("bar") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["bar"]) -> Schema_.Properties.Bar[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["bar"]) -> Bar[decimal.Decimal]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -317,44 +258,9 @@ def __getitem__( def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> AllofWithBaseSchema[ typing.Union[ frozendict.frozendict, @@ -389,3 +295,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_with_one_empty_schema.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_with_one_empty_schema.py index 2878853faee..55d03fc6311 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_with_one_empty_schema.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_with_one_empty_schema.py @@ -10,6 +10,11 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +_0: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] +AllOf = typing.Tuple[ + typing.Type[_0[schemas.U]], +] + class AllofWithOneEmptySchema( schemas.AnyTypeSchema[schemas.T], @@ -21,56 +26,17 @@ class AllofWithOneEmptySchema( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AllOf: - _0: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - classes = [ - _0, - ] + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> AllofWithOneEmptySchema[ typing.Union[ frozendict.frozendict, @@ -105,3 +71,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_with_the_first_empty_schema.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_with_the_first_empty_schema.py index b5ad42a8142..e640c00767e 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_with_the_first_empty_schema.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_with_the_first_empty_schema.py @@ -10,6 +10,13 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +_0: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] +_1: typing_extensions.TypeAlias = schemas.NumberSchema[U] +AllOf = typing.Tuple[ + typing.Type[_0[schemas.U]], + typing.Type[_1[schemas.U]], +] + class AllofWithTheFirstEmptySchema( schemas.AnyTypeSchema[schemas.T], @@ -21,58 +28,17 @@ class AllofWithTheFirstEmptySchema( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AllOf: - _0: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - _1: typing_extensions.TypeAlias = schemas.NumberSchema[U] - classes = [ - _0, - _1, - ] + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> AllofWithTheFirstEmptySchema[ typing.Union[ frozendict.frozendict, @@ -107,3 +73,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_with_the_last_empty_schema.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_with_the_last_empty_schema.py index b00a55a6fba..18bd961fba1 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_with_the_last_empty_schema.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_with_the_last_empty_schema.py @@ -10,6 +10,13 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +_0: typing_extensions.TypeAlias = schemas.NumberSchema[U] +_1: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] +AllOf = typing.Tuple[ + typing.Type[_0[schemas.U]], + typing.Type[_1[schemas.U]], +] + class AllofWithTheLastEmptySchema( schemas.AnyTypeSchema[schemas.T], @@ -21,58 +28,17 @@ class AllofWithTheLastEmptySchema( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AllOf: - _0: typing_extensions.TypeAlias = schemas.NumberSchema[U] - _1: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - classes = [ - _0, - _1, - ] + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> AllofWithTheLastEmptySchema[ typing.Union[ frozendict.frozendict, @@ -107,3 +73,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_with_two_empty_schemas.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_with_two_empty_schemas.py index a78a115621e..bcb530a8db9 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_with_two_empty_schemas.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/allof_with_two_empty_schemas.py @@ -10,6 +10,13 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +_0: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] +_1: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] +AllOf = typing.Tuple[ + typing.Type[_0[schemas.U]], + typing.Type[_1[schemas.U]], +] + class AllofWithTwoEmptySchemas( schemas.AnyTypeSchema[schemas.T], @@ -21,58 +28,17 @@ class AllofWithTwoEmptySchemas( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AllOf: - _0: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - _1: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - classes = [ - _0, - _1, - ] + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> AllofWithTwoEmptySchemas[ typing.Union[ frozendict.frozendict, @@ -107,3 +73,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/anyof.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/anyof.py index e9aee9e65dc..db5ab8f98c5 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/anyof.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/anyof.py @@ -10,6 +10,65 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +_0: typing_extensions.TypeAlias = schemas.IntSchema[U] + + +class _1( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + inclusive_minimum: typing.Union[int, float] = 2 + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _1[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _1[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + +AnyOf = typing.Tuple[ + typing.Type[_0[schemas.U]], + typing.Type[_1[schemas.U]], +] + class Anyof( schemas.AnyTypeSchema[schemas.T], @@ -21,143 +80,17 @@ class Anyof( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AnyOf: - _0: typing_extensions.TypeAlias = schemas.IntSchema[U] - - - class _1( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - inclusive_minimum = 2 - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> Anyof.Schema_.AnyOf._1[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - Anyof.Schema_.AnyOf._1[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - classes = [ - _0, - _1, - ] + any_of: AnyOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AnyOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Anyof[ typing.Union[ frozendict.frozendict, @@ -192,3 +125,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/anyof_complex_types.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/anyof_complex_types.py index a1e074a4fc4..a437baabc35 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/anyof_complex_types.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/anyof_complex_types.py @@ -10,50 +10,84 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +Bar: typing_extensions.TypeAlias = schemas.IntSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "bar": typing.Type[Bar], + } +) -class AnyofComplexTypes( + +class _0( schemas.AnyTypeSchema[schemas.T], ): - """NOTE: This class is auto generated by OpenAPI JSON Schema Generator. - Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator - - Do not edit the class manually. - """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AnyOf: - - - class _0( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - required = { - "bar", - } - - class Properties: - Bar: typing_extensions.TypeAlias = schemas.IntSchema[U] - __annotations__ = { - "bar": Bar, - } - - - @property - def bar(self) -> Schema_.Properties.Bar[decimal.Decimal]: - return self.__getitem__("bar") - - @typing.overload - def __getitem__(self, name: typing_extensions.Literal["bar"]) -> Schema_.Properties.Bar[decimal.Decimal]: ... - - @typing.overload - def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + required: typing.FrozenSet[str] = frozenset({ + "bar", + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + + + @property + def bar(self) -> Bar[decimal.Decimal]: + return self.__getitem__("bar") + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["bar"]) -> Bar[decimal.Decimal]: ... + + @typing.overload + def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + def __getitem__( + self, + name: typing.Union[ + typing_extensions.Literal["bar"], + str + ] + ): + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _0[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _0[ + typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -62,121 +96,90 @@ def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ tuple, bytes, schemas.FileIO - ]]: ... - - def __getitem__( - self, - name: typing.Union[ - typing_extensions.Literal["bar"], - str - ] - ): - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> AnyofComplexTypes.Schema_.AnyOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AnyofComplexTypes.Schema_.AnyOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - - - class _1( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - required = { - "foo", - } - - class Properties: - Foo: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "foo": Foo, - } - - - @property - def foo(self) -> Schema_.Properties.Foo[str]: - return self.__getitem__("foo") - - @typing.overload - def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Schema_.Properties.Foo[str]: ... - - @typing.overload - def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + ] + ], + inst + ) + return inst + +Foo: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties2 = typing_extensions.TypedDict( + 'Properties2', + { + "foo": typing.Type[Foo], + } +) + + +class _1( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + required: typing.FrozenSet[str] = frozenset({ + "foo", + }) + properties: Properties2 = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties2)) # type: ignore + + + @property + def foo(self) -> Foo[str]: + return self.__getitem__("foo") + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Foo[str]: ... + + @typing.overload + def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + def __getitem__( + self, + name: typing.Union[ + typing_extensions.Literal["foo"], + str + ] + ): + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _1[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _1[ + typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -185,138 +188,39 @@ def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ tuple, bytes, schemas.FileIO - ]]: ... - - def __getitem__( - self, - name: typing.Union[ - typing_extensions.Literal["foo"], - str - ] - ): - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> AnyofComplexTypes.Schema_.AnyOf._1[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AnyofComplexTypes.Schema_.AnyOf._1[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - classes = [ - _0, - _1, - ] + ] + ], + inst + ) + return inst + +AnyOf = typing.Tuple[ + typing.Type[_0[schemas.U]], + typing.Type[_1[schemas.U]], +] + + +class AnyofComplexTypes( + schemas.AnyTypeSchema[schemas.T], +): + """NOTE: This class is auto generated by OpenAPI JSON Schema Generator. + Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator + + Do not edit the class manually. + """ + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + any_of: AnyOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AnyOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> AnyofComplexTypes[ typing.Union[ frozendict.frozendict, @@ -351,3 +255,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/anyof_with_base_schema.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/anyof_with_base_schema.py index f709e98e6dc..ff8e02bf23d 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/anyof_with_base_schema.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/anyof_with_base_schema.py @@ -11,6 +11,117 @@ from unit_test_api.shared_imports.schema_imports import * + +class _0( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + max_length: int = 2 + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _0[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _0[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + + + +class _1( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + min_length: int = 4 + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _1[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _1[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + +AnyOf = typing.Tuple[ + typing.Type[_0[schemas.U]], + typing.Type[_1[schemas.U]], +] + + class AnyofWithBaseSchema( schemas.StrSchema[schemas.T] ): @@ -21,188 +132,12 @@ class AnyofWithBaseSchema( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ str, - } - - class AnyOf: - - - class _0( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - max_length = 2 - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> AnyofWithBaseSchema.Schema_.AnyOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AnyofWithBaseSchema.Schema_.AnyOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - - - class _1( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - min_length = 4 - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> AnyofWithBaseSchema.Schema_.AnyOf._1[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AnyofWithBaseSchema.Schema_.AnyOf._1[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - classes = [ - _0, - _1, - ] + }) + any_of: AnyOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AnyOf)) # type: ignore def __new__( @@ -220,3 +155,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/anyof_with_one_empty_schema.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/anyof_with_one_empty_schema.py index 0a54d1f7ec1..ead1b940c10 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/anyof_with_one_empty_schema.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/anyof_with_one_empty_schema.py @@ -10,6 +10,13 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +_0: typing_extensions.TypeAlias = schemas.NumberSchema[U] +_1: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] +AnyOf = typing.Tuple[ + typing.Type[_0[schemas.U]], + typing.Type[_1[schemas.U]], +] + class AnyofWithOneEmptySchema( schemas.AnyTypeSchema[schemas.T], @@ -21,58 +28,17 @@ class AnyofWithOneEmptySchema( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AnyOf: - _0: typing_extensions.TypeAlias = schemas.NumberSchema[U] - _1: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - classes = [ - _0, - _1, - ] + any_of: AnyOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AnyOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> AnyofWithOneEmptySchema[ typing.Union[ frozendict.frozendict, @@ -107,3 +73,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/array_type_matches_arrays.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/array_type_matches_arrays.py index 0562514c260..68aae77b810 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/array_type_matches_arrays.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/array_type_matches_arrays.py @@ -10,6 +10,8 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +Items: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] + class ArrayTypeMatchesArrays( schemas.ListSchema[schemas.T] @@ -21,24 +23,18 @@ class ArrayTypeMatchesArrays( """ - class Schema_: - types = {tuple} - Items: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore def __new__( cls, arg_: typing.Sequence[ typing.Union[ - Schema_.Items[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + Items[ + schemas.INPUT_BASE_TYPES + ], dict, frozendict.frozendict, str, @@ -70,7 +66,7 @@ def __new__( ) return inst - def __getitem__(self, name: int) -> Schema_.Items[typing.Union[ + def __getitem__(self, name: int) -> Items[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -81,3 +77,4 @@ def __getitem__(self, name: int) -> Schema_.Items[typing.Union[ schemas.FileIO ]]: return super().__getitem__(name) + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/boolean_type_matches_booleans.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/boolean_type_matches_booleans.py index a05ab8f47a7..cf11a7cea6a 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/boolean_type_matches_booleans.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/boolean_type_matches_booleans.py @@ -9,4 +9,5 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * + BooleanTypeMatchesBooleans: typing_extensions.TypeAlias = schemas.BoolSchema[U] diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/by_int.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/by_int.py index bce8744bcba..8d48c6ff0a1 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/by_int.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/by_int.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class ByInt( schemas.AnyTypeSchema[schemas.T], ): @@ -21,51 +22,17 @@ class ByInt( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - multiple_of = 2 + multiple_of: typing.Union[int, float] = 2 def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ByInt[ typing.Union[ frozendict.frozendict, @@ -100,3 +67,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/by_number.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/by_number.py index cdbac729ffc..6b8c819d611 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/by_number.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/by_number.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class ByNumber( schemas.AnyTypeSchema[schemas.T], ): @@ -21,51 +22,17 @@ class ByNumber( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - multiple_of = 1.5 + multiple_of: typing.Union[int, float] = 1.5 def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ByNumber[ typing.Union[ frozendict.frozendict, @@ -100,3 +67,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/by_small_number.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/by_small_number.py index 5fc2ceae620..5eaa6cdac4e 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/by_small_number.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/by_small_number.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class BySmallNumber( schemas.AnyTypeSchema[schemas.T], ): @@ -21,51 +22,17 @@ class BySmallNumber( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - multiple_of = 0.00010 + multiple_of: typing.Union[int, float] = 0.00010 def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> BySmallNumber[ typing.Union[ frozendict.frozendict, @@ -100,3 +67,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/date_time_format.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/date_time_format.py index a4f732bd35a..2d202d5bdd6 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/date_time_format.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/date_time_format.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class DateTimeFormat( schemas.DateTimeBase, schemas.AnyTypeSchema[schemas.T], @@ -22,51 +23,17 @@ class DateTimeFormat( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - format = 'date-time' + format: str = 'date-time' def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> DateTimeFormat[ typing.Union[ frozendict.frozendict, @@ -101,3 +68,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/email_format.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/email_format.py index 10137f7ff3e..8ec0d70100d 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/email_format.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/email_format.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class EmailFormat( schemas.AnyTypeSchema[schemas.T], ): @@ -21,51 +22,17 @@ class EmailFormat( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - format = 'email' + format: str = 'email' def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> EmailFormat[ typing.Union[ frozendict.frozendict, @@ -100,3 +67,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/enum_with0_does_not_match_false.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/enum_with0_does_not_match_false.py index 57b1759d613..2937d8ad664 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/enum_with0_does_not_match_false.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/enum_with0_does_not_match_false.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class EnumWith0DoesNotMatchFalse( schemas.NumberSchema[schemas.T] ): @@ -21,14 +22,17 @@ class EnumWith0DoesNotMatchFalse( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ decimal.Decimal, - } - enum_value_to_name = { - 0: "POSITIVE_0", - } + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + 0: "POSITIVE_0", + } + ) @schemas.classproperty - def POSITIVE_0(cls): + def POSITIVE_0(cls) -> EnumWith0DoesNotMatchFalse[decimal.Decimal]: return cls(0) # type: ignore diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/enum_with1_does_not_match_true.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/enum_with1_does_not_match_true.py index 446a161f320..7635643d493 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/enum_with1_does_not_match_true.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/enum_with1_does_not_match_true.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class EnumWith1DoesNotMatchTrue( schemas.NumberSchema[schemas.T] ): @@ -21,14 +22,17 @@ class EnumWith1DoesNotMatchTrue( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ decimal.Decimal, - } - enum_value_to_name = { - 1: "POSITIVE_1", - } + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + 1: "POSITIVE_1", + } + ) @schemas.classproperty - def POSITIVE_1(cls): + def POSITIVE_1(cls) -> EnumWith1DoesNotMatchTrue[decimal.Decimal]: return cls(1) # type: ignore diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/enum_with_escaped_characters.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/enum_with_escaped_characters.py index ab9825a89ca..628af705215 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/enum_with_escaped_characters.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/enum_with_escaped_characters.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class EnumWithEscapedCharacters( schemas.StrSchema[schemas.T] ): @@ -21,19 +22,22 @@ class EnumWithEscapedCharacters( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ str, - } - enum_value_to_name = { - "foo\nbar": "FOO_LINE_FEED_LF_BAR", - "foo\rbar": "FOO_CARRIAGE_RETURN_CR_BAR", - } + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "foo\nbar": "FOO_LINE_FEED_LF_BAR", + "foo\rbar": "FOO_CARRIAGE_RETURN_CR_BAR", + } + ) @schemas.classproperty - def FOO_LINE_FEED_LF_BAR(cls): + def FOO_LINE_FEED_LF_BAR(cls) -> EnumWithEscapedCharacters[str]: return cls("foo\nbar") # type: ignore @schemas.classproperty - def FOO_CARRIAGE_RETURN_CR_BAR(cls): + def FOO_CARRIAGE_RETURN_CR_BAR(cls) -> EnumWithEscapedCharacters[str]: return cls("foo\rbar") # type: ignore diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/enum_with_false_does_not_match0.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/enum_with_false_does_not_match0.py index 5ec216ce0b3..f53dc10eb1d 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/enum_with_false_does_not_match0.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/enum_with_false_does_not_match0.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class EnumWithFalseDoesNotMatch0( schemas.BoolSchema[schemas.T] ): @@ -21,14 +22,17 @@ class EnumWithFalseDoesNotMatch0( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ schemas.BoolClass, - } - enum_value_to_name = { - schemas.BoolClass.FALSE: "FALSE", - } + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + schemas.BoolClass.FALSE: "FALSE", + } + ) @schemas.classproperty - def FALSE(cls): + def FALSE(cls) -> EnumWithFalseDoesNotMatch0[schemas.BoolClass]: return cls(False) # type: ignore diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/enum_with_true_does_not_match1.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/enum_with_true_does_not_match1.py index cd9d9e98321..9a8261c9f9b 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/enum_with_true_does_not_match1.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/enum_with_true_does_not_match1.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class EnumWithTrueDoesNotMatch1( schemas.BoolSchema[schemas.T] ): @@ -21,14 +22,17 @@ class EnumWithTrueDoesNotMatch1( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ schemas.BoolClass, - } - enum_value_to_name = { - schemas.BoolClass.TRUE: "TRUE", - } + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + schemas.BoolClass.TRUE: "TRUE", + } + ) @schemas.classproperty - def TRUE(cls): + def TRUE(cls) -> EnumWithTrueDoesNotMatch1[schemas.BoolClass]: return cls(True) # type: ignore diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/enums_in_properties.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/enums_in_properties.py index 1a8dd6ab9a1..ee45bbd69ec 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/enums_in_properties.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/enums_in_properties.py @@ -11,6 +11,56 @@ from unit_test_api.shared_imports.schema_imports import * + +class Foo( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "foo": "FOO", + } + ) + + @schemas.classproperty + def FOO(cls) -> Foo[str]: + return cls("foo") # type: ignore + + +class Bar( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "bar": "BAR", + } + ) + + @schemas.classproperty + def BAR(cls) -> Bar[str]: + return cls("bar") # type: ignore +Properties = typing_extensions.TypedDict( + 'Properties', + { + "foo": typing.Type[Foo], + "bar": typing.Type[Bar], + } +) + + class EnumsInProperties( schemas.DictSchema[schemas.T] ): @@ -21,63 +71,23 @@ class EnumsInProperties( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "bar", - } - - class Properties: - - - class Foo( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - enum_value_to_name = { - "foo": "FOO", - } - - @schemas.classproperty - def FOO(cls): - return cls("foo") # type: ignore - - - class Bar( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - enum_value_to_name = { - "bar": "BAR", - } - - @schemas.classproperty - def BAR(cls): - return cls("bar") # type: ignore - __annotations__ = { - "foo": Foo, - "bar": Bar, - } + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @property - def bar(self) -> Schema_.Properties.Bar[str]: + def bar(self) -> Bar[str]: return self.__getitem__("bar") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["bar"]) -> Schema_.Properties.Bar[str]: ... + def __getitem__(self, name: typing_extensions.Literal["bar"]) -> Bar[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Schema_.Properties.Foo[str]: ... + def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Foo[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -106,34 +116,16 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], bar: typing.Union[ - Schema_.Properties.Bar[str], + Bar[str], str ], foo: typing.Union[ - Schema_.Properties.Foo[str], + Foo[str], schemas.Unset, str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> EnumsInProperties[frozendict.frozendict]: inst = super().__new__( cls, @@ -148,3 +140,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/forbidden_property.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/forbidden_property.py index b4ecaa176dc..dd596562f38 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/forbidden_property.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/forbidden_property.py @@ -10,6 +10,14 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +Foo: typing_extensions.TypeAlias = schemas.NotAnyTypeSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "foo": typing.Type[Foo], + } +) + class ForbiddenProperty( schemas.AnyTypeSchema[schemas.T], @@ -21,18 +29,14 @@ class ForbiddenProperty( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class Properties: - Foo: typing_extensions.TypeAlias = schemas.NotAnyTypeSchema[U] - __annotations__ = { - "foo": Foo, - } + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Schema_.Properties.Foo[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Foo[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -67,35 +71,11 @@ def __getitem__( def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, foo: typing.Union[ - Schema_.Properties.Foo[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + Foo[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -115,25 +95,7 @@ def __new__( io.BufferedReader ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ForbiddenProperty[ typing.Union[ frozendict.frozendict, @@ -169,3 +131,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/hostname_format.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/hostname_format.py index 029776e662e..11d784597b8 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/hostname_format.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/hostname_format.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class HostnameFormat( schemas.AnyTypeSchema[schemas.T], ): @@ -21,51 +22,17 @@ class HostnameFormat( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - format = 'hostname' + format: str = 'hostname' def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> HostnameFormat[ typing.Union[ frozendict.frozendict, @@ -100,3 +67,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/integer_type_matches_integers.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/integer_type_matches_integers.py index 9cdd584c154..94c116e4de1 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/integer_type_matches_integers.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/integer_type_matches_integers.py @@ -9,4 +9,5 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * + IntegerTypeMatchesIntegers: typing_extensions.TypeAlias = schemas.IntSchema[U] diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/invalid_instance_should_not_raise_error_when_float_division_inf.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/invalid_instance_should_not_raise_error_when_float_division_inf.py index e5f055a20e8..8d2c0de4369 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/invalid_instance_should_not_raise_error_when_float_division_inf.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/invalid_instance_should_not_raise_error_when_float_division_inf.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class InvalidInstanceShouldNotRaiseErrorWhenFloatDivisionInf( schemas.IntSchema[schemas.T] ): @@ -21,9 +22,10 @@ class InvalidInstanceShouldNotRaiseErrorWhenFloatDivisionInf( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ decimal.Decimal, - } - format = 'int' - multiple_of = 0.123456789 + }) + format: str = 'int' + multiple_of: typing.Union[int, float] = 0.123456789 diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/invalid_string_value_for_default.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/invalid_string_value_for_default.py index b797518a6d9..9e2bb008e57 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/invalid_string_value_for_default.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/invalid_string_value_for_default.py @@ -11,6 +11,27 @@ from unit_test_api.shared_imports.schema_imports import * + +class Bar( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + min_length: int = 4 + default: str = "bad" +Properties = typing_extensions.TypedDict( + 'Properties', + { + "bar": typing.Type[Bar], + } +) + + class InvalidStringValueForDefault( schemas.AnyTypeSchema[schemas.T], ): @@ -21,30 +42,14 @@ class InvalidStringValueForDefault( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class Properties: - - - class Bar( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - min_length = 4 - default = "bad" - __annotations__ = { - "bar": Bar, - } + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["bar"]) -> Schema_.Properties.Bar[str]: ... + def __getitem__(self, name: typing_extensions.Literal["bar"]) -> Bar[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -70,49 +75,14 @@ def __getitem__( def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, bar: typing.Union[ - Schema_.Properties.Bar[str], + Bar[str], schemas.Unset, str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> InvalidStringValueForDefault[ typing.Union[ frozendict.frozendict, @@ -148,3 +118,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ipv4_format.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ipv4_format.py index 6fe6699aaac..5a05f608b8b 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ipv4_format.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ipv4_format.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class Ipv4Format( schemas.AnyTypeSchema[schemas.T], ): @@ -21,51 +22,17 @@ class Ipv4Format( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - format = 'ipv4' + format: str = 'ipv4' def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Ipv4Format[ typing.Union[ frozendict.frozendict, @@ -100,3 +67,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ipv6_format.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ipv6_format.py index 6eb4c21e351..be23fd2b76c 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ipv6_format.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ipv6_format.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class Ipv6Format( schemas.AnyTypeSchema[schemas.T], ): @@ -21,51 +22,17 @@ class Ipv6Format( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - format = 'ipv6' + format: str = 'ipv6' def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Ipv6Format[ typing.Union[ frozendict.frozendict, @@ -100,3 +67,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/json_pointer_format.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/json_pointer_format.py index 0a6f585abcf..42e84fce010 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/json_pointer_format.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/json_pointer_format.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class JsonPointerFormat( schemas.AnyTypeSchema[schemas.T], ): @@ -21,51 +22,17 @@ class JsonPointerFormat( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - format = 'json-pointer' + format: str = 'json-pointer' def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> JsonPointerFormat[ typing.Union[ frozendict.frozendict, @@ -100,3 +67,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/maximum_validation.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/maximum_validation.py index 366559eddf4..14714346cb3 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/maximum_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/maximum_validation.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class MaximumValidation( schemas.AnyTypeSchema[schemas.T], ): @@ -21,51 +22,17 @@ class MaximumValidation( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - inclusive_maximum = 3.0 + inclusive_maximum: typing.Union[int, float] = 3.0 def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> MaximumValidation[ typing.Union[ frozendict.frozendict, @@ -100,3 +67,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/maximum_validation_with_unsigned_integer.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/maximum_validation_with_unsigned_integer.py index 926eb7c8c8a..9d3b5f2d81a 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/maximum_validation_with_unsigned_integer.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/maximum_validation_with_unsigned_integer.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class MaximumValidationWithUnsignedInteger( schemas.AnyTypeSchema[schemas.T], ): @@ -21,51 +22,17 @@ class MaximumValidationWithUnsignedInteger( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - inclusive_maximum = 300 + inclusive_maximum: typing.Union[int, float] = 300 def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> MaximumValidationWithUnsignedInteger[ typing.Union[ frozendict.frozendict, @@ -100,3 +67,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/maxitems_validation.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/maxitems_validation.py index 2d219a4b1ff..296641f1fe1 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/maxitems_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/maxitems_validation.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class MaxitemsValidation( schemas.AnyTypeSchema[schemas.T], ): @@ -21,51 +22,17 @@ class MaxitemsValidation( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - max_items = 2 + max_items: int = 2 def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> MaxitemsValidation[ typing.Union[ frozendict.frozendict, @@ -100,3 +67,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/maxlength_validation.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/maxlength_validation.py index f6afe9bcc88..8f3481fc68b 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/maxlength_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/maxlength_validation.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class MaxlengthValidation( schemas.AnyTypeSchema[schemas.T], ): @@ -21,51 +22,17 @@ class MaxlengthValidation( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - max_length = 2 + max_length: int = 2 def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> MaxlengthValidation[ typing.Union[ frozendict.frozendict, @@ -100,3 +67,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/maxproperties0_means_the_object_is_empty.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/maxproperties0_means_the_object_is_empty.py index 0866d3f2579..4258f1d4f9d 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/maxproperties0_means_the_object_is_empty.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/maxproperties0_means_the_object_is_empty.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class Maxproperties0MeansTheObjectIsEmpty( schemas.AnyTypeSchema[schemas.T], ): @@ -21,51 +22,17 @@ class Maxproperties0MeansTheObjectIsEmpty( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - max_properties = 0 + max_properties: int = 0 def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Maxproperties0MeansTheObjectIsEmpty[ typing.Union[ frozendict.frozendict, @@ -100,3 +67,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/maxproperties_validation.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/maxproperties_validation.py index c83d2a4470a..4a0f296bbb1 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/maxproperties_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/maxproperties_validation.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class MaxpropertiesValidation( schemas.AnyTypeSchema[schemas.T], ): @@ -21,51 +22,17 @@ class MaxpropertiesValidation( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - max_properties = 2 + max_properties: int = 2 def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> MaxpropertiesValidation[ typing.Union[ frozendict.frozendict, @@ -100,3 +67,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/minimum_validation.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/minimum_validation.py index 1412749b421..3f47f668e0d 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/minimum_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/minimum_validation.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class MinimumValidation( schemas.AnyTypeSchema[schemas.T], ): @@ -21,51 +22,17 @@ class MinimumValidation( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - inclusive_minimum = 1.1 + inclusive_minimum: typing.Union[int, float] = 1.1 def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> MinimumValidation[ typing.Union[ frozendict.frozendict, @@ -100,3 +67,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/minimum_validation_with_signed_integer.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/minimum_validation_with_signed_integer.py index f58aaa2d434..663669f8064 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/minimum_validation_with_signed_integer.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/minimum_validation_with_signed_integer.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class MinimumValidationWithSignedInteger( schemas.AnyTypeSchema[schemas.T], ): @@ -21,51 +22,17 @@ class MinimumValidationWithSignedInteger( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - inclusive_minimum = -2 + inclusive_minimum: typing.Union[int, float] = -2 def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> MinimumValidationWithSignedInteger[ typing.Union[ frozendict.frozendict, @@ -100,3 +67,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/minitems_validation.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/minitems_validation.py index 24cadc4dd5b..b5c7396656c 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/minitems_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/minitems_validation.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class MinitemsValidation( schemas.AnyTypeSchema[schemas.T], ): @@ -21,51 +22,17 @@ class MinitemsValidation( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - min_items = 1 + min_items: int = 1 def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> MinitemsValidation[ typing.Union[ frozendict.frozendict, @@ -100,3 +67,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/minlength_validation.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/minlength_validation.py index 0161e958417..fd84680732a 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/minlength_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/minlength_validation.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class MinlengthValidation( schemas.AnyTypeSchema[schemas.T], ): @@ -21,51 +22,17 @@ class MinlengthValidation( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - min_length = 2 + min_length: int = 2 def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> MinlengthValidation[ typing.Union[ frozendict.frozendict, @@ -100,3 +67,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/minproperties_validation.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/minproperties_validation.py index e35de7ca34d..3bee8da4cf1 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/minproperties_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/minproperties_validation.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class MinpropertiesValidation( schemas.AnyTypeSchema[schemas.T], ): @@ -21,51 +22,17 @@ class MinpropertiesValidation( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - min_properties = 1 + min_properties: int = 1 def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> MinpropertiesValidation[ typing.Union[ frozendict.frozendict, @@ -100,3 +67,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/nested_allof_to_check_validation_semantics.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/nested_allof_to_check_validation_semantics.py index 1f5696ef5c0..183cd7b7ca7 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/nested_allof_to_check_validation_semantics.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/nested_allof_to_check_validation_semantics.py @@ -10,6 +10,67 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +_02: typing_extensions.TypeAlias = schemas.NoneSchema[U] +AllOf = typing.Tuple[ + typing.Type[_02[schemas.U]], +] + + +class _0( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _0[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _0[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + +AllOf = typing.Tuple[ + typing.Type[_0[schemas.U]], +] + class NestedAllofToCheckValidationSemantics( schemas.AnyTypeSchema[schemas.T], @@ -21,146 +82,17 @@ class NestedAllofToCheckValidationSemantics( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AllOf: - - - class _0( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - - class AllOf: - _0: typing_extensions.TypeAlias = schemas.NoneSchema[U] - classes = [ - _0, - ] - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> NestedAllofToCheckValidationSemantics.Schema_.AllOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - NestedAllofToCheckValidationSemantics.Schema_.AllOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - classes = [ - _0, - ] + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> NestedAllofToCheckValidationSemantics[ typing.Union[ frozendict.frozendict, @@ -195,3 +127,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/nested_anyof_to_check_validation_semantics.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/nested_anyof_to_check_validation_semantics.py index 69f937a9bc4..018fbed6bb9 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/nested_anyof_to_check_validation_semantics.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/nested_anyof_to_check_validation_semantics.py @@ -10,6 +10,67 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +_02: typing_extensions.TypeAlias = schemas.NoneSchema[U] +AnyOf = typing.Tuple[ + typing.Type[_02[schemas.U]], +] + + +class _0( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + any_of: AnyOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AnyOf)) # type: ignore + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _0[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _0[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + +AnyOf = typing.Tuple[ + typing.Type[_0[schemas.U]], +] + class NestedAnyofToCheckValidationSemantics( schemas.AnyTypeSchema[schemas.T], @@ -21,146 +82,17 @@ class NestedAnyofToCheckValidationSemantics( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AnyOf: - - - class _0( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - - class AnyOf: - _0: typing_extensions.TypeAlias = schemas.NoneSchema[U] - classes = [ - _0, - ] - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> NestedAnyofToCheckValidationSemantics.Schema_.AnyOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - NestedAnyofToCheckValidationSemantics.Schema_.AnyOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - classes = [ - _0, - ] + any_of: AnyOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AnyOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> NestedAnyofToCheckValidationSemantics[ typing.Union[ frozendict.frozendict, @@ -195,3 +127,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/nested_items.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/nested_items.py index 5178a97c96a..282da9cd705 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/nested_items.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/nested_items.py @@ -10,6 +10,120 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +Items4: typing_extensions.TypeAlias = schemas.NumberSchema[U] + + +class Items3( + schemas.ListSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items4] = dataclasses.field(default_factory=lambda: Items4) # type: ignore + + def __new__( + cls, + arg_: typing.Sequence[ + typing.Union[ + Items4[decimal.Decimal], + decimal.Decimal, + int, + float + ] + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> Items3[tuple]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + Items3[tuple], + inst + ) + return inst + + def __getitem__(self, name: int) -> Items4[decimal.Decimal]: + return super().__getitem__(name) + + + +class Items2( + schemas.ListSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items3] = dataclasses.field(default_factory=lambda: Items3) # type: ignore + + def __new__( + cls, + arg_: typing.Sequence[ + typing.Union[ + Items3[tuple], + list, + tuple + ] + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> Items2[tuple]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + Items2[tuple], + inst + ) + return inst + + def __getitem__(self, name: int) -> Items3[tuple]: + return super().__getitem__(name) + + + +class Items( + schemas.ListSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items2] = dataclasses.field(default_factory=lambda: Items2) # type: ignore + + def __new__( + cls, + arg_: typing.Sequence[ + typing.Union[ + Items2[tuple], + list, + tuple + ] + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> Items[tuple]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + Items[tuple], + inst + ) + return inst + + def __getitem__(self, name: int) -> Items2[tuple]: + return super().__getitem__(name) + + class NestedItems( schemas.ListSchema[schemas.T] @@ -21,118 +135,16 @@ class NestedItems( """ - class Schema_: - types = {tuple} - - - class Items( - schemas.ListSchema[schemas.T] - ): - - - class Schema_: - types = {tuple} - - - class Items( - schemas.ListSchema[schemas.T] - ): - - - class Schema_: - types = {tuple} - - - class Items( - schemas.ListSchema[schemas.T] - ): - - - class Schema_: - types = {tuple} - Items: typing_extensions.TypeAlias = schemas.NumberSchema[U] - - def __new__( - cls, - arg_: typing.Sequence[ - typing.Union[ - Schema_.Items[decimal.Decimal], - decimal.Decimal, - int, - float - ] - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> NestedItems.Schema_.Items.Schema_.Items.Schema_.Items[tuple]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - NestedItems.Schema_.Items.Schema_.Items.Schema_.Items[tuple], - inst - ) - return inst - - def __getitem__(self, name: int) -> Schema_.Items[decimal.Decimal]: - return super().__getitem__(name) - - def __new__( - cls, - arg_: typing.Sequence[ - typing.Union[ - Schema_.Items[tuple], - list, - tuple - ] - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> NestedItems.Schema_.Items.Schema_.Items[tuple]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - NestedItems.Schema_.Items.Schema_.Items[tuple], - inst - ) - return inst - - def __getitem__(self, name: int) -> Schema_.Items[tuple]: - return super().__getitem__(name) - - def __new__( - cls, - arg_: typing.Sequence[ - typing.Union[ - Schema_.Items[tuple], - list, - tuple - ] - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> NestedItems.Schema_.Items[tuple]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - NestedItems.Schema_.Items[tuple], - inst - ) - return inst - - def __getitem__(self, name: int) -> Schema_.Items[tuple]: - return super().__getitem__(name) + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore def __new__( cls, arg_: typing.Sequence[ typing.Union[ - Schema_.Items[tuple], + Items[tuple], list, tuple ] @@ -150,5 +162,6 @@ def __new__( ) return inst - def __getitem__(self, name: int) -> Schema_.Items[tuple]: + def __getitem__(self, name: int) -> Items[tuple]: return super().__getitem__(name) + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/nested_oneof_to_check_validation_semantics.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/nested_oneof_to_check_validation_semantics.py index 8d4b1adf428..92dbb5d3bf5 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/nested_oneof_to_check_validation_semantics.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/nested_oneof_to_check_validation_semantics.py @@ -10,6 +10,67 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +_02: typing_extensions.TypeAlias = schemas.NoneSchema[U] +OneOf = typing.Tuple[ + typing.Type[_02[schemas.U]], +] + + +class _0( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + one_of: OneOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(OneOf)) # type: ignore + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _0[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _0[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + +OneOf = typing.Tuple[ + typing.Type[_0[schemas.U]], +] + class NestedOneofToCheckValidationSemantics( schemas.AnyTypeSchema[schemas.T], @@ -21,146 +82,17 @@ class NestedOneofToCheckValidationSemantics( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class OneOf: - - - class _0( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - - class OneOf: - _0: typing_extensions.TypeAlias = schemas.NoneSchema[U] - classes = [ - _0, - ] - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> NestedOneofToCheckValidationSemantics.Schema_.OneOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - NestedOneofToCheckValidationSemantics.Schema_.OneOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - classes = [ - _0, - ] + one_of: OneOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(OneOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> NestedOneofToCheckValidationSemantics[ typing.Union[ frozendict.frozendict, @@ -195,3 +127,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/not_more_complex_schema.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/not_more_complex_schema.py index 53f3d33f485..7d6875a4d83 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/not_more_complex_schema.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/not_more_complex_schema.py @@ -10,6 +10,75 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +Foo: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "foo": typing.Type[Foo], + } +) + + +class _Not( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Foo[str]: ... + + @typing.overload + def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + def __getitem__( + self, + name: typing.Union[ + typing_extensions.Literal["foo"], + str + ] + ): + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + foo: typing.Union[ + Foo[str], + schemas.Unset, + str + ] = schemas.unset, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _Not[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + foo=foo, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _Not[frozendict.frozendict], + inst + ) + return inst + + class NotMoreComplexSchema( schemas.AnyTypeSchema[schemas.T], @@ -21,132 +90,17 @@ class NotMoreComplexSchema( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - - class _Not( - schemas.DictSchema[schemas.T] - ): - - - class Schema_: - types = {frozendict.frozendict} - - class Properties: - Foo: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "foo": Foo, - } - - @typing.overload - def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Schema_.Properties.Foo[str]: ... - - @typing.overload - def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: ... - - def __getitem__( - self, - name: typing.Union[ - typing_extensions.Literal["foo"], - str - ] - ): - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[dict, frozendict.frozendict], - foo: typing.Union[ - Schema_.Properties.Foo[str], - schemas.Unset, - str - ] = schemas.unset, - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> NotMoreComplexSchema.Schema_._Not[frozendict.frozendict]: - inst = super().__new__( - cls, - *args_, - foo=foo, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - NotMoreComplexSchema.Schema_._Not[frozendict.frozendict], - inst - ) - return inst + not_: typing.Type[_Not] = dataclasses.field(default_factory=lambda: _Not) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> NotMoreComplexSchema[ typing.Union[ frozendict.frozendict, @@ -181,3 +135,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/nul_characters_in_strings.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/nul_characters_in_strings.py index 81fd03d3a97..18316568c3c 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/nul_characters_in_strings.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/nul_characters_in_strings.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class NulCharactersInStrings( schemas.StrSchema[schemas.T] ): @@ -21,14 +22,17 @@ class NulCharactersInStrings( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ str, - } - enum_value_to_name = { - "hello\x00there": "HELLO_NULL_THERE", - } + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "hello\x00there": "HELLO_NULL_THERE", + } + ) @schemas.classproperty - def HELLO_NULL_THERE(cls): + def HELLO_NULL_THERE(cls) -> NulCharactersInStrings[str]: return cls("hello\x00there") # type: ignore diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/null_type_matches_only_the_null_object.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/null_type_matches_only_the_null_object.py index bf8f516615d..8fcdc3127ba 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/null_type_matches_only_the_null_object.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/null_type_matches_only_the_null_object.py @@ -9,4 +9,5 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * + NullTypeMatchesOnlyTheNullObject: typing_extensions.TypeAlias = schemas.NoneSchema[U] diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/number_type_matches_numbers.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/number_type_matches_numbers.py index 6f006c9185c..f7e661dfad2 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/number_type_matches_numbers.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/number_type_matches_numbers.py @@ -9,4 +9,5 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * + NumberTypeMatchesNumbers: typing_extensions.TypeAlias = schemas.NumberSchema[U] diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/object_properties_validation.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/object_properties_validation.py index f1dcf90c1a1..3bf18389483 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/object_properties_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/object_properties_validation.py @@ -10,6 +10,16 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +Foo: typing_extensions.TypeAlias = schemas.IntSchema[U] +Bar: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "foo": typing.Type[Foo], + "bar": typing.Type[Bar], + } +) + class ObjectPropertiesValidation( schemas.AnyTypeSchema[schemas.T], @@ -21,23 +31,17 @@ class ObjectPropertiesValidation( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class Properties: - Foo: typing_extensions.TypeAlias = schemas.IntSchema[U] - Bar: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "foo": Foo, - "bar": Bar, - } + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Schema_.Properties.Foo[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Foo[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["bar"]) -> Schema_.Properties.Bar[str]: ... + def __getitem__(self, name: typing_extensions.Literal["bar"]) -> Bar[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -64,55 +68,20 @@ def __getitem__( def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, foo: typing.Union[ - Schema_.Properties.Foo[decimal.Decimal], + Foo[decimal.Decimal], schemas.Unset, decimal.Decimal, int ] = schemas.unset, bar: typing.Union[ - Schema_.Properties.Bar[str], + Bar[str], schemas.Unset, str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ObjectPropertiesValidation[ typing.Union[ frozendict.frozendict, @@ -149,3 +118,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/object_type_matches_objects.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/object_type_matches_objects.py index a0ee6e9bcbd..f95a814a561 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/object_type_matches_objects.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/object_type_matches_objects.py @@ -9,4 +9,5 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * + ObjectTypeMatchesObjects: typing_extensions.TypeAlias = schemas.DictSchema[U] diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/oneof.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/oneof.py index 4c875b6609e..b920d695a4f 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/oneof.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/oneof.py @@ -10,6 +10,65 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +_0: typing_extensions.TypeAlias = schemas.IntSchema[U] + + +class _1( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + inclusive_minimum: typing.Union[int, float] = 2 + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _1[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _1[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + +OneOf = typing.Tuple[ + typing.Type[_0[schemas.U]], + typing.Type[_1[schemas.U]], +] + class Oneof( schemas.AnyTypeSchema[schemas.T], @@ -21,143 +80,17 @@ class Oneof( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class OneOf: - _0: typing_extensions.TypeAlias = schemas.IntSchema[U] - - - class _1( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - inclusive_minimum = 2 - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> Oneof.Schema_.OneOf._1[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - Oneof.Schema_.OneOf._1[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - classes = [ - _0, - _1, - ] + one_of: OneOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(OneOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Oneof[ typing.Union[ frozendict.frozendict, @@ -192,3 +125,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/oneof_complex_types.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/oneof_complex_types.py index c17dccc2bb1..9a95c94c98c 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/oneof_complex_types.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/oneof_complex_types.py @@ -10,50 +10,84 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +Bar: typing_extensions.TypeAlias = schemas.IntSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "bar": typing.Type[Bar], + } +) -class OneofComplexTypes( + +class _0( schemas.AnyTypeSchema[schemas.T], ): - """NOTE: This class is auto generated by OpenAPI JSON Schema Generator. - Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator - - Do not edit the class manually. - """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class OneOf: - - - class _0( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - required = { - "bar", - } - - class Properties: - Bar: typing_extensions.TypeAlias = schemas.IntSchema[U] - __annotations__ = { - "bar": Bar, - } - - - @property - def bar(self) -> Schema_.Properties.Bar[decimal.Decimal]: - return self.__getitem__("bar") - - @typing.overload - def __getitem__(self, name: typing_extensions.Literal["bar"]) -> Schema_.Properties.Bar[decimal.Decimal]: ... - - @typing.overload - def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + required: typing.FrozenSet[str] = frozenset({ + "bar", + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + + + @property + def bar(self) -> Bar[decimal.Decimal]: + return self.__getitem__("bar") + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["bar"]) -> Bar[decimal.Decimal]: ... + + @typing.overload + def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + def __getitem__( + self, + name: typing.Union[ + typing_extensions.Literal["bar"], + str + ] + ): + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _0[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _0[ + typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -62,121 +96,90 @@ def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ tuple, bytes, schemas.FileIO - ]]: ... - - def __getitem__( - self, - name: typing.Union[ - typing_extensions.Literal["bar"], - str - ] - ): - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> OneofComplexTypes.Schema_.OneOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - OneofComplexTypes.Schema_.OneOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - - - class _1( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - required = { - "foo", - } - - class Properties: - Foo: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "foo": Foo, - } - - - @property - def foo(self) -> Schema_.Properties.Foo[str]: - return self.__getitem__("foo") - - @typing.overload - def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Schema_.Properties.Foo[str]: ... - - @typing.overload - def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + ] + ], + inst + ) + return inst + +Foo: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties2 = typing_extensions.TypedDict( + 'Properties2', + { + "foo": typing.Type[Foo], + } +) + + +class _1( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + required: typing.FrozenSet[str] = frozenset({ + "foo", + }) + properties: Properties2 = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties2)) # type: ignore + + + @property + def foo(self) -> Foo[str]: + return self.__getitem__("foo") + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Foo[str]: ... + + @typing.overload + def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + def __getitem__( + self, + name: typing.Union[ + typing_extensions.Literal["foo"], + str + ] + ): + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _1[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _1[ + typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -185,138 +188,39 @@ def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ tuple, bytes, schemas.FileIO - ]]: ... - - def __getitem__( - self, - name: typing.Union[ - typing_extensions.Literal["foo"], - str - ] - ): - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> OneofComplexTypes.Schema_.OneOf._1[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - OneofComplexTypes.Schema_.OneOf._1[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - classes = [ - _0, - _1, - ] + ] + ], + inst + ) + return inst + +OneOf = typing.Tuple[ + typing.Type[_0[schemas.U]], + typing.Type[_1[schemas.U]], +] + + +class OneofComplexTypes( + schemas.AnyTypeSchema[schemas.T], +): + """NOTE: This class is auto generated by OpenAPI JSON Schema Generator. + Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator + + Do not edit the class manually. + """ + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + one_of: OneOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(OneOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> OneofComplexTypes[ typing.Union[ frozendict.frozendict, @@ -351,3 +255,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/oneof_with_base_schema.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/oneof_with_base_schema.py index 54eebb13e28..b8ba029a4eb 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/oneof_with_base_schema.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/oneof_with_base_schema.py @@ -11,6 +11,117 @@ from unit_test_api.shared_imports.schema_imports import * + +class _0( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + min_length: int = 2 + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _0[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _0[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + + + +class _1( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + max_length: int = 4 + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _1[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _1[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + +OneOf = typing.Tuple[ + typing.Type[_0[schemas.U]], + typing.Type[_1[schemas.U]], +] + + class OneofWithBaseSchema( schemas.StrSchema[schemas.T] ): @@ -21,188 +132,12 @@ class OneofWithBaseSchema( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ str, - } - - class OneOf: - - - class _0( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - min_length = 2 - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> OneofWithBaseSchema.Schema_.OneOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - OneofWithBaseSchema.Schema_.OneOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - - - class _1( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - max_length = 4 - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> OneofWithBaseSchema.Schema_.OneOf._1[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - OneofWithBaseSchema.Schema_.OneOf._1[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - classes = [ - _0, - _1, - ] + }) + one_of: OneOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(OneOf)) # type: ignore def __new__( @@ -220,3 +155,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/oneof_with_empty_schema.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/oneof_with_empty_schema.py index baeaf6785e3..ca8705889a2 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/oneof_with_empty_schema.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/oneof_with_empty_schema.py @@ -10,6 +10,13 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +_0: typing_extensions.TypeAlias = schemas.NumberSchema[U] +_1: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] +OneOf = typing.Tuple[ + typing.Type[_0[schemas.U]], + typing.Type[_1[schemas.U]], +] + class OneofWithEmptySchema( schemas.AnyTypeSchema[schemas.T], @@ -21,58 +28,17 @@ class OneofWithEmptySchema( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class OneOf: - _0: typing_extensions.TypeAlias = schemas.NumberSchema[U] - _1: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - classes = [ - _0, - _1, - ] + one_of: OneOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(OneOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> OneofWithEmptySchema[ typing.Union[ frozendict.frozendict, @@ -107,3 +73,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/oneof_with_required.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/oneof_with_required.py index dc1ba609c6d..535bdd7fdac 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/oneof_with_required.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/oneof_with_required.py @@ -11,239 +11,120 @@ from unit_test_api.shared_imports.schema_imports import * -class OneofWithRequired( - schemas.DictSchema[schemas.T] + +class _0( + schemas.AnyTypeSchema[schemas.T], ): - """NOTE: This class is auto generated by OpenAPI JSON Schema Generator. - Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator - Do not edit the class manually. - """ + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + required: typing.FrozenSet[str] = frozenset({ + "bar", + "foo", + }) - class Schema_: - types = { + + @property + def bar(self) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: + return self.__getitem__("bar") + + @property + def foo(self) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: + return self.__getitem__("foo") + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["bar"]) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["foo"]) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + @typing.overload + def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + def __getitem__( + self, + name: typing.Union[ + typing_extensions.Literal["bar"], + typing_extensions.Literal["foo"], + str + ] + ): + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _0[ + typing.Union[ frozendict.frozendict, - } - - class OneOf: - - - class _0( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - required = { - "bar", - "foo", - } - - - @property - def bar(self) -> schemas.AnyTypeSchema[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: - return self.__getitem__("bar") - - @property - def foo(self) -> schemas.AnyTypeSchema[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: - return self.__getitem__("foo") - - @typing.overload - def __getitem__(self, name: typing_extensions.Literal["bar"]) -> schemas.AnyTypeSchema[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: ... - - @typing.overload - def __getitem__(self, name: typing_extensions.Literal["foo"]) -> schemas.AnyTypeSchema[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: ... - - @typing.overload - def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: ... - - def __getitem__( - self, - name: typing.Union[ - typing_extensions.Literal["bar"], - typing_extensions.Literal["foo"], - str - ] - ): - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> OneofWithRequired.Schema_.OneOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - OneofWithRequired.Schema_.OneOf._0[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - - - class _1( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - required = { - "baz", - "foo", - } - - - @property - def baz(self) -> schemas.AnyTypeSchema[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: - return self.__getitem__("baz") - - @property - def foo(self) -> schemas.AnyTypeSchema[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: - return self.__getitem__("foo") - - @typing.overload - def __getitem__(self, name: typing_extensions.Literal["baz"]) -> schemas.AnyTypeSchema[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: ... - - @typing.overload - def __getitem__(self, name: typing_extensions.Literal["foo"]) -> schemas.AnyTypeSchema[typing.Union[ + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _0[ + typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -252,10 +133,127 @@ def __getitem__(self, name: typing_extensions.Literal["foo"]) -> schemas.AnyType tuple, bytes, schemas.FileIO - ]]: ... - - @typing.overload - def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + ] + ], + inst + ) + return inst + + + +class _1( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + required: typing.FrozenSet[str] = frozenset({ + "baz", + "foo", + }) + + + @property + def baz(self) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: + return self.__getitem__("baz") + + @property + def foo(self) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: + return self.__getitem__("foo") + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["baz"]) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["foo"]) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + @typing.overload + def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + def __getitem__( + self, + name: typing.Union[ + typing_extensions.Literal["baz"], + typing_extensions.Literal["foo"], + str + ] + ): + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _1[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _1[ + typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -264,122 +262,41 @@ def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ tuple, bytes, schemas.FileIO - ]]: ... - - def __getitem__( - self, - name: typing.Union[ - typing_extensions.Literal["baz"], - typing_extensions.Literal["foo"], - str - ] - ): - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> OneofWithRequired.Schema_.OneOf._1[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - OneofWithRequired.Schema_.OneOf._1[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - classes = [ - _0, - _1, - ] + ] + ], + inst + ) + return inst + +OneOf = typing.Tuple[ + typing.Type[_0[schemas.U]], + typing.Type[_1[schemas.U]], +] + + +class OneofWithRequired( + schemas.DictSchema[schemas.T] +): + """NOTE: This class is auto generated by OpenAPI JSON Schema Generator. + Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator + + Do not edit the class manually. + """ + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + frozendict.frozendict, + }) + one_of: OneOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(OneOf)) # type: ignore def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> OneofWithRequired[frozendict.frozendict]: inst = super().__new__( cls, @@ -392,3 +309,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/pattern_is_not_anchored.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/pattern_is_not_anchored.py index 72ff5e064f2..16416b2de31 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/pattern_is_not_anchored.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/pattern_is_not_anchored.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class PatternIsNotAnchored( schemas.AnyTypeSchema[schemas.T], ): @@ -21,53 +22,19 @@ class PatternIsNotAnchored( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - regex={ - 'pattern': r'a+', # noqa: E501 - } + pattern: schemas.PatternInfo = schemas.PatternInfo( + pattern=r'a+' # noqa: E501 + ) def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> PatternIsNotAnchored[ typing.Union[ frozendict.frozendict, @@ -102,3 +69,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/pattern_validation.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/pattern_validation.py index 2fab3d72df1..cd28f452f0d 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/pattern_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/pattern_validation.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class PatternValidation( schemas.AnyTypeSchema[schemas.T], ): @@ -21,53 +22,19 @@ class PatternValidation( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - regex={ - 'pattern': r'^a*$', # noqa: E501 - } + pattern: schemas.PatternInfo = schemas.PatternInfo( + pattern=r'^a*$' # noqa: E501 + ) def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> PatternValidation[ typing.Union[ frozendict.frozendict, @@ -102,3 +69,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/properties_with_escaped_characters.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/properties_with_escaped_characters.py index b33e742b085..cfb37ff352d 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/properties_with_escaped_characters.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/properties_with_escaped_characters.py @@ -10,6 +10,24 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +FooNbar: typing_extensions.TypeAlias = schemas.NumberSchema[U] +FooBar: typing_extensions.TypeAlias = schemas.NumberSchema[U] +FooBar: typing_extensions.TypeAlias = schemas.NumberSchema[U] +FooRbar: typing_extensions.TypeAlias = schemas.NumberSchema[U] +FooTbar: typing_extensions.TypeAlias = schemas.NumberSchema[U] +FooFbar: typing_extensions.TypeAlias = schemas.NumberSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "foo\nbar": typing.Type[FooNbar], + "foo\"bar": typing.Type[FooBar], + "foo\\bar": typing.Type[FooBar], + "foo\rbar": typing.Type[FooRbar], + "foo\tbar": typing.Type[FooTbar], + "foo\fbar": typing.Type[FooFbar], + } +) + class PropertiesWithEscapedCharacters( schemas.AnyTypeSchema[schemas.T], @@ -21,43 +39,29 @@ class PropertiesWithEscapedCharacters( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class Properties: - FooNbar: typing_extensions.TypeAlias = schemas.NumberSchema[U] - FooBar: typing_extensions.TypeAlias = schemas.NumberSchema[U] - FooBar: typing_extensions.TypeAlias = schemas.NumberSchema[U] - FooRbar: typing_extensions.TypeAlias = schemas.NumberSchema[U] - FooTbar: typing_extensions.TypeAlias = schemas.NumberSchema[U] - FooFbar: typing_extensions.TypeAlias = schemas.NumberSchema[U] - __annotations__ = { - "foo\nbar": FooNbar, - "foo\"bar": FooBar, - "foo\\bar": FooBar, - "foo\rbar": FooRbar, - "foo\tbar": FooTbar, - "foo\fbar": FooFbar, - } + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["foo\nbar"]) -> Schema_.Properties.FooNbar[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["foo\nbar"]) -> FooNbar[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["foo\"bar"]) -> Schema_.Properties.FooBar[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["foo\"bar"]) -> FooBar[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["foo\\bar"]) -> Schema_.Properties.FooBar[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["foo\\bar"]) -> FooBar[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["foo\rbar"]) -> Schema_.Properties.FooRbar[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["foo\rbar"]) -> FooRbar[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["foo\tbar"]) -> Schema_.Properties.FooTbar[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["foo\tbar"]) -> FooTbar[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["foo\fbar"]) -> Schema_.Properties.FooFbar[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["foo\fbar"]) -> FooFbar[decimal.Decimal]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -88,44 +92,9 @@ def __getitem__( def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> PropertiesWithEscapedCharacters[ typing.Union[ frozendict.frozendict, @@ -160,3 +129,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/property_named_ref_that_is_not_a_reference.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/property_named_ref_that_is_not_a_reference.py index f1ec8573687..6f1a114f1b7 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/property_named_ref_that_is_not_a_reference.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/property_named_ref_that_is_not_a_reference.py @@ -10,6 +10,14 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +Ref: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "$ref": typing.Type[Ref], + } +) + class PropertyNamedRefThatIsNotAReference( schemas.AnyTypeSchema[schemas.T], @@ -21,18 +29,14 @@ class PropertyNamedRefThatIsNotAReference( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class Properties: - Ref: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "$ref": Ref, - } + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["$ref"]) -> Schema_.Properties.Ref[str]: ... + def __getitem__(self, name: typing_extensions.Literal["$ref"]) -> Ref[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -58,44 +62,9 @@ def __getitem__( def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> PropertyNamedRefThatIsNotAReference[ typing.Union[ frozendict.frozendict, @@ -130,3 +99,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_additionalproperties.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_additionalproperties.py index e9b0a5205f3..aec11997502 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_additionalproperties.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_additionalproperties.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class RefInAdditionalproperties( schemas.DictSchema[schemas.T] ): @@ -21,12 +22,10 @@ class RefInAdditionalproperties( """ - class Schema_: - types = {frozendict.frozendict} - - @staticmethod - def additional_properties() -> typing.Type[property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference]: - return property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + additional_properties: typing.Type[property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference] = dataclasses.field(default_factory=lambda: property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference) # type: ignore def __getitem__(self, name: str) -> property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference[typing.Union[ frozendict.frozendict, @@ -46,16 +45,9 @@ def __new__( *args_: typing.Union[dict, frozendict.frozendict], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, **kwargs: typing.Union[ - property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference[ + schemas.INPUT_BASE_TYPES + ], dict, frozendict.frozendict, str, @@ -86,4 +78,5 @@ def __new__( ) return inst + from unit_test_api.components.schema import property_named_ref_that_is_not_a_reference diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_allof.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_allof.py index e5a66061416..4dca37c7804 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_allof.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_allof.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class RefInAllof( schemas.AnyTypeSchema[schemas.T], ): @@ -21,59 +22,17 @@ class RefInAllof( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AllOf: - - @staticmethod - def _0() -> typing.Type[property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference]: - return property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference - classes = [ - _0, - ] + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> RefInAllof[ typing.Union[ frozendict.frozendict, @@ -109,4 +68,8 @@ def __new__( ) return inst + from unit_test_api.components.schema import property_named_ref_that_is_not_a_reference +AllOf = typing.Tuple[ + typing.Type[property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference], +] diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_anyof.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_anyof.py index 0f9fe6d1f87..5f4b98a0e92 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_anyof.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_anyof.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class RefInAnyof( schemas.AnyTypeSchema[schemas.T], ): @@ -21,59 +22,17 @@ class RefInAnyof( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AnyOf: - - @staticmethod - def _0() -> typing.Type[property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference]: - return property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference - classes = [ - _0, - ] + any_of: AnyOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AnyOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> RefInAnyof[ typing.Union[ frozendict.frozendict, @@ -109,4 +68,8 @@ def __new__( ) return inst + from unit_test_api.components.schema import property_named_ref_that_is_not_a_reference +AnyOf = typing.Tuple[ + typing.Type[property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference], +] diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_items.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_items.py index 3b4d5f59763..51d6c06e927 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_items.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_items.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class RefInItems( schemas.ListSchema[schemas.T] ): @@ -21,27 +22,18 @@ class RefInItems( """ - class Schema_: - types = {tuple} - - @staticmethod - def items() -> typing.Type[property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference]: - return property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference] = dataclasses.field(default_factory=lambda: property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference) # type: ignore def __new__( cls, arg_: typing.Sequence[ typing.Union[ - property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference[ + schemas.INPUT_BASE_TYPES + ], dict, frozendict.frozendict, str, @@ -85,4 +77,5 @@ def __getitem__(self, name: int) -> property_named_ref_that_is_not_a_reference.P ]]: return super().__getitem__(name) + from unit_test_api.components.schema import property_named_ref_that_is_not_a_reference diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_not.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_not.py index 5a139ae4739..5a9f9a7e7b6 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_not.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_not.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class RefInNot( schemas.AnyTypeSchema[schemas.T], ): @@ -21,54 +22,17 @@ class RefInNot( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - @staticmethod - def _not() -> typing.Type[property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference]: - return property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference + not_: typing.Type[property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference] = dataclasses.field(default_factory=lambda: property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> RefInNot[ typing.Union[ frozendict.frozendict, @@ -104,4 +68,5 @@ def __new__( ) return inst + from unit_test_api.components.schema import property_named_ref_that_is_not_a_reference diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_oneof.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_oneof.py index c5da56f37f3..58548748ba2 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_oneof.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_oneof.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class RefInOneof( schemas.AnyTypeSchema[schemas.T], ): @@ -21,59 +22,17 @@ class RefInOneof( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class OneOf: - - @staticmethod - def _0() -> typing.Type[property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference]: - return property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference - classes = [ - _0, - ] + one_of: OneOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(OneOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> RefInOneof[ typing.Union[ frozendict.frozendict, @@ -109,4 +68,8 @@ def __new__( ) return inst + from unit_test_api.components.schema import property_named_ref_that_is_not_a_reference +OneOf = typing.Tuple[ + typing.Type[property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference], +] diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_property.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_property.py index 4fc7813ae2c..9be138cf449 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_property.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/ref_in_property.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class RefInProperty( schemas.AnyTypeSchema[schemas.T], ): @@ -21,17 +22,10 @@ class RefInProperty( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class Properties: - - @staticmethod - def a() -> typing.Type[property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference]: - return property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference - __annotations__ = { - "a": a, - } + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload @@ -70,35 +64,11 @@ def __getitem__( def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, a: typing.Union[ - property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -118,25 +88,7 @@ def __new__( io.BufferedReader ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> RefInProperty[ typing.Union[ frozendict.frozendict, @@ -173,4 +125,11 @@ def __new__( ) return inst + from unit_test_api.components.schema import property_named_ref_that_is_not_a_reference +Properties = typing_extensions.TypedDict( + 'Properties', + { + "a": typing.Type[property_named_ref_that_is_not_a_reference.PropertyNamedRefThatIsNotAReference], + } +) diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/required_default_validation.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/required_default_validation.py index 766c2e51bb6..fcacf281873 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/required_default_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/required_default_validation.py @@ -10,6 +10,14 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +Foo: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "foo": typing.Type[Foo], + } +) + class RequiredDefaultValidation( schemas.AnyTypeSchema[schemas.T], @@ -21,18 +29,14 @@ class RequiredDefaultValidation( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class Properties: - Foo: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - __annotations__ = { - "foo": Foo, - } + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Schema_.Properties.Foo[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Foo[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -67,35 +71,11 @@ def __getitem__( def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, foo: typing.Union[ - Schema_.Properties.Foo[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + Foo[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -115,25 +95,7 @@ def __new__( io.BufferedReader ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> RequiredDefaultValidation[ typing.Union[ frozendict.frozendict, @@ -169,3 +131,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/required_validation.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/required_validation.py index 5c6f3623ea7..216367e2b8e 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/required_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/required_validation.py @@ -10,6 +10,16 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +Foo: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] +Bar: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "foo": typing.Type[Foo], + "bar": typing.Type[Bar], + } +) + class RequiredValidation( schemas.AnyTypeSchema[schemas.T], @@ -21,23 +31,17 @@ class RequiredValidation( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - required = { + required: typing.FrozenSet[str] = frozenset({ "foo", - } - - class Properties: - Foo: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - Bar: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - __annotations__ = { - "foo": Foo, - "bar": Bar, - } + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @property - def foo(self) -> Schema_.Properties.Foo[typing.Union[ + def foo(self) -> Foo[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -50,7 +54,7 @@ def foo(self) -> Schema_.Properties.Foo[typing.Union[ return self.__getitem__("foo") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Schema_.Properties.Foo[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Foo[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -62,7 +66,7 @@ def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Schema_.Propert ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["bar"]) -> Schema_.Properties.Bar[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["bar"]) -> Bar[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -98,35 +102,11 @@ def __getitem__( def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, bar: typing.Union[ - Schema_.Properties.Bar[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + Bar[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -146,25 +126,7 @@ def __new__( io.BufferedReader ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> RequiredValidation[ typing.Union[ frozendict.frozendict, @@ -200,3 +162,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/required_with_empty_array.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/required_with_empty_array.py index 4dc13bd91c9..127ee15485b 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/required_with_empty_array.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/required_with_empty_array.py @@ -10,6 +10,14 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * +Foo: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "foo": typing.Type[Foo], + } +) + class RequiredWithEmptyArray( schemas.AnyTypeSchema[schemas.T], @@ -21,18 +29,14 @@ class RequiredWithEmptyArray( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class Properties: - Foo: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - __annotations__ = { - "foo": Foo, - } + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Schema_.Properties.Foo[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Foo[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -67,35 +71,11 @@ def __getitem__( def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, foo: typing.Union[ - Schema_.Properties.Foo[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + Foo[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -115,25 +95,7 @@ def __new__( io.BufferedReader ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> RequiredWithEmptyArray[ typing.Union[ frozendict.frozendict, @@ -169,3 +131,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/required_with_escaped_characters.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/required_with_escaped_characters.py index f48b099cd21..26295127b1f 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/required_with_escaped_characters.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/required_with_escaped_characters.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class RequiredWithEscapedCharacters( schemas.AnyTypeSchema[schemas.T], ): @@ -21,16 +22,17 @@ class RequiredWithEscapedCharacters( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - required = { + required: typing.FrozenSet[str] = frozenset({ "foo\tbar", "foo\nbar", "foo\fbar", "foo\rbar", "foo\"bar", "foo\\bar", - } + }) @typing.overload @@ -134,44 +136,9 @@ def __getitem__( def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> RequiredWithEscapedCharacters[ typing.Union[ frozendict.frozendict, @@ -206,3 +173,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/simple_enum_validation.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/simple_enum_validation.py index a61183718df..8a5016a19e3 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/simple_enum_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/simple_enum_validation.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class SimpleEnumValidation( schemas.NumberSchema[schemas.T] ): @@ -21,24 +22,27 @@ class SimpleEnumValidation( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ decimal.Decimal, - } - enum_value_to_name = { - 1: "POSITIVE_1", - 2: "POSITIVE_2", - 3: "POSITIVE_3", - } + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + 1: "POSITIVE_1", + 2: "POSITIVE_2", + 3: "POSITIVE_3", + } + ) @schemas.classproperty - def POSITIVE_1(cls): + def POSITIVE_1(cls) -> SimpleEnumValidation[decimal.Decimal]: return cls(1) # type: ignore @schemas.classproperty - def POSITIVE_2(cls): + def POSITIVE_2(cls) -> SimpleEnumValidation[decimal.Decimal]: return cls(2) # type: ignore @schemas.classproperty - def POSITIVE_3(cls): + def POSITIVE_3(cls) -> SimpleEnumValidation[decimal.Decimal]: return cls(3) # type: ignore diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/string_type_matches_strings.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/string_type_matches_strings.py index c275c4f8bab..b0923a98520 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/string_type_matches_strings.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/string_type_matches_strings.py @@ -9,4 +9,5 @@ from __future__ import annotations from unit_test_api.shared_imports.schema_imports import * + StringTypeMatchesStrings: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/the_default_keyword_does_not_do_anything_if_the_property_is_missing.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/the_default_keyword_does_not_do_anything_if_the_property_is_missing.py index d07431c05a0..c33552ffbef 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/the_default_keyword_does_not_do_anything_if_the_property_is_missing.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/the_default_keyword_does_not_do_anything_if_the_property_is_missing.py @@ -11,6 +11,27 @@ from unit_test_api.shared_imports.schema_imports import * + +class Alpha( + schemas.NumberSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + decimal.Decimal, + }) + inclusive_maximum: typing.Union[int, float] = 3 + default: typing.Union[int, float] = 5 +Properties = typing_extensions.TypedDict( + 'Properties', + { + "alpha": typing.Type[Alpha], + } +) + + class TheDefaultKeywordDoesNotDoAnythingIfThePropertyIsMissing( schemas.DictSchema[schemas.T] ): @@ -21,29 +42,13 @@ class TheDefaultKeywordDoesNotDoAnythingIfThePropertyIsMissing( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - - class Alpha( - schemas.NumberSchema[schemas.T] - ): - - - class Schema_: - types = { - decimal.Decimal, - } - inclusive_maximum = 3 - default = 5 - __annotations__ = { - "alpha": Alpha, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["alpha"]) -> Schema_.Properties.Alpha[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["alpha"]) -> Alpha[decimal.Decimal]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -71,32 +76,14 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], alpha: typing.Union[ - Schema_.Properties.Alpha[decimal.Decimal], + Alpha[decimal.Decimal], schemas.Unset, decimal.Decimal, int, float ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> TheDefaultKeywordDoesNotDoAnythingIfThePropertyIsMissing[frozendict.frozendict]: inst = super().__new__( cls, @@ -110,3 +97,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/uniqueitems_false_validation.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/uniqueitems_false_validation.py index da3746ad462..276bb8fd317 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/uniqueitems_false_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/uniqueitems_false_validation.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class UniqueitemsFalseValidation( schemas.AnyTypeSchema[schemas.T], ): @@ -21,51 +22,17 @@ class UniqueitemsFalseValidation( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - unique_items = False + unique_items: bool = False def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> UniqueitemsFalseValidation[ typing.Union[ frozendict.frozendict, @@ -100,3 +67,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/uniqueitems_validation.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/uniqueitems_validation.py index 980c83f98e1..144918fc43a 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/uniqueitems_validation.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/uniqueitems_validation.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class UniqueitemsValidation( schemas.AnyTypeSchema[schemas.T], ): @@ -21,51 +22,17 @@ class UniqueitemsValidation( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - unique_items = True + unique_items: bool = True def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> UniqueitemsValidation[ typing.Union[ frozendict.frozendict, @@ -100,3 +67,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/uri_format.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/uri_format.py index 15599d775e5..a5d4cc3df6e 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/uri_format.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/uri_format.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class UriFormat( schemas.AnyTypeSchema[schemas.T], ): @@ -21,51 +22,17 @@ class UriFormat( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - format = 'uri' + format: str = 'uri' def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> UriFormat[ typing.Union[ frozendict.frozendict, @@ -100,3 +67,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/uri_reference_format.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/uri_reference_format.py index 0e95c99f9f9..0459886ab18 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/uri_reference_format.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/uri_reference_format.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class UriReferenceFormat( schemas.AnyTypeSchema[schemas.T], ): @@ -21,51 +22,17 @@ class UriReferenceFormat( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - format = 'uri-reference' + format: str = 'uri-reference' def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> UriReferenceFormat[ typing.Union[ frozendict.frozendict, @@ -100,3 +67,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/uri_template_format.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/uri_template_format.py index cb9707e53f3..24ae897eecd 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/uri_template_format.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/components/schema/uri_template_format.py @@ -11,6 +11,7 @@ from unit_test_api.shared_imports.schema_imports import * + class UriTemplateFormat( schemas.AnyTypeSchema[schemas.T], ): @@ -21,51 +22,17 @@ class UriTemplateFormat( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - format = 'uri-template' + format: str = 'uri-template' def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> UriTemplateFormat[ typing.Union[ frozendict.frozendict, @@ -100,3 +67,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/configurations/schema_configuration.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/configurations/schema_configuration.py index 3a91b77b502..ffc69a3a8a1 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/configurations/schema_configuration.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/configurations/schema_configuration.py @@ -13,34 +13,32 @@ PYTHON_KEYWORD_TO_JSON_SCHEMA_KEYWORD = { - 'types': 'type', + 'additional_properties': 'additionalProperties', + 'all_of': 'allOf', + 'any_of': 'anyOf', + 'discriminator': 'discriminator', + # default omitted because it has no validation impact 'enum_value_to_name': 'enum', - 'unique_items': 'uniqueItems', - 'min_items': 'minItems', + 'exclusive_maximum': 'exclusiveMaximum', + 'exclusive_minimum': 'exclusiveMinimum', + 'format': 'format', + 'inclusive_maximum': 'maximum', + 'inclusive_minimum': 'minimum', + 'items': 'items', 'max_items': 'maxItems', - 'min_properties': 'minProperties', + 'max_length': 'maxLength', 'max_properties': 'maxProperties', + 'min_items': 'minItems', 'min_length': 'minLength', - 'max_length': 'maxLength', - 'inclusive_minimum': 'minimum', - 'exclusive_minimum': 'exclusiveMinimum', - 'inclusive_maximum': 'maximum', - 'exclusive_maximum': 'exclusiveMaximum', + 'min_properties': 'minProperties', 'multiple_of': 'multipleOf', - 'regex': 'pattern', - 'format': 'format', + 'not_': 'not', + 'one_of': 'oneOf', + 'pattern': 'pattern', + 'properties': 'properties', 'required': 'required', - 'items': 'items', - 'Items': 'items', - 'Properties': 'properties', - 'additional_properties': 'additionalProperties', - 'additionalProperties': 'additionalProperties', - 'OneOf': 'oneOf', - 'AnyOf': 'anyOf', - 'AllOf': 'allOf', - '_not': 'not', - '_Not': 'not', - 'discriminator': 'discriminator' + 'types': 'type', + 'unique_items': 'uniqueItems' } class SchemaConfiguration: diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/schemas.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/schemas.py index 246bfae8fd6..58ba9d009c3 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/schemas.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/schemas.py @@ -13,6 +13,7 @@ import dataclasses import functools import decimal +import inspect import io import re import types @@ -111,6 +112,20 @@ def add_deeper_validated_schemas(validation_metadata: ValidationMetadata, path_t update(path_to_schemas, other_path_to_schemas) +class SingletonMeta(type): + """ + A singleton class for schemas + Schemas are frozen classes that are never instantiated with init args + All args come from defaults + """ + _instances = {} + + def __call__(cls, *args, **kwargs): + if cls not in cls._instances: + cls._instances[cls] = super().__call__(*args, **kwargs) + return cls._instances[cls] + + class Singleton: """ Enums and singletons are the same @@ -147,14 +162,18 @@ def __repr__(self): return f'<{self.__class__.__name__}: False>' return f'<{self.__class__.__name__}: {super().__repr__()}>' +T = typing.TypeVar('T') -class classproperty: - def __init__(self, fget): - self.fget = fget +class classproperty(typing.Generic[T]): + def __init__(self, method: typing.Callable[..., T]): + self.__method = method + functools.update_wrapper(self, method) # type: ignore - def __get__(self, owner_self, owner_cls): - return self.fget(owner_cls) + def __get__(self, obj, cls=None) -> T: + if cls is None: + cls = type(obj) + return self.__method(cls) class NoneClass(Singleton): @@ -183,32 +202,40 @@ def __bool__(self) -> bool: raise ValueError('Unable to find the boolean value of this instance') +@dataclasses.dataclass(frozen=True) +class PatternInfo: + pattern: str + flags: typing.Optional[re.RegexFlag] = None + + class SchemaTyped: - types: typing.Optional[typing.Set[typing.Type]] + additional_properties: typing.Type[Schema] + all_of: typing.Tuple[typing.Type[Schema], ...] + any_of: typing.Tuple[typing.Type[Schema], ...] + discriminator: typing.Mapping[str, typing.Mapping[str, typing.Type[Schema]]] + default: typing.Union[str, int, float, BoolClass, NoneClass] + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, BoolClass, NoneClass], str] exclusive_maximum: typing.Union[int, float] - inclusive_maximum: typing.Union[int, float] exclusive_minimum: typing.Union[int, float] + format: str + inclusive_maximum: typing.Union[int, float] inclusive_minimum: typing.Union[int, float] + items: typing.Type[Schema] max_items: int - min_items: int - discriminator: typing.Dict[str, typing.Dict[str, typing.Type['Schema']]] - default: typing.Union[str, int, BoolClass] - - - class Properties: - # to hold object properties - pass - - additionalProperties: typing.Optional[typing.Type['Schema']] - max_properties: int - min_properties: int - AllOf: typing.List[typing.Type['Schema']] - OneOf: typing.List[typing.Type['Schema']] - AnyOf: typing.List[typing.Type['Schema']] - _not: typing.Type['Schema'] max_length: int + max_properties: int + min_items: int min_length: int - items: typing.Type['Schema'] + min_properties: int + multiple_of: typing.Union[int, float] + not_: typing.Type[Schema] + one_of: typing.Tuple[typing.Type[Schema], ...] + pattern: PatternInfo + properties: typing.Mapping[str, typing.Type[Schema]] + required: typing.FrozenSet[str] + types: typing.FrozenSet[typing.Type] + unique_items: bool + PathToSchemasType = typing.Dict[ typing.Tuple[typing.Union[str, int], ...], @@ -530,30 +557,30 @@ def validate_multiple_of( return None -def validate_regex( +def validate_pattern( arg: typing.Any, - regex_dict: typing.Dict, + pattern_info: PatternInfo, cls: typing.Type, validation_metadata: ValidationMetadata, ) -> None: if not isinstance(arg, str): return None - flags = regex_dict.get('flags', 0) - if not re.search(regex_dict['pattern'], arg, flags=flags): + flags = pattern_info.flags if pattern_info.flags is not None else 0 + if not re.search(pattern_info.pattern, arg, flags=flags): if flags != 0: # Don't print the regex flags if the flags are not # specified in the OAS document. _raise_validation_error_message( value=arg, constraint_msg="must match regular expression", - constraint_value=regex_dict['pattern'], + constraint_value=pattern_info.pattern, path_to_item=validation_metadata.path_to_item, additional_txt=" with flags=`{}`".format(flags) ) _raise_validation_error_message( value=arg, constraint_msg="must match regular expression", - constraint_value=regex_dict['pattern'], + constraint_value=pattern_info.pattern, path_to_item=validation_metadata.path_to_item ) return None @@ -649,8 +676,8 @@ def __parse_isodate(self, dt_str: str) -> typing.Tuple[typing.Tuple[int, int, in def __parse_isotime(self, dt_str: str) -> typing.Tuple[int, int, int, int, typing.Optional[typing.Union[tz.tzutc, tz.tzoffset]]]: dt_str_ascii = self.__get_ascii_bytes(dt_str) values = self._parse_isotime(dt_str_ascii) # type: ignore - components: typing.Tuple[int, int, int, int, typing.Optional[typing.Union[tz.tzutc, tz.tzoffset]]] = tuple(values) - return tuple(components) + components: typing.Tuple[int, int, int, int, typing.Optional[typing.Union[tz.tzutc, tz.tzoffset]]] = tuple(values) # type: ignore + return components def parse_isodatetime(self, dt_str: str) -> datetime.datetime: components, pos = self.__parse_isodate(dt_str) @@ -786,17 +813,20 @@ def _get_class(item_cls: typing.Union[types.FunctionType, staticmethod, typing.T elif isinstance(item_cls, staticmethod): # referenced schema return item_cls.__func__() - return item_cls + elif isinstance(item_cls, type): + return item_cls + raise ValueError('invalid class value passed in') def validate_items( arg: typing.Any, - item_cls: typing.Type, + item_cls: typing.Type[Schema], cls: typing.Type, validation_metadata: ValidationMetadata, ) -> typing.Optional[PathToSchemasType]: if not isinstance(arg, tuple): return None + schema = _get_class(additional_properties_cls) item_cls = _get_class(item_cls) path_to_schemas = {} for i, value in enumerate(arg): @@ -816,17 +846,17 @@ def validate_items( def validate_properties( arg: typing.Any, - properties: typing.Type, + properties: typing.Mapping[str, typing.Type[Schema]], cls: typing.Type, validation_metadata: ValidationMetadata, ) -> typing.Optional[PathToSchemasType]: if not isinstance(arg, frozendict.frozendict): return None path_to_schemas = {} - present_properties = {k: v for k, v, in arg.items() if k in properties.__annotations__} + present_properties = {k: v for k, v, in arg.items() if k in properties} for property_name, value in present_properties.items(): path_to_item = validation_metadata.path_to_item + (property_name,) - schema = properties.__annotations__[property_name] + schema = properties[property_name] schema = _get_class(schema) arg_validation_metadata = ValidationMetadata( path_to_item=path_to_item, @@ -843,16 +873,17 @@ def validate_properties( def validate_additional_properties( arg: typing.Any, - additional_properties_schema: typing.Type, + additional_properties_cls: typing.Type[Schema], cls: typing.Type, validation_metadata: ValidationMetadata, ) -> typing.Optional[PathToSchemasType]: if not isinstance(arg, frozendict.frozendict): return None - schema = _get_class(additional_properties_schema) + schema = _get_class(additional_properties_cls) path_to_schemas = {} - properties_annotations = cls.Schema_.Properties.__annotations__ if hasattr(cls.Schema_, 'Properties') else {} - present_additional_properties = {k: v for k, v, in arg.items() if k not in properties_annotations} + cls_schema = cls.Schema_() + properties = cls_schema.properties if hasattr(cls_schema, 'properties') else {} + present_additional_properties = {k: v for k, v, in arg.items() if k not in properties} for property_name, value in present_additional_properties.items(): path_to_item = validation_metadata.path_to_item + (property_name,) arg_validation_metadata = ValidationMetadata( @@ -870,14 +901,14 @@ def validate_additional_properties( def validate_one_of( arg: typing.Any, - one_of_container_cls: typing.Type, + classes: typing.Tuple[typing.Type[Schema], ...], cls: 'Schema', validation_metadata: ValidationMetadata, ) -> PathToSchemasType: oneof_classes = [] path_to_schemas = collections.defaultdict(set) - for one_of_cls in one_of_container_cls.classes: - schema = _get_class(one_of_cls) + for schema in classes: + schema = _get_class(schema) if schema in path_to_schemas[validation_metadata.path_to_item]: oneof_classes.append(schema) continue @@ -914,14 +945,14 @@ def validate_one_of( def validate_any_of( arg: typing.Any, - any_of_container_cls: typing.Type, + classes: typing.Tuple[typing.Type[Schema], ...], cls: 'Schema', validation_metadata: ValidationMetadata, ) -> PathToSchemasType: anyof_classes = [] path_to_schemas = collections.defaultdict(set) - for any_of_cls in any_of_container_cls.classes: - schema = _get_class(any_of_cls) + for schema in classes: + schema = _get_class(schema) if schema is cls: """ optimistically assume that cls schema will pass validation @@ -951,13 +982,13 @@ def validate_any_of( def validate_all_of( arg: typing.Any, - all_of_cls: typing.Type, + classes: typing.Tuple[typing.Type[Schema], ...], cls: typing.Type, validation_metadata: ValidationMetadata, ) -> PathToSchemasType: path_to_schemas = collections.defaultdict(set) - for allof_cls in all_of_cls.classes: - schema = _get_class(allof_cls) + for schema in classes: + schema = _get_class(schema) if schema is cls: """ optimistically assume that cls schema will pass validation @@ -974,7 +1005,7 @@ def validate_all_of( def validate_not( arg: typing.Any, - not_cls: typing.Type, + not_cls: typing.Type[Schema], cls: typing.Type, validation_metadata: ValidationMetadata, ) -> None: @@ -1016,38 +1047,36 @@ def __get_discriminated_class(cls, disc_property_name: str, disc_payload_value: """ Used in schemas with discriminators """ - if not hasattr(cls.Schema_, 'discriminator'): + cls_schema = cls.Schema_() + if not hasattr(cls_schema, 'discriminator'): return None - disc = cls.Schema_.discriminator() + disc = cls_schema.discriminator if disc_property_name not in disc: return None discriminated_cls = disc[disc_property_name].get(disc_payload_value) if discriminated_cls is not None: return discriminated_cls if not ( - hasattr(cls.Schema_, 'AllOf') or - hasattr(cls.Schema_, 'OneOf') or - hasattr(cls.Schema_, 'AnyOf') + hasattr(cls_schema, 'all_of') or + hasattr(cls_schema, 'one_of') or + hasattr(cls_schema, 'any_of') ): return None # TODO stop traveling if a cycle is hit - if hasattr(cls.Schema_, 'AllOf'): - for allof_cls in cls.Schema_.AllOf.classes: - allof_cls = _get_class(allof_cls) + if hasattr(cls_schema, 'all_of'): + for allof_cls in cls_schema.all_of: discriminated_cls = __get_discriminated_class( allof_cls, disc_property_name=disc_property_name, disc_payload_value=disc_payload_value) if discriminated_cls is not None: return discriminated_cls - if hasattr(cls.Schema_, 'OneOf'): - for oneof_cls in cls.Schema_.OneOf.classes: - oneof_cls = _get_class(oneof_cls) + if hasattr(cls_schema, 'one_of'): + for oneof_cls in cls_schema.one_of: discriminated_cls = __get_discriminated_class( oneof_cls, disc_property_name=disc_property_name, disc_payload_value=disc_payload_value) if discriminated_cls is not None: return discriminated_cls - if hasattr(cls.Schema_, 'AnyOf'): - for anyof_cls in cls.Schema_.AnyOf.classes: - anyof_cls = _get_class(anyof_cls) + if hasattr(cls_schema, 'any_of'): + for anyof_cls in cls_schema.any_of: discriminated_cls = __get_discriminated_class( anyof_cls, disc_property_name=disc_property_name, disc_payload_value=disc_payload_value) if discriminated_cls is not None: @@ -1057,13 +1086,12 @@ def __get_discriminated_class(cls, disc_property_name: str, disc_payload_value: def validate_discriminator( arg: typing.Any, - discriminator_fn: typing.Type, + discriminator: typing.Mapping[str, typing.Mapping[str, typing.Type[Schema]]], cls: typing.Type, validation_metadata: ValidationMetadata, ) -> typing.Optional[PathToSchemasType]: if not isinstance(arg, frozendict.frozendict): return None - discriminator = discriminator_fn.__func__() disc_prop_name = list(discriminator.keys())[0] __ensure_discriminator_value_present(disc_prop_name, validation_metadata, arg) discriminated_cls = __get_discriminated_class( @@ -1112,24 +1140,19 @@ def validate_discriminator( 'inclusive_maximum': validate_inclusive_maximum, 'exclusive_maximum': validate_exclusive_maximum, 'multiple_of': validate_multiple_of, - 'regex': validate_regex, + 'pattern': validate_pattern, 'format': validate_format, 'required': validate_required, 'items': validate_items, - 'Items': validate_items, - 'Properties': validate_properties, - 'AdditionalProperties': validate_additional_properties, + 'properties': validate_properties, 'additional_properties': validate_additional_properties, - 'OneOf': validate_one_of, - 'AnyOf': validate_any_of, - 'AllOf': validate_all_of, - '_not': validate_not, - '_Not': validate_not, - 'ModelNot': validate_not, + 'one_of': validate_one_of, + 'any_of': validate_any_of, + 'all_of': validate_all_of, + 'not_': validate_not, 'discriminator': validate_discriminator } -T = typing.TypeVar('T') U = typing.TypeVar('U') class Schema(typing.Generic[T]): @@ -1158,9 +1181,10 @@ def _validate( All keyword validation except for type checking was done in calling stack frames If those validations passed, the validated classes are collected in path_to_schemas """ + cls_schema = cls.Schema_() json_schema_data = { k: v - for k, v in vars(cls.Schema_).items() + for k, v in vars(cls_schema).items() if k not in cls.__excluded_cls_properties and k not in validation_metadata.configuration.disabled_json_schema_python_keywords @@ -1276,7 +1300,7 @@ def __get_new_cls( """ cls._process_schema_classes(schema_classes) enum_schema = any( - issubclass(this_cls, Schema) and hasattr(this_cls.Schema_, "enum_value_to_name") + issubclass(this_cls, Schema) and hasattr(this_cls.Schema_(), "enum_value_to_name") for this_cls in schema_classes ) inheritable_primitive_type = schema_classes.intersection(cls.__inheritable_primitive_types_set) @@ -1396,9 +1420,11 @@ def __new__( bytes, io.FileIO, io.BufferedReader, - 'Schema', ], + 'Schema', + ], configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None, **kwargs: typing.Union[ + Unset, dict, frozendict.frozendict, list, @@ -1415,7 +1441,7 @@ def __new__( bytes, io.FileIO, io.BufferedReader, - 'Schema', Unset + 'Schema', ] ): """ @@ -1971,7 +1997,8 @@ def cast_to_allowed_types( bytes, io.FileIO, io.BufferedReader, - 'Schema', ], + '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.frozendict, tuple]]], path_to_item: typing.Tuple[typing.Union[str, int], ...], @@ -2100,8 +2127,9 @@ class ListSchema( Schema[T], TupleMixin ): - class Schema_: - types = {tuple} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) @classmethod def from_openapi_data_(cls, arg: typing.Sequence[typing.Any], configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2116,8 +2144,9 @@ class NoneSchema( Schema[T], NoneMixin ): - class Schema_: - types = {NoneClass} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({NoneClass}) @classmethod def from_openapi_data_(cls, arg: None, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2136,8 +2165,9 @@ class NumberSchema( This is used for type: number with no format Both integers AND floats are accepted """ - class Schema_: - types = {decimal.Decimal} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) @classmethod def from_openapi_data_(cls, arg: typing.Union[int, float], configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2160,9 +2190,10 @@ def as_int_(self) -> int: class IntSchema(IntBase, NumberSchema[T]): - class Schema_: - types = {decimal.Decimal} - format = 'int' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) + format: str = 'int' @classmethod def from_openapi_data_(cls, arg: int, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2176,9 +2207,10 @@ def __new__(cls, arg_: typing.Union[decimal.Decimal, int], **kwargs: schema_conf class Int32Schema( IntSchema[T] ): - class Schema_: - types = {decimal.Decimal} - format = 'int32' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) + format: str = 'int32' def __new__(cls, arg_: typing.Union[decimal.Decimal, int], **kwargs: schema_configuration.SchemaConfiguration) -> Int32Schema[decimal.Decimal]: inst = super().__new__(cls, arg_, **kwargs) @@ -2188,9 +2220,10 @@ def __new__(cls, arg_: typing.Union[decimal.Decimal, int], **kwargs: schema_conf class Int64Schema( IntSchema[T] ): - class Schema_: - types = {decimal.Decimal} - format = 'int64' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) + format: str = 'int64' def __new__(cls, arg_: typing.Union[decimal.Decimal, int], **kwargs: schema_configuration.SchemaConfiguration) -> Int64Schema[decimal.Decimal]: inst = super().__new__(cls, arg_, **kwargs) @@ -2200,9 +2233,10 @@ def __new__(cls, arg_: typing.Union[decimal.Decimal, int], **kwargs: schema_conf class Float32Schema( NumberSchema[T] ): - class Schema_: - types = {decimal.Decimal} - format = 'float' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) + format: str = 'float' @classmethod def from_openapi_data_(cls, arg: float, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2216,9 +2250,10 @@ def __new__(cls, arg_: typing.Union[decimal.Decimal, int, float], **kwargs: sche class Float64Schema( NumberSchema[T] ): - class Schema_: - types = {decimal.Decimal} - format = 'double' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) + format: str = 'double' @classmethod def from_openapi_data_(cls, arg: float, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2240,8 +2275,9 @@ class StrSchema( - type: string (format unset) - type: string, format: date """ - class Schema_: - types = {str} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({str}) @classmethod def from_openapi_data_(cls, arg: str, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None) -> StrSchema[str]: @@ -2252,9 +2288,10 @@ def __new__(cls, arg_: typing.Union[str, datetime.date, datetime.datetime, uuid. class UUIDSchema(UUIDBase, StrSchema[T]): - class Schema_: - types = {str} - format = 'uuid' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({str}) + format: str = 'uuid' def __new__(cls, arg_: typing.Union[str, uuid.UUID], **kwargs: schema_configuration.SchemaConfiguration) -> UUIDSchema[str]: inst = super().__new__(cls, arg_, **kwargs) @@ -2262,9 +2299,10 @@ def __new__(cls, arg_: typing.Union[str, uuid.UUID], **kwargs: schema_configurat class DateSchema(DateBase, StrSchema[T]): - class Schema_: - types = {str} - format = 'date' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({str}) + format: str = 'date' def __new__(cls, arg_: typing.Union[str, datetime.date], **kwargs: schema_configuration.SchemaConfiguration) -> DateSchema[str]: inst = super().__new__(cls, arg_, **kwargs) @@ -2272,9 +2310,10 @@ def __new__(cls, arg_: typing.Union[str, datetime.date], **kwargs: schema_config class DateTimeSchema(DateTimeBase, StrSchema[T]): - class Schema_: - types = {str} - format = 'date-time' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({str}) + format: str = 'date-time' def __new__(cls, arg_: typing.Union[str, datetime.datetime], **kwargs: schema_configuration.SchemaConfiguration) -> DateTimeSchema[str]: inst = super().__new__(cls, arg_, **kwargs) @@ -2282,9 +2321,10 @@ def __new__(cls, arg_: typing.Union[str, datetime.datetime], **kwargs: schema_co class DecimalSchema(DecimalBase, StrSchema[T]): - class Schema_: - types = {str} - format = 'number' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({str}) + format: str = 'number' def __new__(cls, arg_: str, **kwargs: schema_configuration.SchemaConfiguration) -> DecimalSchema[str]: """ @@ -2306,8 +2346,9 @@ class BytesSchema( """ this class will subclass bytes and is immutable """ - class Schema_: - types = {bytes} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({bytes}) def __new__(cls, arg_: bytes, **kwargs: schema_configuration.SchemaConfiguration) -> BytesSchema[bytes]: super_cls: typing.Type = super(Schema, cls) @@ -2334,8 +2375,9 @@ class FileSchema( - to allow file reading and writing to disk - to be able to preserve file name info """ - class Schema_: - types = {FileIO} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({FileIO}) def __new__(cls, arg_: typing.Union[io.FileIO, io.BufferedReader], **kwargs: schema_configuration.SchemaConfiguration) -> FileSchema[FileIO]: super_cls: typing.Type = super(Schema, cls) @@ -2346,15 +2388,15 @@ class BinarySchema( Schema[T], BinaryMixin ): - class Schema_: - types = {FileIO, bytes} - format = 'binary' - - class OneOf: - classes = [ - BytesSchema, - FileSchema, - ] + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({FileIO, bytes}) + format: str = 'binary' + + one_of: typing.Tuple[typing.Type[Schema], ...] = ( + BytesSchema, + FileSchema, + ) def __new__(cls, arg_: typing.Union[io.FileIO, io.BufferedReader, bytes], **kwargs: schema_configuration.SchemaConfiguration) -> BinarySchema[typing.Union[FileIO, bytes]]: return super().__new__(cls, arg_) @@ -2365,8 +2407,9 @@ class BoolSchema( Schema[T], BoolMixin ): - class Schema_: - types = {BoolClass} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({BoolClass}) @classmethod def from_openapi_data_(cls, arg: bool, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2387,7 +2430,8 @@ class AnyTypeSchema( NoneFrozenDictTupleStrDecimalBoolFileBytesMixin ): # Python representation of a schema defined as true or {} - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): pass def __new__( @@ -2427,7 +2471,8 @@ def __new__( Schema, bytes, io.FileIO, - io.BufferedReader + io.BufferedReader, + Unset ] ) -> AnyTypeSchema[typing.Union[ NoneClass, @@ -2497,9 +2542,9 @@ class NotAnyTypeSchema(AnyTypeSchema[T]): Does not allow inputs in of AnyType Note: validations on this class are never run because the code knows that no inputs will ever validate """ - - class Schema_: - _not = AnyTypeSchema[U] + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + not_: typing.Type[Schema] = AnyTypeSchema def __new__( cls, @@ -2515,8 +2560,9 @@ class DictSchema( Schema[T], FrozenDictMixin ): - class Schema_: - types = {frozendict.frozendict} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) @classmethod def from_openapi_data_(cls, arg: typing.Dict[str, typing.Any], configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2552,3 +2598,57 @@ def get_new_class( def log_cache_usage(cache_fn): if LOG_CACHE_USAGE: print(cache_fn.__name__, cache_fn.cache_info()) + + +W = typing.TypeVar('W', bound=typing_extensions.TypedDict) + +def typed_dict_to_instance(t_dict: typing.Type[W]) -> W: + res = {} + for key, val in t_dict.__annotations__.items(): + if isinstance(val, typing._GenericAlias): # type: ignore + # typing.Type[W] -> W + val_cls = typing_extensions.get_args(val)[0] + res[key] = val_cls + return res # type: ignore + +X = typing.TypeVar('X', bound=typing.Tuple) + +def tuple_to_instance(tup: typing.Type[X]) -> X: + res = [] + for arg in typing_extensions.get_args(tup): + if isinstance(arg, typing._GenericAlias): # type: ignore + # typing.Type[Schema] -> Schema + arg_cls = typing_extensions.get_args(arg)[0] + res.append(arg_cls) + return tuple(res) # type: ignore + +INPUT_TYPES_ALL_INCL_SCHEMA = typing.Union[ + dict, + frozendict.frozendict, + list, + tuple, + decimal.Decimal, + float, + int, + str, + datetime.date, + datetime.datetime, + uuid.UUID, + bool, + None, + bytes, + io.FileIO, + io.BufferedReader, + Schema +] + +INPUT_BASE_TYPES = typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + BoolClass, + NoneClass, + tuple, + bytes, + FileIO +] \ No newline at end of file diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/server.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/server.py index a79625349de..af2f5b502bf 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/server.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/server.py @@ -6,30 +6,29 @@ Generated by: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator """ +from __future__ import annotations import abc import dataclasses import typing @dataclasses.dataclass -class Server(abc.ABC): +class ServerWithoutVariables(abc.ABC): + url: str + + +@dataclasses.dataclass +class ServerWithVariables(abc.ABC): _url: str - variables: typing.Optional[typing.Dict[str, str]] = None - variable_schemas: typing.Optional[typing.Dict[str, typing.Type['schemas.Schema']]] = None + variables: schemas.DictSchema + variables_cls: typing.Type[schemas.DictSchema] url: str = dataclasses.field(init=False) def __post_init__(self): - if not self.variable_schemas: - self.url = self._url - return url = self._url - for (key, schema) in self.variable_schemas.items(): - if self.variables and key in self.variables: - value = self.variables[key] - cast_value = schema(value) - else: - cast_value = schema.Schema_.default - cast_value = typing.cast(str, cast_value) + assert isinstance (self.variables, self.variables_cls) + for (key, value) in self.variables.items(): + cast_value = typing.cast(str, value) url = url.replace("{" + key + "}", cast_value) self.url = url diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/servers/server_0.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/servers/server_0.py index df7bf987021..784da442e94 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/servers/server_0.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/servers/server_0.py @@ -7,5 +7,5 @@ @dataclasses.dataclass -class Server0(server.Server): - _url: str = "https://someserver.com/v1" +class Server0(server.ServerWithoutVariables): + url: str = "https://someserver.com/v1" diff --git a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/shared_imports/schema_imports.py b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/shared_imports/schema_imports.py index 9e22456a866..c30d31ae0ad 100644 --- a/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/shared_imports/schema_imports.py +++ b/samples/openapi3/client/3_0_3_unit_test/python/src/unit_test_api/shared_imports/schema_imports.py @@ -1,3 +1,4 @@ +import dataclasses import datetime import decimal import io diff --git a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/components/schema/addition_operator.py b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/components/schema/addition_operator.py index 29b44792834..93cc2e9090f 100644 --- a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/components/schema/addition_operator.py +++ b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/components/schema/addition_operator.py @@ -10,6 +10,31 @@ from __future__ import annotations from this_package.shared_imports.schema_imports import * +AdditionalProperties: typing_extensions.TypeAlias = schemas.NotAnyTypeSchema[U] +A: typing_extensions.TypeAlias = schemas.Float64Schema[U] +B: typing_extensions.TypeAlias = schemas.Float64Schema[U] + + +class OperatorId( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + default: str = "ADD" +Properties = typing_extensions.TypedDict( + 'Properties', + { + "a": typing.Type[A], + "b": typing.Type[B], + "operator_id": typing.Type[OperatorId], + } +) + class AdditionOperator( schemas.DictSchema[schemas.T] @@ -21,56 +46,37 @@ class AdditionOperator( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "a", "b", "operator_id", - } - - class Properties: - A: typing_extensions.TypeAlias = schemas.Float64Schema[U] - B: typing_extensions.TypeAlias = schemas.Float64Schema[U] - - - class OperatorId( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - default = "ADD" - __annotations__ = { - "a": A, - "b": B, - "operator_id": OperatorId, - } - AdditionalProperties: typing_extensions.TypeAlias = schemas.NotAnyTypeSchema[U] + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore @property - def a(self) -> Schema_.Properties.A[decimal.Decimal]: + def a(self) -> A[decimal.Decimal]: return self.__getitem__("a") @property - def b(self) -> Schema_.Properties.B[decimal.Decimal]: + def b(self) -> B[decimal.Decimal]: return self.__getitem__("b") @property - def operator_id(self) -> Schema_.Properties.OperatorId[str]: + def operator_id(self) -> OperatorId[str]: return self.__getitem__("operator_id") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["a"]) -> Schema_.Properties.A[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["a"]) -> A[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["b"]) -> Schema_.Properties.B[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["b"]) -> B[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["operator_id"]) -> Schema_.Properties.OperatorId[str]: ... + def __getitem__(self, name: typing_extensions.Literal["operator_id"]) -> OperatorId[str]: ... def __getitem__( self, @@ -87,19 +93,19 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], a: typing.Union[ - Schema_.Properties.A[decimal.Decimal], + A[decimal.Decimal], decimal.Decimal, int, float ], b: typing.Union[ - Schema_.Properties.B[decimal.Decimal], + B[decimal.Decimal], decimal.Decimal, int, float ], operator_id: typing.Union[ - Schema_.Properties.OperatorId[str], + OperatorId[str], str ], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, @@ -117,3 +123,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/components/schema/operator.py b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/components/schema/operator.py index 17a7b302fd6..3a97af0bf1f 100644 --- a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/components/schema/operator.py +++ b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/components/schema/operator.py @@ -11,6 +11,7 @@ from this_package.shared_imports.schema_imports import * + class Operator( schemas.AnyTypeSchema[schemas.T], ): @@ -21,12 +22,11 @@ class Operator( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - @staticmethod - def discriminator(): - return { + discriminator: typing.Mapping[str, typing.Mapping[str, typing.Type[schemas.Schema]]] = dataclasses.field( + default_factory=lambda: { 'operator_id': { 'ADD': addition_operator.AdditionOperator, 'AdditionOperator': addition_operator.AdditionOperator, @@ -34,62 +34,15 @@ def discriminator(): 'SubtractionOperator': subtraction_operator.SubtractionOperator, } } - - class OneOf: - - @staticmethod - def _0() -> typing.Type[addition_operator.AdditionOperator]: - return addition_operator.AdditionOperator - - @staticmethod - def _1() -> typing.Type[subtraction_operator.SubtractionOperator]: - return subtraction_operator.SubtractionOperator - classes = [ - _0, - _1, - ] + ) + one_of: OneOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(OneOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Operator[ typing.Union[ frozendict.frozendict, @@ -125,5 +78,10 @@ def __new__( ) return inst + from this_package.components.schema import addition_operator from this_package.components.schema import subtraction_operator +OneOf = typing.Tuple[ + typing.Type[addition_operator.AdditionOperator], + typing.Type[subtraction_operator.SubtractionOperator], +] diff --git a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/components/schema/subtraction_operator.py b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/components/schema/subtraction_operator.py index 213e5860569..3ffa4bf9909 100644 --- a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/components/schema/subtraction_operator.py +++ b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/components/schema/subtraction_operator.py @@ -10,6 +10,31 @@ from __future__ import annotations from this_package.shared_imports.schema_imports import * +AdditionalProperties: typing_extensions.TypeAlias = schemas.NotAnyTypeSchema[U] +A: typing_extensions.TypeAlias = schemas.Float64Schema[U] +B: typing_extensions.TypeAlias = schemas.Float64Schema[U] + + +class OperatorId( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + default: str = "SUB" +Properties = typing_extensions.TypedDict( + 'Properties', + { + "a": typing.Type[A], + "b": typing.Type[B], + "operator_id": typing.Type[OperatorId], + } +) + class SubtractionOperator( schemas.DictSchema[schemas.T] @@ -21,56 +46,37 @@ class SubtractionOperator( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "a", "b", "operator_id", - } - - class Properties: - A: typing_extensions.TypeAlias = schemas.Float64Schema[U] - B: typing_extensions.TypeAlias = schemas.Float64Schema[U] - - - class OperatorId( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - default = "SUB" - __annotations__ = { - "a": A, - "b": B, - "operator_id": OperatorId, - } - AdditionalProperties: typing_extensions.TypeAlias = schemas.NotAnyTypeSchema[U] + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore @property - def a(self) -> Schema_.Properties.A[decimal.Decimal]: + def a(self) -> A[decimal.Decimal]: return self.__getitem__("a") @property - def b(self) -> Schema_.Properties.B[decimal.Decimal]: + def b(self) -> B[decimal.Decimal]: return self.__getitem__("b") @property - def operator_id(self) -> Schema_.Properties.OperatorId[str]: + def operator_id(self) -> OperatorId[str]: return self.__getitem__("operator_id") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["a"]) -> Schema_.Properties.A[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["a"]) -> A[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["b"]) -> Schema_.Properties.B[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["b"]) -> B[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["operator_id"]) -> Schema_.Properties.OperatorId[str]: ... + def __getitem__(self, name: typing_extensions.Literal["operator_id"]) -> OperatorId[str]: ... def __getitem__( self, @@ -87,19 +93,19 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], a: typing.Union[ - Schema_.Properties.A[decimal.Decimal], + A[decimal.Decimal], decimal.Decimal, int, float ], b: typing.Union[ - Schema_.Properties.B[decimal.Decimal], + B[decimal.Decimal], decimal.Decimal, int, float ], operator_id: typing.Union[ - Schema_.Properties.OperatorId[str], + OperatorId[str], str ], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, @@ -117,3 +123,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/configurations/schema_configuration.py b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/configurations/schema_configuration.py index 14c059be5e7..8eb07924ba4 100644 --- a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/configurations/schema_configuration.py +++ b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/configurations/schema_configuration.py @@ -13,34 +13,32 @@ PYTHON_KEYWORD_TO_JSON_SCHEMA_KEYWORD = { - 'types': 'type', + 'additional_properties': 'additionalProperties', + 'all_of': 'allOf', + 'any_of': 'anyOf', + 'discriminator': 'discriminator', + # default omitted because it has no validation impact 'enum_value_to_name': 'enum', - 'unique_items': 'uniqueItems', - 'min_items': 'minItems', + 'exclusive_maximum': 'exclusiveMaximum', + 'exclusive_minimum': 'exclusiveMinimum', + 'format': 'format', + 'inclusive_maximum': 'maximum', + 'inclusive_minimum': 'minimum', + 'items': 'items', 'max_items': 'maxItems', - 'min_properties': 'minProperties', + 'max_length': 'maxLength', 'max_properties': 'maxProperties', + 'min_items': 'minItems', 'min_length': 'minLength', - 'max_length': 'maxLength', - 'inclusive_minimum': 'minimum', - 'exclusive_minimum': 'exclusiveMinimum', - 'inclusive_maximum': 'maximum', - 'exclusive_maximum': 'exclusiveMaximum', + 'min_properties': 'minProperties', 'multiple_of': 'multipleOf', - 'regex': 'pattern', - 'format': 'format', + 'not_': 'not', + 'one_of': 'oneOf', + 'pattern': 'pattern', + 'properties': 'properties', 'required': 'required', - 'items': 'items', - 'Items': 'items', - 'Properties': 'properties', - 'additional_properties': 'additionalProperties', - 'additionalProperties': 'additionalProperties', - 'OneOf': 'oneOf', - 'AnyOf': 'anyOf', - 'AllOf': 'allOf', - '_not': 'not', - '_Not': 'not', - 'discriminator': 'discriminator' + 'types': 'type', + 'unique_items': 'uniqueItems' } class SchemaConfiguration: diff --git a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/schemas.py b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/schemas.py index 83723f9f597..2ff8b5046c0 100644 --- a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/schemas.py +++ b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/schemas.py @@ -13,6 +13,7 @@ import dataclasses import functools import decimal +import inspect import io import re import types @@ -111,6 +112,20 @@ def add_deeper_validated_schemas(validation_metadata: ValidationMetadata, path_t update(path_to_schemas, other_path_to_schemas) +class SingletonMeta(type): + """ + A singleton class for schemas + Schemas are frozen classes that are never instantiated with init args + All args come from defaults + """ + _instances = {} + + def __call__(cls, *args, **kwargs): + if cls not in cls._instances: + cls._instances[cls] = super().__call__(*args, **kwargs) + return cls._instances[cls] + + class Singleton: """ Enums and singletons are the same @@ -147,14 +162,18 @@ def __repr__(self): return f'<{self.__class__.__name__}: False>' return f'<{self.__class__.__name__}: {super().__repr__()}>' +T = typing.TypeVar('T') -class classproperty: - def __init__(self, fget): - self.fget = fget +class classproperty(typing.Generic[T]): + def __init__(self, method: typing.Callable[..., T]): + self.__method = method + functools.update_wrapper(self, method) # type: ignore - def __get__(self, owner_self, owner_cls): - return self.fget(owner_cls) + def __get__(self, obj, cls=None) -> T: + if cls is None: + cls = type(obj) + return self.__method(cls) class NoneClass(Singleton): @@ -183,32 +202,40 @@ def __bool__(self) -> bool: raise ValueError('Unable to find the boolean value of this instance') +@dataclasses.dataclass(frozen=True) +class PatternInfo: + pattern: str + flags: typing.Optional[re.RegexFlag] = None + + class SchemaTyped: - types: typing.Optional[typing.Set[typing.Type]] + additional_properties: typing.Type[Schema] + all_of: typing.Tuple[typing.Type[Schema], ...] + any_of: typing.Tuple[typing.Type[Schema], ...] + discriminator: typing.Mapping[str, typing.Mapping[str, typing.Type[Schema]]] + default: typing.Union[str, int, float, BoolClass, NoneClass] + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, BoolClass, NoneClass], str] exclusive_maximum: typing.Union[int, float] - inclusive_maximum: typing.Union[int, float] exclusive_minimum: typing.Union[int, float] + format: str + inclusive_maximum: typing.Union[int, float] inclusive_minimum: typing.Union[int, float] + items: typing.Type[Schema] max_items: int - min_items: int - discriminator: typing.Dict[str, typing.Dict[str, typing.Type['Schema']]] - default: typing.Union[str, int, BoolClass] - - - class Properties: - # to hold object properties - pass - - additionalProperties: typing.Optional[typing.Type['Schema']] - max_properties: int - min_properties: int - AllOf: typing.List[typing.Type['Schema']] - OneOf: typing.List[typing.Type['Schema']] - AnyOf: typing.List[typing.Type['Schema']] - _not: typing.Type['Schema'] max_length: int + max_properties: int + min_items: int min_length: int - items: typing.Type['Schema'] + min_properties: int + multiple_of: typing.Union[int, float] + not_: typing.Type[Schema] + one_of: typing.Tuple[typing.Type[Schema], ...] + pattern: PatternInfo + properties: typing.Mapping[str, typing.Type[Schema]] + required: typing.FrozenSet[str] + types: typing.FrozenSet[typing.Type] + unique_items: bool + PathToSchemasType = typing.Dict[ typing.Tuple[typing.Union[str, int], ...], @@ -544,31 +571,31 @@ def validate_multiple_of( return None -def validate_regex( +def validate_pattern( arg: typing.Any, - regex_dict: typing.Dict, + pattern_info: PatternInfo, cls: typing.Type, validation_metadata: ValidationMetadata, **kwargs ) -> None: if not isinstance(arg, str): return None - flags = regex_dict.get('flags', 0) - if not re.search(regex_dict['pattern'], arg, flags=flags): + flags = pattern_info.flags if pattern_info.flags is not None else 0 + if not re.search(pattern_info.pattern, arg, flags=flags): if flags != 0: # Don't print the regex flags if the flags are not # specified in the OAS document. _raise_validation_error_message( value=arg, constraint_msg="must match regular expression", - constraint_value=regex_dict['pattern'], + constraint_value=pattern_info.pattern, path_to_item=validation_metadata.path_to_item, additional_txt=" with flags=`{}`".format(flags) ) _raise_validation_error_message( value=arg, constraint_msg="must match regular expression", - constraint_value=regex_dict['pattern'], + constraint_value=pattern_info.pattern, path_to_item=validation_metadata.path_to_item ) return None @@ -664,8 +691,8 @@ def __parse_isodate(self, dt_str: str) -> typing.Tuple[typing.Tuple[int, int, in def __parse_isotime(self, dt_str: str) -> typing.Tuple[int, int, int, int, typing.Optional[typing.Union[tz.tzutc, tz.tzoffset]]]: dt_str_ascii = self.__get_ascii_bytes(dt_str) values = self._parse_isotime(dt_str_ascii) # type: ignore - components: typing.Tuple[int, int, int, int, typing.Optional[typing.Union[tz.tzutc, tz.tzoffset]]] = tuple(values) - return tuple(components) + components: typing.Tuple[int, int, int, int, typing.Optional[typing.Union[tz.tzutc, tz.tzoffset]]] = tuple(values) # type: ignore + return components def parse_isodatetime(self, dt_str: str) -> datetime.datetime: components, pos = self.__parse_isodate(dt_str) @@ -803,18 +830,21 @@ def _get_class(item_cls: typing.Union[types.FunctionType, staticmethod, typing.T elif isinstance(item_cls, staticmethod): # referenced schema return item_cls.__func__() - return item_cls + elif isinstance(item_cls, type): + return item_cls + raise ValueError('invalid class value passed in') def validate_items( arg: typing.Any, - item_cls: typing.Type, + item_cls: typing.Type[Schema], cls: typing.Type, validation_metadata: ValidationMetadata, **kwargs ) -> typing.Optional[PathToSchemasType]: if not isinstance(arg, tuple): return None + schema = _get_class(additional_properties_cls) item_cls = _get_class(item_cls) path_to_schemas = {} for i, value in enumerate(arg): @@ -834,7 +864,7 @@ def validate_items( def validate_properties( arg: typing.Any, - properties: typing.Type, + properties: typing.Mapping[str, typing.Type[Schema]], cls: typing.Type, validation_metadata: ValidationMetadata, **kwargs @@ -842,10 +872,10 @@ def validate_properties( if not isinstance(arg, frozendict.frozendict): return None path_to_schemas = {} - present_properties = {k: v for k, v, in arg.items() if k in properties.__annotations__} + present_properties = {k: v for k, v, in arg.items() if k in properties} for property_name, value in present_properties.items(): path_to_item = validation_metadata.path_to_item + (property_name,) - schema = properties.__annotations__[property_name] + schema = properties[property_name] schema = _get_class(schema) arg_validation_metadata = ValidationMetadata( path_to_item=path_to_item, @@ -862,17 +892,18 @@ def validate_properties( def validate_additional_properties( arg: typing.Any, - additional_properties_schema: typing.Type, + additional_properties_cls: typing.Type[Schema], cls: typing.Type, validation_metadata: ValidationMetadata, **kwargs ) -> typing.Optional[PathToSchemasType]: if not isinstance(arg, frozendict.frozendict): return None - schema = _get_class(additional_properties_schema) + schema = _get_class(additional_properties_cls) path_to_schemas = {} - properties_annotations = cls.Schema_.Properties.__annotations__ if hasattr(cls.Schema_, 'Properties') else {} - present_additional_properties = {k: v for k, v, in arg.items() if k not in properties_annotations} + cls_schema = cls.Schema_() + properties = cls_schema.properties if hasattr(cls_schema, 'properties') else {} + present_additional_properties = {k: v for k, v, in arg.items() if k not in properties} for property_name, value in present_additional_properties.items(): path_to_item = validation_metadata.path_to_item + (property_name,) arg_validation_metadata = ValidationMetadata( @@ -890,7 +921,7 @@ def validate_additional_properties( def validate_one_of( arg: typing.Any, - one_of_container_cls: typing.Type, + classes: typing.Tuple[typing.Type[Schema], ...], cls: 'Schema', validation_metadata: ValidationMetadata, discriminated_cls: typing.Optional['Schema'], @@ -898,8 +929,8 @@ def validate_one_of( ) -> PathToSchemasType: oneof_classes = [] path_to_schemas = collections.defaultdict(set) - for one_of_cls in one_of_container_cls.classes: - schema = _get_class(one_of_cls) + for schema in classes: + schema = _get_class(schema) if schema in path_to_schemas[validation_metadata.path_to_item]: oneof_classes.append(schema) continue @@ -948,7 +979,7 @@ def validate_one_of( def validate_any_of( arg: typing.Any, - any_of_container_cls: typing.Type, + classes: typing.Tuple[typing.Type[Schema], ...], cls: 'Schema', validation_metadata: ValidationMetadata, discriminated_cls: typing.Optional['Schema'], @@ -956,8 +987,8 @@ def validate_any_of( ) -> PathToSchemasType: anyof_classes = [] path_to_schemas = collections.defaultdict(set) - for any_of_cls in any_of_container_cls.classes: - schema = _get_class(any_of_cls) + for schema in classes: + schema = _get_class(schema) if schema is cls: """ optimistically assume that cls schema will pass validation @@ -993,14 +1024,14 @@ def validate_any_of( def validate_all_of( arg: typing.Any, - all_of_cls: typing.Type, + classes: typing.Tuple[typing.Type[Schema], ...], cls: typing.Type, validation_metadata: ValidationMetadata, **kwargs ) -> PathToSchemasType: path_to_schemas = collections.defaultdict(set) - for allof_cls in all_of_cls.classes: - schema = _get_class(allof_cls) + for schema in classes: + schema = _get_class(schema) if schema is cls: """ optimistically assume that cls schema will pass validation @@ -1017,7 +1048,7 @@ def validate_all_of( def validate_not( arg: typing.Any, - not_cls: typing.Type, + not_cls: typing.Type[Schema], cls: typing.Type, validation_metadata: ValidationMetadata, **kwargs @@ -1060,38 +1091,36 @@ def __get_discriminated_class(cls, disc_property_name: str, disc_payload_value: """ Used in schemas with discriminators """ - if not hasattr(cls.Schema_, 'discriminator'): + cls_schema = cls.Schema_() + if not hasattr(cls_schema, 'discriminator'): return None - disc = cls.Schema_.discriminator() + disc = cls_schema.discriminator if disc_property_name not in disc: return None discriminated_cls = disc[disc_property_name].get(disc_payload_value) if discriminated_cls is not None: return discriminated_cls if not ( - hasattr(cls.Schema_, 'AllOf') or - hasattr(cls.Schema_, 'OneOf') or - hasattr(cls.Schema_, 'AnyOf') + hasattr(cls_schema, 'all_of') or + hasattr(cls_schema, 'one_of') or + hasattr(cls_schema, 'any_of') ): return None # TODO stop traveling if a cycle is hit - if hasattr(cls.Schema_, 'AllOf'): - for allof_cls in cls.Schema_.AllOf.classes: - allof_cls = _get_class(allof_cls) + if hasattr(cls_schema, 'all_of'): + for allof_cls in cls_schema.all_of: discriminated_cls = __get_discriminated_class( allof_cls, disc_property_name=disc_property_name, disc_payload_value=disc_payload_value) if discriminated_cls is not None: return discriminated_cls - if hasattr(cls.Schema_, 'OneOf'): - for oneof_cls in cls.Schema_.OneOf.classes: - oneof_cls = _get_class(oneof_cls) + if hasattr(cls_schema, 'one_of'): + for oneof_cls in cls_schema.one_of: discriminated_cls = __get_discriminated_class( oneof_cls, disc_property_name=disc_property_name, disc_payload_value=disc_payload_value) if discriminated_cls is not None: return discriminated_cls - if hasattr(cls.Schema_, 'AnyOf'): - for anyof_cls in cls.Schema_.AnyOf.classes: - anyof_cls = _get_class(anyof_cls) + if hasattr(cls_schema, 'any_of'): + for anyof_cls in cls_schema.any_of: discriminated_cls = __get_discriminated_class( anyof_cls, disc_property_name=disc_property_name, disc_payload_value=disc_payload_value) if discriminated_cls is not None: @@ -1105,7 +1134,7 @@ def _get_discriminated_class_and_exception( ) -> typing.Tuple[typing.Optional['Schema'], typing.Optional[Exception]]: if not isinstance(arg, frozendict.frozendict): return None, None - discriminator = cls.Schema_.discriminator() + discriminator = cls_schema().discriminator() disc_prop_name = list(discriminator.keys())[0] try: __ensure_discriminator_value_present(disc_prop_name, validation_metadata, arg) @@ -1121,7 +1150,7 @@ def _get_discriminated_class_and_exception( def validate_discriminator( arg: typing.Any, - discriminator_fn: typing.Type, + discriminator: typing.Mapping[str, typing.Mapping[str, typing.Type[Schema]]], cls: typing.Type, validation_metadata: ValidationMetadata, discriminated_cls: typing.Optional['Schema'], @@ -1129,7 +1158,6 @@ def validate_discriminator( ) -> typing.Optional[PathToSchemasType]: if not isinstance(arg, frozendict.frozendict): return None - discriminator = discriminator_fn.__func__() disc_prop_name = list(discriminator.keys())[0] if ensure_discriminator_value_present_exc: raise ensure_discriminator_value_present_exc @@ -1176,24 +1204,19 @@ def validate_discriminator( 'inclusive_maximum': validate_inclusive_maximum, 'exclusive_maximum': validate_exclusive_maximum, 'multiple_of': validate_multiple_of, - 'regex': validate_regex, + 'pattern': validate_pattern, 'format': validate_format, 'required': validate_required, 'items': validate_items, - 'Items': validate_items, - 'Properties': validate_properties, - 'AdditionalProperties': validate_additional_properties, + 'properties': validate_properties, 'additional_properties': validate_additional_properties, - 'OneOf': validate_one_of, - 'AnyOf': validate_any_of, - 'AllOf': validate_all_of, - '_not': validate_not, - '_Not': validate_not, - 'ModelNot': validate_not, + 'one_of': validate_one_of, + 'any_of': validate_any_of, + 'all_of': validate_all_of, + 'not_': validate_not, 'discriminator': validate_discriminator } -T = typing.TypeVar('T') U = typing.TypeVar('U') class Schema(typing.Generic[T]): @@ -1222,13 +1245,15 @@ def _validate( All keyword validation except for type checking was done in calling stack frames If those validations passed, the validated classes are collected in path_to_schemas """ + cls_schema = cls.Schema_() json_schema_data = { k: v - for k, v in vars(cls.Schema_).items() + for k, v in vars(cls_schema).items() if k not in cls.__excluded_cls_properties and k not in validation_metadata.configuration.disabled_json_schema_python_keywords } + print(f'json_schema_data {json_schema_data}') kwargs = {} if 'discriminator' in json_schema_data: discriminated_cls, ensure_discriminator_value_present_exc = _get_discriminated_class_and_exception( @@ -1352,7 +1377,7 @@ def __get_new_cls( """ cls._process_schema_classes(schema_classes) enum_schema = any( - issubclass(this_cls, Schema) and hasattr(this_cls.Schema_, "enum_value_to_name") + issubclass(this_cls, Schema) and hasattr(this_cls.Schema_(), "enum_value_to_name") for this_cls in schema_classes ) inheritable_primitive_type = schema_classes.intersection(cls.__inheritable_primitive_types_set) @@ -1472,9 +1497,11 @@ def __new__( bytes, io.FileIO, io.BufferedReader, - 'Schema', ], + 'Schema', + ], configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None, **kwargs: typing.Union[ + Unset, dict, frozendict.frozendict, list, @@ -1491,7 +1518,7 @@ def __new__( bytes, io.FileIO, io.BufferedReader, - 'Schema', Unset + 'Schema', ] ): """ @@ -2047,7 +2074,8 @@ def cast_to_allowed_types( bytes, io.FileIO, io.BufferedReader, - 'Schema', ], + '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.frozendict, tuple]]], path_to_item: typing.Tuple[typing.Union[str, int], ...], @@ -2176,8 +2204,9 @@ class ListSchema( Schema[T], TupleMixin ): - class Schema_: - types = {tuple} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) @classmethod def from_openapi_data_(cls, arg: typing.Sequence[typing.Any], configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2192,8 +2221,9 @@ class NoneSchema( Schema[T], NoneMixin ): - class Schema_: - types = {NoneClass} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({NoneClass}) @classmethod def from_openapi_data_(cls, arg: None, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2212,8 +2242,9 @@ class NumberSchema( This is used for type: number with no format Both integers AND floats are accepted """ - class Schema_: - types = {decimal.Decimal} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) @classmethod def from_openapi_data_(cls, arg: typing.Union[int, float], configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2236,9 +2267,10 @@ def as_int_(self) -> int: class IntSchema(IntBase, NumberSchema[T]): - class Schema_: - types = {decimal.Decimal} - format = 'int' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) + format: str = 'int' @classmethod def from_openapi_data_(cls, arg: int, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2252,9 +2284,10 @@ def __new__(cls, arg_: typing.Union[decimal.Decimal, int], **kwargs: schema_conf class Int32Schema( IntSchema[T] ): - class Schema_: - types = {decimal.Decimal} - format = 'int32' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) + format: str = 'int32' def __new__(cls, arg_: typing.Union[decimal.Decimal, int], **kwargs: schema_configuration.SchemaConfiguration) -> Int32Schema[decimal.Decimal]: inst = super().__new__(cls, arg_, **kwargs) @@ -2264,9 +2297,10 @@ def __new__(cls, arg_: typing.Union[decimal.Decimal, int], **kwargs: schema_conf class Int64Schema( IntSchema[T] ): - class Schema_: - types = {decimal.Decimal} - format = 'int64' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) + format: str = 'int64' def __new__(cls, arg_: typing.Union[decimal.Decimal, int], **kwargs: schema_configuration.SchemaConfiguration) -> Int64Schema[decimal.Decimal]: inst = super().__new__(cls, arg_, **kwargs) @@ -2276,9 +2310,10 @@ def __new__(cls, arg_: typing.Union[decimal.Decimal, int], **kwargs: schema_conf class Float32Schema( NumberSchema[T] ): - class Schema_: - types = {decimal.Decimal} - format = 'float' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) + format: str = 'float' @classmethod def from_openapi_data_(cls, arg: float, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2292,9 +2327,10 @@ def __new__(cls, arg_: typing.Union[decimal.Decimal, int, float], **kwargs: sche class Float64Schema( NumberSchema[T] ): - class Schema_: - types = {decimal.Decimal} - format = 'double' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) + format: str = 'double' @classmethod def from_openapi_data_(cls, arg: float, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2316,8 +2352,9 @@ class StrSchema( - type: string (format unset) - type: string, format: date """ - class Schema_: - types = {str} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({str}) @classmethod def from_openapi_data_(cls, arg: str, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None) -> StrSchema[str]: @@ -2328,9 +2365,10 @@ def __new__(cls, arg_: typing.Union[str, datetime.date, datetime.datetime, uuid. class UUIDSchema(UUIDBase, StrSchema[T]): - class Schema_: - types = {str} - format = 'uuid' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({str}) + format: str = 'uuid' def __new__(cls, arg_: typing.Union[str, uuid.UUID], **kwargs: schema_configuration.SchemaConfiguration) -> UUIDSchema[str]: inst = super().__new__(cls, arg_, **kwargs) @@ -2338,9 +2376,10 @@ def __new__(cls, arg_: typing.Union[str, uuid.UUID], **kwargs: schema_configurat class DateSchema(DateBase, StrSchema[T]): - class Schema_: - types = {str} - format = 'date' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({str}) + format: str = 'date' def __new__(cls, arg_: typing.Union[str, datetime.date], **kwargs: schema_configuration.SchemaConfiguration) -> DateSchema[str]: inst = super().__new__(cls, arg_, **kwargs) @@ -2348,9 +2387,10 @@ def __new__(cls, arg_: typing.Union[str, datetime.date], **kwargs: schema_config class DateTimeSchema(DateTimeBase, StrSchema[T]): - class Schema_: - types = {str} - format = 'date-time' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({str}) + format: str = 'date-time' def __new__(cls, arg_: typing.Union[str, datetime.datetime], **kwargs: schema_configuration.SchemaConfiguration) -> DateTimeSchema[str]: inst = super().__new__(cls, arg_, **kwargs) @@ -2358,9 +2398,10 @@ def __new__(cls, arg_: typing.Union[str, datetime.datetime], **kwargs: schema_co class DecimalSchema(DecimalBase, StrSchema[T]): - class Schema_: - types = {str} - format = 'number' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({str}) + format: str = 'number' def __new__(cls, arg_: str, **kwargs: schema_configuration.SchemaConfiguration) -> DecimalSchema[str]: """ @@ -2382,8 +2423,9 @@ class BytesSchema( """ this class will subclass bytes and is immutable """ - class Schema_: - types = {bytes} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({bytes}) def __new__(cls, arg_: bytes, **kwargs: schema_configuration.SchemaConfiguration) -> BytesSchema[bytes]: super_cls: typing.Type = super(Schema, cls) @@ -2410,8 +2452,9 @@ class FileSchema( - to allow file reading and writing to disk - to be able to preserve file name info """ - class Schema_: - types = {FileIO} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({FileIO}) def __new__(cls, arg_: typing.Union[io.FileIO, io.BufferedReader], **kwargs: schema_configuration.SchemaConfiguration) -> FileSchema[FileIO]: super_cls: typing.Type = super(Schema, cls) @@ -2422,15 +2465,15 @@ class BinarySchema( Schema[T], BinaryMixin ): - class Schema_: - types = {FileIO, bytes} - format = 'binary' - - class OneOf: - classes = [ - BytesSchema, - FileSchema, - ] + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({FileIO, bytes}) + format: str = 'binary' + + one_of: typing.Tuple[typing.Type[Schema], ...] = ( + BytesSchema, + FileSchema, + ) def __new__(cls, arg_: typing.Union[io.FileIO, io.BufferedReader, bytes], **kwargs: schema_configuration.SchemaConfiguration) -> BinarySchema[typing.Union[FileIO, bytes]]: return super().__new__(cls, arg_) @@ -2441,8 +2484,9 @@ class BoolSchema( Schema[T], BoolMixin ): - class Schema_: - types = {BoolClass} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({BoolClass}) @classmethod def from_openapi_data_(cls, arg: bool, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2463,7 +2507,8 @@ class AnyTypeSchema( NoneFrozenDictTupleStrDecimalBoolFileBytesMixin ): # Python representation of a schema defined as true or {} - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): pass def __new__( @@ -2503,7 +2548,8 @@ def __new__( Schema, bytes, io.FileIO, - io.BufferedReader + io.BufferedReader, + Unset ] ) -> AnyTypeSchema[typing.Union[ NoneClass, @@ -2573,9 +2619,9 @@ class NotAnyTypeSchema(AnyTypeSchema[T]): Does not allow inputs in of AnyType Note: validations on this class are never run because the code knows that no inputs will ever validate """ - - class Schema_: - _not = AnyTypeSchema[U] + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + not_: typing.Type[Schema] = AnyTypeSchema def __new__( cls, @@ -2591,8 +2637,9 @@ class DictSchema( Schema[T], FrozenDictMixin ): - class Schema_: - types = {frozendict.frozendict} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) @classmethod def from_openapi_data_(cls, arg: typing.Dict[str, typing.Any], configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2628,3 +2675,57 @@ def get_new_class( def log_cache_usage(cache_fn): if LOG_CACHE_USAGE: print(cache_fn.__name__, cache_fn.cache_info()) + + +W = typing.TypeVar('W', bound=typing_extensions.TypedDict) + +def typed_dict_to_instance(t_dict: typing.Type[W]) -> W: + res = {} + for key, val in t_dict.__annotations__.items(): + if isinstance(val, typing._GenericAlias): # type: ignore + # typing.Type[W] -> W + val_cls = typing_extensions.get_args(val)[0] + res[key] = val_cls + return res # type: ignore + +X = typing.TypeVar('X', bound=typing.Tuple) + +def tuple_to_instance(tup: typing.Type[X]) -> X: + res = [] + for arg in typing_extensions.get_args(tup): + if isinstance(arg, typing._GenericAlias): # type: ignore + # typing.Type[Schema] -> Schema + arg_cls = typing_extensions.get_args(arg)[0] + res.append(arg_cls) + return tuple(res) # type: ignore + +INPUT_TYPES_ALL_INCL_SCHEMA = typing.Union[ + dict, + frozendict.frozendict, + list, + tuple, + decimal.Decimal, + float, + int, + str, + datetime.date, + datetime.datetime, + uuid.UUID, + bool, + None, + bytes, + io.FileIO, + io.BufferedReader, + Schema +] + +INPUT_BASE_TYPES = typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + BoolClass, + NoneClass, + tuple, + bytes, + FileIO +] \ No newline at end of file diff --git a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/server.py b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/server.py index efd2334213d..f92a1e80960 100644 --- a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/server.py +++ b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/server.py @@ -6,30 +6,29 @@ Generated by: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator """ +from __future__ import annotations import abc import dataclasses import typing @dataclasses.dataclass -class Server(abc.ABC): +class ServerWithoutVariables(abc.ABC): + url: str + + +@dataclasses.dataclass +class ServerWithVariables(abc.ABC): _url: str - variables: typing.Optional[typing.Dict[str, str]] = None - variable_schemas: typing.Optional[typing.Dict[str, typing.Type['schemas.Schema']]] = None + variables: schemas.DictSchema + variables_cls: typing.Type[schemas.DictSchema] url: str = dataclasses.field(init=False) def __post_init__(self): - if not self.variable_schemas: - self.url = self._url - return url = self._url - for (key, schema) in self.variable_schemas.items(): - if self.variables and key in self.variables: - value = self.variables[key] - cast_value = schema(value) - else: - cast_value = schema.Schema_.default - cast_value = typing.cast(str, cast_value) + assert isinstance (self.variables, self.variables_cls) + for (key, value) in self.variables.items(): + cast_value = typing.cast(str, value) url = url.replace("{" + key + "}", cast_value) self.url = url diff --git a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/servers/server_0.py b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/servers/server_0.py index b91d5343350..0caec3ac8b6 100644 --- a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/servers/server_0.py +++ b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/servers/server_0.py @@ -7,5 +7,5 @@ @dataclasses.dataclass -class Server0(server.Server): - _url: str = "http://localhost:3000" +class Server0(server.ServerWithoutVariables): + url: str = "http://localhost:3000" diff --git a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/shared_imports/schema_imports.py b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/shared_imports/schema_imports.py index 969dc875d45..4f12c94ef07 100644 --- a/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/shared_imports/schema_imports.py +++ b/samples/openapi3/client/features/nonCompliantUseDiscriminatorIfCompositionFails/python/src/this_package/shared_imports/schema_imports.py @@ -1,3 +1,4 @@ +import dataclasses import datetime import decimal import io diff --git a/samples/openapi3/client/features/security/python/src/this_package/configurations/schema_configuration.py b/samples/openapi3/client/features/security/python/src/this_package/configurations/schema_configuration.py index cc5a49d463d..242a6ea368e 100644 --- a/samples/openapi3/client/features/security/python/src/this_package/configurations/schema_configuration.py +++ b/samples/openapi3/client/features/security/python/src/this_package/configurations/schema_configuration.py @@ -13,34 +13,32 @@ PYTHON_KEYWORD_TO_JSON_SCHEMA_KEYWORD = { - 'types': 'type', + 'additional_properties': 'additionalProperties', + 'all_of': 'allOf', + 'any_of': 'anyOf', + 'discriminator': 'discriminator', + # default omitted because it has no validation impact 'enum_value_to_name': 'enum', - 'unique_items': 'uniqueItems', - 'min_items': 'minItems', + 'exclusive_maximum': 'exclusiveMaximum', + 'exclusive_minimum': 'exclusiveMinimum', + 'format': 'format', + 'inclusive_maximum': 'maximum', + 'inclusive_minimum': 'minimum', + 'items': 'items', 'max_items': 'maxItems', - 'min_properties': 'minProperties', + 'max_length': 'maxLength', 'max_properties': 'maxProperties', + 'min_items': 'minItems', 'min_length': 'minLength', - 'max_length': 'maxLength', - 'inclusive_minimum': 'minimum', - 'exclusive_minimum': 'exclusiveMinimum', - 'inclusive_maximum': 'maximum', - 'exclusive_maximum': 'exclusiveMaximum', + 'min_properties': 'minProperties', 'multiple_of': 'multipleOf', - 'regex': 'pattern', - 'format': 'format', + 'not_': 'not', + 'one_of': 'oneOf', + 'pattern': 'pattern', + 'properties': 'properties', 'required': 'required', - 'items': 'items', - 'Items': 'items', - 'Properties': 'properties', - 'additional_properties': 'additionalProperties', - 'additionalProperties': 'additionalProperties', - 'OneOf': 'oneOf', - 'AnyOf': 'anyOf', - 'AllOf': 'allOf', - '_not': 'not', - '_Not': 'not', - 'discriminator': 'discriminator' + 'types': 'type', + 'unique_items': 'uniqueItems' } class SchemaConfiguration: diff --git a/samples/openapi3/client/features/security/python/src/this_package/schemas.py b/samples/openapi3/client/features/security/python/src/this_package/schemas.py index afdbd92be28..835416dd93b 100644 --- a/samples/openapi3/client/features/security/python/src/this_package/schemas.py +++ b/samples/openapi3/client/features/security/python/src/this_package/schemas.py @@ -13,6 +13,7 @@ import dataclasses import functools import decimal +import inspect import io import re import types @@ -111,6 +112,20 @@ def add_deeper_validated_schemas(validation_metadata: ValidationMetadata, path_t update(path_to_schemas, other_path_to_schemas) +class SingletonMeta(type): + """ + A singleton class for schemas + Schemas are frozen classes that are never instantiated with init args + All args come from defaults + """ + _instances = {} + + def __call__(cls, *args, **kwargs): + if cls not in cls._instances: + cls._instances[cls] = super().__call__(*args, **kwargs) + return cls._instances[cls] + + class Singleton: """ Enums and singletons are the same @@ -147,14 +162,18 @@ def __repr__(self): return f'<{self.__class__.__name__}: False>' return f'<{self.__class__.__name__}: {super().__repr__()}>' +T = typing.TypeVar('T') -class classproperty: - def __init__(self, fget): - self.fget = fget +class classproperty(typing.Generic[T]): + def __init__(self, method: typing.Callable[..., T]): + self.__method = method + functools.update_wrapper(self, method) # type: ignore - def __get__(self, owner_self, owner_cls): - return self.fget(owner_cls) + def __get__(self, obj, cls=None) -> T: + if cls is None: + cls = type(obj) + return self.__method(cls) class NoneClass(Singleton): @@ -183,32 +202,40 @@ def __bool__(self) -> bool: raise ValueError('Unable to find the boolean value of this instance') +@dataclasses.dataclass(frozen=True) +class PatternInfo: + pattern: str + flags: typing.Optional[re.RegexFlag] = None + + class SchemaTyped: - types: typing.Optional[typing.Set[typing.Type]] + additional_properties: typing.Type[Schema] + all_of: typing.Tuple[typing.Type[Schema], ...] + any_of: typing.Tuple[typing.Type[Schema], ...] + discriminator: typing.Mapping[str, typing.Mapping[str, typing.Type[Schema]]] + default: typing.Union[str, int, float, BoolClass, NoneClass] + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, BoolClass, NoneClass], str] exclusive_maximum: typing.Union[int, float] - inclusive_maximum: typing.Union[int, float] exclusive_minimum: typing.Union[int, float] + format: str + inclusive_maximum: typing.Union[int, float] inclusive_minimum: typing.Union[int, float] + items: typing.Type[Schema] max_items: int - min_items: int - discriminator: typing.Dict[str, typing.Dict[str, typing.Type['Schema']]] - default: typing.Union[str, int, BoolClass] - - - class Properties: - # to hold object properties - pass - - additionalProperties: typing.Optional[typing.Type['Schema']] - max_properties: int - min_properties: int - AllOf: typing.List[typing.Type['Schema']] - OneOf: typing.List[typing.Type['Schema']] - AnyOf: typing.List[typing.Type['Schema']] - _not: typing.Type['Schema'] max_length: int + max_properties: int + min_items: int min_length: int - items: typing.Type['Schema'] + min_properties: int + multiple_of: typing.Union[int, float] + not_: typing.Type[Schema] + one_of: typing.Tuple[typing.Type[Schema], ...] + pattern: PatternInfo + properties: typing.Mapping[str, typing.Type[Schema]] + required: typing.FrozenSet[str] + types: typing.FrozenSet[typing.Type] + unique_items: bool + PathToSchemasType = typing.Dict[ typing.Tuple[typing.Union[str, int], ...], @@ -530,30 +557,30 @@ def validate_multiple_of( return None -def validate_regex( +def validate_pattern( arg: typing.Any, - regex_dict: typing.Dict, + pattern_info: PatternInfo, cls: typing.Type, validation_metadata: ValidationMetadata, ) -> None: if not isinstance(arg, str): return None - flags = regex_dict.get('flags', 0) - if not re.search(regex_dict['pattern'], arg, flags=flags): + flags = pattern_info.flags if pattern_info.flags is not None else 0 + if not re.search(pattern_info.pattern, arg, flags=flags): if flags != 0: # Don't print the regex flags if the flags are not # specified in the OAS document. _raise_validation_error_message( value=arg, constraint_msg="must match regular expression", - constraint_value=regex_dict['pattern'], + constraint_value=pattern_info.pattern, path_to_item=validation_metadata.path_to_item, additional_txt=" with flags=`{}`".format(flags) ) _raise_validation_error_message( value=arg, constraint_msg="must match regular expression", - constraint_value=regex_dict['pattern'], + constraint_value=pattern_info.pattern, path_to_item=validation_metadata.path_to_item ) return None @@ -649,8 +676,8 @@ def __parse_isodate(self, dt_str: str) -> typing.Tuple[typing.Tuple[int, int, in def __parse_isotime(self, dt_str: str) -> typing.Tuple[int, int, int, int, typing.Optional[typing.Union[tz.tzutc, tz.tzoffset]]]: dt_str_ascii = self.__get_ascii_bytes(dt_str) values = self._parse_isotime(dt_str_ascii) # type: ignore - components: typing.Tuple[int, int, int, int, typing.Optional[typing.Union[tz.tzutc, tz.tzoffset]]] = tuple(values) - return tuple(components) + components: typing.Tuple[int, int, int, int, typing.Optional[typing.Union[tz.tzutc, tz.tzoffset]]] = tuple(values) # type: ignore + return components def parse_isodatetime(self, dt_str: str) -> datetime.datetime: components, pos = self.__parse_isodate(dt_str) @@ -786,17 +813,20 @@ def _get_class(item_cls: typing.Union[types.FunctionType, staticmethod, typing.T elif isinstance(item_cls, staticmethod): # referenced schema return item_cls.__func__() - return item_cls + elif isinstance(item_cls, type): + return item_cls + raise ValueError('invalid class value passed in') def validate_items( arg: typing.Any, - item_cls: typing.Type, + item_cls: typing.Type[Schema], cls: typing.Type, validation_metadata: ValidationMetadata, ) -> typing.Optional[PathToSchemasType]: if not isinstance(arg, tuple): return None + schema = _get_class(additional_properties_cls) item_cls = _get_class(item_cls) path_to_schemas = {} for i, value in enumerate(arg): @@ -816,17 +846,17 @@ def validate_items( def validate_properties( arg: typing.Any, - properties: typing.Type, + properties: typing.Mapping[str, typing.Type[Schema]], cls: typing.Type, validation_metadata: ValidationMetadata, ) -> typing.Optional[PathToSchemasType]: if not isinstance(arg, frozendict.frozendict): return None path_to_schemas = {} - present_properties = {k: v for k, v, in arg.items() if k in properties.__annotations__} + present_properties = {k: v for k, v, in arg.items() if k in properties} for property_name, value in present_properties.items(): path_to_item = validation_metadata.path_to_item + (property_name,) - schema = properties.__annotations__[property_name] + schema = properties[property_name] schema = _get_class(schema) arg_validation_metadata = ValidationMetadata( path_to_item=path_to_item, @@ -843,16 +873,17 @@ def validate_properties( def validate_additional_properties( arg: typing.Any, - additional_properties_schema: typing.Type, + additional_properties_cls: typing.Type[Schema], cls: typing.Type, validation_metadata: ValidationMetadata, ) -> typing.Optional[PathToSchemasType]: if not isinstance(arg, frozendict.frozendict): return None - schema = _get_class(additional_properties_schema) + schema = _get_class(additional_properties_cls) path_to_schemas = {} - properties_annotations = cls.Schema_.Properties.__annotations__ if hasattr(cls.Schema_, 'Properties') else {} - present_additional_properties = {k: v for k, v, in arg.items() if k not in properties_annotations} + cls_schema = cls.Schema_() + properties = cls_schema.properties if hasattr(cls_schema, 'properties') else {} + present_additional_properties = {k: v for k, v, in arg.items() if k not in properties} for property_name, value in present_additional_properties.items(): path_to_item = validation_metadata.path_to_item + (property_name,) arg_validation_metadata = ValidationMetadata( @@ -870,14 +901,14 @@ def validate_additional_properties( def validate_one_of( arg: typing.Any, - one_of_container_cls: typing.Type, + classes: typing.Tuple[typing.Type[Schema], ...], cls: 'Schema', validation_metadata: ValidationMetadata, ) -> PathToSchemasType: oneof_classes = [] path_to_schemas = collections.defaultdict(set) - for one_of_cls in one_of_container_cls.classes: - schema = _get_class(one_of_cls) + for schema in classes: + schema = _get_class(schema) if schema in path_to_schemas[validation_metadata.path_to_item]: oneof_classes.append(schema) continue @@ -914,14 +945,14 @@ def validate_one_of( def validate_any_of( arg: typing.Any, - any_of_container_cls: typing.Type, + classes: typing.Tuple[typing.Type[Schema], ...], cls: 'Schema', validation_metadata: ValidationMetadata, ) -> PathToSchemasType: anyof_classes = [] path_to_schemas = collections.defaultdict(set) - for any_of_cls in any_of_container_cls.classes: - schema = _get_class(any_of_cls) + for schema in classes: + schema = _get_class(schema) if schema is cls: """ optimistically assume that cls schema will pass validation @@ -951,13 +982,13 @@ def validate_any_of( def validate_all_of( arg: typing.Any, - all_of_cls: typing.Type, + classes: typing.Tuple[typing.Type[Schema], ...], cls: typing.Type, validation_metadata: ValidationMetadata, ) -> PathToSchemasType: path_to_schemas = collections.defaultdict(set) - for allof_cls in all_of_cls.classes: - schema = _get_class(allof_cls) + for schema in classes: + schema = _get_class(schema) if schema is cls: """ optimistically assume that cls schema will pass validation @@ -974,7 +1005,7 @@ def validate_all_of( def validate_not( arg: typing.Any, - not_cls: typing.Type, + not_cls: typing.Type[Schema], cls: typing.Type, validation_metadata: ValidationMetadata, ) -> None: @@ -1016,38 +1047,36 @@ def __get_discriminated_class(cls, disc_property_name: str, disc_payload_value: """ Used in schemas with discriminators """ - if not hasattr(cls.Schema_, 'discriminator'): + cls_schema = cls.Schema_() + if not hasattr(cls_schema, 'discriminator'): return None - disc = cls.Schema_.discriminator() + disc = cls_schema.discriminator if disc_property_name not in disc: return None discriminated_cls = disc[disc_property_name].get(disc_payload_value) if discriminated_cls is not None: return discriminated_cls if not ( - hasattr(cls.Schema_, 'AllOf') or - hasattr(cls.Schema_, 'OneOf') or - hasattr(cls.Schema_, 'AnyOf') + hasattr(cls_schema, 'all_of') or + hasattr(cls_schema, 'one_of') or + hasattr(cls_schema, 'any_of') ): return None # TODO stop traveling if a cycle is hit - if hasattr(cls.Schema_, 'AllOf'): - for allof_cls in cls.Schema_.AllOf.classes: - allof_cls = _get_class(allof_cls) + if hasattr(cls_schema, 'all_of'): + for allof_cls in cls_schema.all_of: discriminated_cls = __get_discriminated_class( allof_cls, disc_property_name=disc_property_name, disc_payload_value=disc_payload_value) if discriminated_cls is not None: return discriminated_cls - if hasattr(cls.Schema_, 'OneOf'): - for oneof_cls in cls.Schema_.OneOf.classes: - oneof_cls = _get_class(oneof_cls) + if hasattr(cls_schema, 'one_of'): + for oneof_cls in cls_schema.one_of: discriminated_cls = __get_discriminated_class( oneof_cls, disc_property_name=disc_property_name, disc_payload_value=disc_payload_value) if discriminated_cls is not None: return discriminated_cls - if hasattr(cls.Schema_, 'AnyOf'): - for anyof_cls in cls.Schema_.AnyOf.classes: - anyof_cls = _get_class(anyof_cls) + if hasattr(cls_schema, 'any_of'): + for anyof_cls in cls_schema.any_of: discriminated_cls = __get_discriminated_class( anyof_cls, disc_property_name=disc_property_name, disc_payload_value=disc_payload_value) if discriminated_cls is not None: @@ -1057,13 +1086,12 @@ def __get_discriminated_class(cls, disc_property_name: str, disc_payload_value: def validate_discriminator( arg: typing.Any, - discriminator_fn: typing.Type, + discriminator: typing.Mapping[str, typing.Mapping[str, typing.Type[Schema]]], cls: typing.Type, validation_metadata: ValidationMetadata, ) -> typing.Optional[PathToSchemasType]: if not isinstance(arg, frozendict.frozendict): return None - discriminator = discriminator_fn.__func__() disc_prop_name = list(discriminator.keys())[0] __ensure_discriminator_value_present(disc_prop_name, validation_metadata, arg) discriminated_cls = __get_discriminated_class( @@ -1112,24 +1140,19 @@ def validate_discriminator( 'inclusive_maximum': validate_inclusive_maximum, 'exclusive_maximum': validate_exclusive_maximum, 'multiple_of': validate_multiple_of, - 'regex': validate_regex, + 'pattern': validate_pattern, 'format': validate_format, 'required': validate_required, 'items': validate_items, - 'Items': validate_items, - 'Properties': validate_properties, - 'AdditionalProperties': validate_additional_properties, + 'properties': validate_properties, 'additional_properties': validate_additional_properties, - 'OneOf': validate_one_of, - 'AnyOf': validate_any_of, - 'AllOf': validate_all_of, - '_not': validate_not, - '_Not': validate_not, - 'ModelNot': validate_not, + 'one_of': validate_one_of, + 'any_of': validate_any_of, + 'all_of': validate_all_of, + 'not_': validate_not, 'discriminator': validate_discriminator } -T = typing.TypeVar('T') U = typing.TypeVar('U') class Schema(typing.Generic[T]): @@ -1158,9 +1181,10 @@ def _validate( All keyword validation except for type checking was done in calling stack frames If those validations passed, the validated classes are collected in path_to_schemas """ + cls_schema = cls.Schema_() json_schema_data = { k: v - for k, v in vars(cls.Schema_).items() + for k, v in vars(cls_schema).items() if k not in cls.__excluded_cls_properties and k not in validation_metadata.configuration.disabled_json_schema_python_keywords @@ -1276,7 +1300,7 @@ def __get_new_cls( """ cls._process_schema_classes(schema_classes) enum_schema = any( - issubclass(this_cls, Schema) and hasattr(this_cls.Schema_, "enum_value_to_name") + issubclass(this_cls, Schema) and hasattr(this_cls.Schema_(), "enum_value_to_name") for this_cls in schema_classes ) inheritable_primitive_type = schema_classes.intersection(cls.__inheritable_primitive_types_set) @@ -1396,9 +1420,11 @@ def __new__( bytes, io.FileIO, io.BufferedReader, - 'Schema', ], + 'Schema', + ], configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None, **kwargs: typing.Union[ + Unset, dict, frozendict.frozendict, list, @@ -1415,7 +1441,7 @@ def __new__( bytes, io.FileIO, io.BufferedReader, - 'Schema', Unset + 'Schema', ] ): """ @@ -1971,7 +1997,8 @@ def cast_to_allowed_types( bytes, io.FileIO, io.BufferedReader, - 'Schema', ], + '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.frozendict, tuple]]], path_to_item: typing.Tuple[typing.Union[str, int], ...], @@ -2100,8 +2127,9 @@ class ListSchema( Schema[T], TupleMixin ): - class Schema_: - types = {tuple} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) @classmethod def from_openapi_data_(cls, arg: typing.Sequence[typing.Any], configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2116,8 +2144,9 @@ class NoneSchema( Schema[T], NoneMixin ): - class Schema_: - types = {NoneClass} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({NoneClass}) @classmethod def from_openapi_data_(cls, arg: None, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2136,8 +2165,9 @@ class NumberSchema( This is used for type: number with no format Both integers AND floats are accepted """ - class Schema_: - types = {decimal.Decimal} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) @classmethod def from_openapi_data_(cls, arg: typing.Union[int, float], configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2160,9 +2190,10 @@ def as_int_(self) -> int: class IntSchema(IntBase, NumberSchema[T]): - class Schema_: - types = {decimal.Decimal} - format = 'int' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) + format: str = 'int' @classmethod def from_openapi_data_(cls, arg: int, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2176,9 +2207,10 @@ def __new__(cls, arg_: typing.Union[decimal.Decimal, int], **kwargs: schema_conf class Int32Schema( IntSchema[T] ): - class Schema_: - types = {decimal.Decimal} - format = 'int32' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) + format: str = 'int32' def __new__(cls, arg_: typing.Union[decimal.Decimal, int], **kwargs: schema_configuration.SchemaConfiguration) -> Int32Schema[decimal.Decimal]: inst = super().__new__(cls, arg_, **kwargs) @@ -2188,9 +2220,10 @@ def __new__(cls, arg_: typing.Union[decimal.Decimal, int], **kwargs: schema_conf class Int64Schema( IntSchema[T] ): - class Schema_: - types = {decimal.Decimal} - format = 'int64' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) + format: str = 'int64' def __new__(cls, arg_: typing.Union[decimal.Decimal, int], **kwargs: schema_configuration.SchemaConfiguration) -> Int64Schema[decimal.Decimal]: inst = super().__new__(cls, arg_, **kwargs) @@ -2200,9 +2233,10 @@ def __new__(cls, arg_: typing.Union[decimal.Decimal, int], **kwargs: schema_conf class Float32Schema( NumberSchema[T] ): - class Schema_: - types = {decimal.Decimal} - format = 'float' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) + format: str = 'float' @classmethod def from_openapi_data_(cls, arg: float, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2216,9 +2250,10 @@ def __new__(cls, arg_: typing.Union[decimal.Decimal, int, float], **kwargs: sche class Float64Schema( NumberSchema[T] ): - class Schema_: - types = {decimal.Decimal} - format = 'double' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) + format: str = 'double' @classmethod def from_openapi_data_(cls, arg: float, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2240,8 +2275,9 @@ class StrSchema( - type: string (format unset) - type: string, format: date """ - class Schema_: - types = {str} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({str}) @classmethod def from_openapi_data_(cls, arg: str, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None) -> StrSchema[str]: @@ -2252,9 +2288,10 @@ def __new__(cls, arg_: typing.Union[str, datetime.date, datetime.datetime, uuid. class UUIDSchema(UUIDBase, StrSchema[T]): - class Schema_: - types = {str} - format = 'uuid' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({str}) + format: str = 'uuid' def __new__(cls, arg_: typing.Union[str, uuid.UUID], **kwargs: schema_configuration.SchemaConfiguration) -> UUIDSchema[str]: inst = super().__new__(cls, arg_, **kwargs) @@ -2262,9 +2299,10 @@ def __new__(cls, arg_: typing.Union[str, uuid.UUID], **kwargs: schema_configurat class DateSchema(DateBase, StrSchema[T]): - class Schema_: - types = {str} - format = 'date' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({str}) + format: str = 'date' def __new__(cls, arg_: typing.Union[str, datetime.date], **kwargs: schema_configuration.SchemaConfiguration) -> DateSchema[str]: inst = super().__new__(cls, arg_, **kwargs) @@ -2272,9 +2310,10 @@ def __new__(cls, arg_: typing.Union[str, datetime.date], **kwargs: schema_config class DateTimeSchema(DateTimeBase, StrSchema[T]): - class Schema_: - types = {str} - format = 'date-time' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({str}) + format: str = 'date-time' def __new__(cls, arg_: typing.Union[str, datetime.datetime], **kwargs: schema_configuration.SchemaConfiguration) -> DateTimeSchema[str]: inst = super().__new__(cls, arg_, **kwargs) @@ -2282,9 +2321,10 @@ def __new__(cls, arg_: typing.Union[str, datetime.datetime], **kwargs: schema_co class DecimalSchema(DecimalBase, StrSchema[T]): - class Schema_: - types = {str} - format = 'number' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({str}) + format: str = 'number' def __new__(cls, arg_: str, **kwargs: schema_configuration.SchemaConfiguration) -> DecimalSchema[str]: """ @@ -2306,8 +2346,9 @@ class BytesSchema( """ this class will subclass bytes and is immutable """ - class Schema_: - types = {bytes} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({bytes}) def __new__(cls, arg_: bytes, **kwargs: schema_configuration.SchemaConfiguration) -> BytesSchema[bytes]: super_cls: typing.Type = super(Schema, cls) @@ -2334,8 +2375,9 @@ class FileSchema( - to allow file reading and writing to disk - to be able to preserve file name info """ - class Schema_: - types = {FileIO} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({FileIO}) def __new__(cls, arg_: typing.Union[io.FileIO, io.BufferedReader], **kwargs: schema_configuration.SchemaConfiguration) -> FileSchema[FileIO]: super_cls: typing.Type = super(Schema, cls) @@ -2346,15 +2388,15 @@ class BinarySchema( Schema[T], BinaryMixin ): - class Schema_: - types = {FileIO, bytes} - format = 'binary' - - class OneOf: - classes = [ - BytesSchema, - FileSchema, - ] + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({FileIO, bytes}) + format: str = 'binary' + + one_of: typing.Tuple[typing.Type[Schema], ...] = ( + BytesSchema, + FileSchema, + ) def __new__(cls, arg_: typing.Union[io.FileIO, io.BufferedReader, bytes], **kwargs: schema_configuration.SchemaConfiguration) -> BinarySchema[typing.Union[FileIO, bytes]]: return super().__new__(cls, arg_) @@ -2365,8 +2407,9 @@ class BoolSchema( Schema[T], BoolMixin ): - class Schema_: - types = {BoolClass} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({BoolClass}) @classmethod def from_openapi_data_(cls, arg: bool, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2387,7 +2430,8 @@ class AnyTypeSchema( NoneFrozenDictTupleStrDecimalBoolFileBytesMixin ): # Python representation of a schema defined as true or {} - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): pass def __new__( @@ -2427,7 +2471,8 @@ def __new__( Schema, bytes, io.FileIO, - io.BufferedReader + io.BufferedReader, + Unset ] ) -> AnyTypeSchema[typing.Union[ NoneClass, @@ -2497,9 +2542,9 @@ class NotAnyTypeSchema(AnyTypeSchema[T]): Does not allow inputs in of AnyType Note: validations on this class are never run because the code knows that no inputs will ever validate """ - - class Schema_: - _not = AnyTypeSchema[U] + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + not_: typing.Type[Schema] = AnyTypeSchema def __new__( cls, @@ -2515,8 +2560,9 @@ class DictSchema( Schema[T], FrozenDictMixin ): - class Schema_: - types = {frozendict.frozendict} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) @classmethod def from_openapi_data_(cls, arg: typing.Dict[str, typing.Any], configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2552,3 +2598,57 @@ def get_new_class( def log_cache_usage(cache_fn): if LOG_CACHE_USAGE: print(cache_fn.__name__, cache_fn.cache_info()) + + +W = typing.TypeVar('W', bound=typing_extensions.TypedDict) + +def typed_dict_to_instance(t_dict: typing.Type[W]) -> W: + res = {} + for key, val in t_dict.__annotations__.items(): + if isinstance(val, typing._GenericAlias): # type: ignore + # typing.Type[W] -> W + val_cls = typing_extensions.get_args(val)[0] + res[key] = val_cls + return res # type: ignore + +X = typing.TypeVar('X', bound=typing.Tuple) + +def tuple_to_instance(tup: typing.Type[X]) -> X: + res = [] + for arg in typing_extensions.get_args(tup): + if isinstance(arg, typing._GenericAlias): # type: ignore + # typing.Type[Schema] -> Schema + arg_cls = typing_extensions.get_args(arg)[0] + res.append(arg_cls) + return tuple(res) # type: ignore + +INPUT_TYPES_ALL_INCL_SCHEMA = typing.Union[ + dict, + frozendict.frozendict, + list, + tuple, + decimal.Decimal, + float, + int, + str, + datetime.date, + datetime.datetime, + uuid.UUID, + bool, + None, + bytes, + io.FileIO, + io.BufferedReader, + Schema +] + +INPUT_BASE_TYPES = typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + BoolClass, + NoneClass, + tuple, + bytes, + FileIO +] \ No newline at end of file diff --git a/samples/openapi3/client/features/security/python/src/this_package/server.py b/samples/openapi3/client/features/security/python/src/this_package/server.py index d1ead4d75c1..542ff1c4487 100644 --- a/samples/openapi3/client/features/security/python/src/this_package/server.py +++ b/samples/openapi3/client/features/security/python/src/this_package/server.py @@ -6,30 +6,29 @@ Generated by: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator """ +from __future__ import annotations import abc import dataclasses import typing @dataclasses.dataclass -class Server(abc.ABC): +class ServerWithoutVariables(abc.ABC): + url: str + + +@dataclasses.dataclass +class ServerWithVariables(abc.ABC): _url: str - variables: typing.Optional[typing.Dict[str, str]] = None - variable_schemas: typing.Optional[typing.Dict[str, typing.Type['schemas.Schema']]] = None + variables: schemas.DictSchema + variables_cls: typing.Type[schemas.DictSchema] url: str = dataclasses.field(init=False) def __post_init__(self): - if not self.variable_schemas: - self.url = self._url - return url = self._url - for (key, schema) in self.variable_schemas.items(): - if self.variables and key in self.variables: - value = self.variables[key] - cast_value = schema(value) - else: - cast_value = schema.Schema_.default - cast_value = typing.cast(str, cast_value) + assert isinstance (self.variables, self.variables_cls) + for (key, value) in self.variables.items(): + cast_value = typing.cast(str, value) url = url.replace("{" + key + "}", cast_value) self.url = url diff --git a/samples/openapi3/client/features/security/python/src/this_package/servers/server_0.py b/samples/openapi3/client/features/security/python/src/this_package/servers/server_0.py index b91d5343350..0caec3ac8b6 100644 --- a/samples/openapi3/client/features/security/python/src/this_package/servers/server_0.py +++ b/samples/openapi3/client/features/security/python/src/this_package/servers/server_0.py @@ -7,5 +7,5 @@ @dataclasses.dataclass -class Server0(server.Server): - _url: str = "http://localhost:3000" +class Server0(server.ServerWithoutVariables): + url: str = "http://localhost:3000" diff --git a/samples/openapi3/client/features/security/python/src/this_package/shared_imports/schema_imports.py b/samples/openapi3/client/features/security/python/src/this_package/shared_imports/schema_imports.py index 969dc875d45..4f12c94ef07 100644 --- a/samples/openapi3/client/features/security/python/src/this_package/shared_imports/schema_imports.py +++ b/samples/openapi3/client/features/security/python/src/this_package/shared_imports/schema_imports.py @@ -1,3 +1,4 @@ +import dataclasses import datetime import decimal import io diff --git a/samples/openapi3/client/petstore/python/docs/components/schema/additional_properties_class.md b/samples/openapi3/client/petstore/python/docs/components/schema/additional_properties_class.md index 6a92ea9cc1a..f37677c0e21 100644 --- a/samples/openapi3/client/petstore/python/docs/components/schema/additional_properties_class.md +++ b/samples/openapi3/client/petstore/python/docs/components/schema/additional_properties_class.md @@ -41,9 +41,9 @@ dict, frozendict.frozendict | frozendict.frozendict | | ## Dictionary Keys Key | Input Type | Accessed Type | Description | Notes ------------ | ------------- | ------------- | ------------- | ------------- -**any_string_name** | dict, frozendict.frozendict | [AdditionalProperties](#properties-mapofmapproperty-additionalproperties) | any string name can be used but the value must be the correct type | [optional] +**any_string_name** | dict, frozendict.frozendict | [AdditionalProperties2](#properties-mapofmapproperty-additionalproperties2) | any string name can be used but the value must be the correct type | [optional] -# properties MapOfMapProperty AdditionalProperties +# properties MapOfMapProperty AdditionalProperties2 ## Type Info Input Type | Accessed Type | Description | Notes diff --git a/samples/openapi3/client/petstore/python/docs/components/schema/array_test.md b/samples/openapi3/client/petstore/python/docs/components/schema/array_test.md index 9f0a23efc2d..5cb5ad65cad 100644 --- a/samples/openapi3/client/petstore/python/docs/components/schema/array_test.md +++ b/samples/openapi3/client/petstore/python/docs/components/schema/array_test.md @@ -36,9 +36,9 @@ list, tuple | tuple | | ## List Items Class Name | Input Type | Accessed Type | Description | Notes ------------- | ------------- | ------------- | ------------- | ------------- -[items](#properties-arrayarrayofinteger-items) | list, tuple | tuple | | +[items](#properties-arrayarrayofinteger-items2) | list, tuple | tuple | | -# properties ArrayArrayOfInteger Items +# properties ArrayArrayOfInteger Items2 ## Type Info Input Type | Accessed Type | Description | Notes @@ -60,9 +60,9 @@ list, tuple | tuple | | ## List Items Class Name | Input Type | Accessed Type | Description | Notes ------------- | ------------- | ------------- | ------------- | ------------- -[items](#properties-arrayarrayofmodel-items) | list, tuple | tuple | | +[items](#properties-arrayarrayofmodel-items4) | list, tuple | tuple | | -# properties ArrayArrayOfModel Items +# properties ArrayArrayOfModel Items4 ## Type Info Input Type | Accessed Type | Description | Notes diff --git a/samples/openapi3/client/petstore/python/docs/components/schema/nullable_class.md b/samples/openapi3/client/petstore/python/docs/components/schema/nullable_class.md index 27117058e3a..6eb7f06fe54 100644 --- a/samples/openapi3/client/petstore/python/docs/components/schema/nullable_class.md +++ b/samples/openapi3/client/petstore/python/docs/components/schema/nullable_class.md @@ -21,7 +21,7 @@ Key | Input Type | Accessed Type | Description | Notes **object_nullable_prop** | None, dict, frozendict.frozendict | [properties.ObjectNullableProp](#properties-objectnullableprop) | | [optional] **object_and_items_nullable_prop** | None, dict, frozendict.frozendict | [properties.ObjectAndItemsNullableProp](#properties-objectanditemsnullableprop) | | [optional] **object_items_nullable** | dict, frozendict.frozendict | [properties.ObjectItemsNullable](#properties-objectitemsnullable) | | [optional] -**any_string_name** | None, dict, frozendict.frozendict | [AdditionalProperties](#additionalproperties) | any string name can be used but the value must be the correct type | [optional] +**any_string_name** | None, dict, frozendict.frozendict | [AdditionalProperties4](#additionalproperties4) | any string name can be used but the value must be the correct type | [optional] # properties ArrayNullableProp @@ -52,9 +52,9 @@ None, list, tuple | NoneClass, tuple | | ## List Items Class Name | Input Type | Accessed Type | Description | Notes ------------- | ------------- | ------------- | ------------- | ------------- -[items](#properties-arrayanditemsnullableprop-items) | None, dict, frozendict.frozendict | NoneClass, frozendict.frozendict | | +[items](#properties-arrayanditemsnullableprop-items2) | None, dict, frozendict.frozendict | NoneClass, frozendict.frozendict | | -# properties ArrayAndItemsNullableProp Items +# properties ArrayAndItemsNullableProp Items2 ## Type Info Input Type | Accessed Type | Description | Notes @@ -71,9 +71,9 @@ list, tuple | tuple | | ## List Items Class Name | Input Type | Accessed Type | Description | Notes ------------- | ------------- | ------------- | ------------- | ------------- -[items](#properties-arrayitemsnullable-items) | None, dict, frozendict.frozendict | NoneClass, frozendict.frozendict | | +[items](#properties-arrayitemsnullable-items3) | None, dict, frozendict.frozendict | NoneClass, frozendict.frozendict | | -# properties ArrayItemsNullable Items +# properties ArrayItemsNullable Items3 ## Type Info Input Type | Accessed Type | Description | Notes @@ -109,9 +109,9 @@ None, dict, frozendict.frozendict | NoneClass, frozendict.frozendict | | ## Dictionary Keys Key | Input Type | Accessed Type | Description | Notes ------------ | ------------- | ------------- | ------------- | ------------- -**any_string_name** | None, dict, frozendict.frozendict | [AdditionalProperties](#properties-objectanditemsnullableprop-additionalproperties) | any string name can be used but the value must be the correct type | [optional] +**any_string_name** | None, dict, frozendict.frozendict | [AdditionalProperties2](#properties-objectanditemsnullableprop-additionalproperties2) | any string name can be used but the value must be the correct type | [optional] -# properties ObjectAndItemsNullableProp AdditionalProperties +# properties ObjectAndItemsNullableProp AdditionalProperties2 ## Type Info Input Type | Accessed Type | Description | Notes @@ -128,16 +128,16 @@ dict, frozendict.frozendict | frozendict.frozendict | | ## Dictionary Keys Key | Input Type | Accessed Type | Description | Notes ------------ | ------------- | ------------- | ------------- | ------------- -**any_string_name** | None, dict, frozendict.frozendict | [AdditionalProperties](#properties-objectitemsnullable-additionalproperties) | any string name can be used but the value must be the correct type | [optional] +**any_string_name** | None, dict, frozendict.frozendict | [AdditionalProperties3](#properties-objectitemsnullable-additionalproperties3) | any string name can be used but the value must be the correct type | [optional] -# properties ObjectItemsNullable AdditionalProperties +# properties ObjectItemsNullable AdditionalProperties3 ## Type Info Input Type | Accessed Type | Description | Notes ------------ | ------------- | ------------- | ------------- None, dict, frozendict.frozendict | NoneClass, frozendict.frozendict | | -# AdditionalProperties +# AdditionalProperties4 ## Type Info Input Type | Accessed Type | Description | Notes diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/headers/header_int32_json_content_type_header/content/application_json/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/headers/header_int32_json_content_type_header/content/application_json/schema.py index af8e03d6a9c..5af8b8a8ede 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/headers/header_int32_json_content_type_header/content/application_json/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/headers/header_int32_json_content_type_header/content/application_json/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.Int32Schema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/headers/header_number_header/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/headers/header_number_header/schema.py index b89a7f46971..e394930dca7 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/headers/header_number_header/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/headers/header_number_header/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.DecimalSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/headers/header_string_header/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/headers/header_string_header/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/headers/header_string_header/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/headers/header_string_header/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/parameters/parameter_path_user_name/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/parameters/parameter_path_user_name/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/parameters/parameter_path_user_name/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/parameters/parameter_path_user_name/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/request_bodies/request_body_user_array/content/application_json/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/request_bodies/request_body_user_array/content/application_json/schema.py index bf33d2594d7..bd05e0c284e 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/request_bodies/request_body_user_array/content/application_json/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/request_bodies/request_body_user_array/content/application_json/schema.py @@ -11,17 +11,16 @@ from petstore_api.shared_imports.schema_imports import * + class Schema( schemas.ListSchema[schemas.T] ): - class Schema_: - types = {tuple} - - @staticmethod - def items() -> typing.Type[user.User]: - return user.User + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[user.User] = dataclasses.field(default_factory=lambda: user.User) # type: ignore def __new__( cls, @@ -48,4 +47,5 @@ def __new__( def __getitem__(self, name: int) -> user.User[frozendict.frozendict]: return super().__getitem__(name) + from petstore_api.components.schema import user diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/responses/response_success_inline_content_and_header/content/application_json/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/responses/response_success_inline_content_and_header/content/application_json/schema.py index ba5df782e33..da3877c8b2a 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/responses/response_success_inline_content_and_header/content/application_json/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/responses/response_success_inline_content_and_header/content/application_json/schema.py @@ -10,17 +10,20 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +AdditionalProperties: typing_extensions.TypeAlias = schemas.Int32Schema[U] + class Schema( schemas.DictSchema[schemas.T] ): - class Schema_: - types = {frozendict.frozendict} - AdditionalProperties: typing_extensions.TypeAlias = schemas.Int32Schema[U] + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[decimal.Decimal]: + def __getitem__(self, name: str) -> AdditionalProperties[decimal.Decimal]: # dict_instance[name] accessor return super().__getitem__(name) @@ -29,7 +32,7 @@ def __new__( *args_: typing.Union[dict, frozendict.frozendict], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, **kwargs: typing.Union[ - Schema_.AdditionalProperties[decimal.Decimal], + AdditionalProperties[decimal.Decimal], decimal.Decimal, int ], @@ -45,3 +48,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/responses/response_success_inline_content_and_header/headers/header_some_header/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/responses/response_success_inline_content_and_header/headers/header_some_header/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/responses/response_success_inline_content_and_header/headers/header_some_header/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/responses/response_success_inline_content_and_header/headers/header_some_header/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/responses/response_successful_xml_and_json_array_of_pet/content/application_json/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/responses/response_successful_xml_and_json_array_of_pet/content/application_json/schema.py index 4c3448a28c3..645ab0e3b45 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/responses/response_successful_xml_and_json_array_of_pet/content/application_json/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/responses/response_successful_xml_and_json_array_of_pet/content/application_json/schema.py @@ -11,17 +11,16 @@ from petstore_api.shared_imports.schema_imports import * + class Schema( schemas.ListSchema[schemas.T] ): - class Schema_: - types = {tuple} - - @staticmethod - def items() -> typing.Type[ref_pet.RefPet]: - return ref_pet.RefPet + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[ref_pet.RefPet] = dataclasses.field(default_factory=lambda: ref_pet.RefPet) # type: ignore def __new__( cls, @@ -48,4 +47,5 @@ def __new__( def __getitem__(self, name: int) -> ref_pet.RefPet[frozendict.frozendict]: return super().__getitem__(name) + from petstore_api.components.schema import ref_pet diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/responses/response_successful_xml_and_json_array_of_pet/content/application_xml/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/responses/response_successful_xml_and_json_array_of_pet/content/application_xml/schema.py index a9277849475..eb78d740ac9 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/responses/response_successful_xml_and_json_array_of_pet/content/application_xml/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/responses/response_successful_xml_and_json_array_of_pet/content/application_xml/schema.py @@ -11,17 +11,16 @@ from petstore_api.shared_imports.schema_imports import * + class Schema( schemas.ListSchema[schemas.T] ): - class Schema_: - types = {tuple} - - @staticmethod - def items() -> typing.Type[pet.Pet]: - return pet.Pet + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[pet.Pet] = dataclasses.field(default_factory=lambda: pet.Pet) # type: ignore def __new__( cls, @@ -48,4 +47,5 @@ def __new__( def __getitem__(self, name: int) -> pet.Pet[frozendict.frozendict]: return super().__getitem__(name) + from petstore_api.components.schema import pet diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/_200_response.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/_200_response.py index 04c09917ad2..3b3d5363c6d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/_200_response.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/_200_response.py @@ -10,6 +10,16 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Name: typing_extensions.TypeAlias = schemas.Int32Schema[U] +_Class: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "name": typing.Type[Name], + "class": typing.Type[_Class], + } +) + class _200Response( schemas.AnyTypeSchema[schemas.T], @@ -23,23 +33,17 @@ class _200Response( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class Properties: - Name: typing_extensions.TypeAlias = schemas.Int32Schema[U] - _Class: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "name": Name, - "class": _Class, - } + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["name"]) -> Schema_.Properties.Name[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["name"]) -> Name[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["class"]) -> Schema_.Properties._Class[str]: ... + def __getitem__(self, name: typing_extensions.Literal["class"]) -> _Class[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -66,50 +70,15 @@ def __getitem__( def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, name: typing.Union[ - Schema_.Properties.Name[decimal.Decimal], + Name[decimal.Decimal], schemas.Unset, decimal.Decimal, int ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> _200Response[ typing.Union[ frozendict.frozendict, @@ -145,3 +114,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/_return.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/_return.py index 214ad473f0c..74a44220c4a 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/_return.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/_return.py @@ -10,6 +10,14 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +_Return: typing_extensions.TypeAlias = schemas.Int32Schema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "return": typing.Type[_Return], + } +) + class _Return( schemas.AnyTypeSchema[schemas.T], @@ -23,18 +31,14 @@ class _Return( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class Properties: - _Return: typing_extensions.TypeAlias = schemas.Int32Schema[U] - __annotations__ = { - "return": _Return, - } + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["return"]) -> Schema_.Properties._Return[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["return"]) -> _Return[decimal.Decimal]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -60,44 +64,9 @@ def __getitem__( def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> _Return[ typing.Union[ frozendict.frozendict, @@ -132,3 +101,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/abstract_step_message.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/abstract_step_message.py index c5215da4bc5..6a6a4c1177a 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/abstract_step_message.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/abstract_step_message.py @@ -10,6 +10,14 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Discriminator: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "discriminator": typing.Type[Discriminator], + } +) + class AbstractStepMessage( schemas.DictSchema[schemas.T] @@ -23,38 +31,25 @@ class AbstractStepMessage( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ frozendict.frozendict, - } - required = { + }) + required: typing.FrozenSet[str] = frozenset({ "description", "discriminator", "sequenceNumber", - } - - @staticmethod - def discriminator(): - return { + }) + discriminator: typing.Mapping[str, typing.Mapping[str, typing.Type[schemas.Schema]]] = dataclasses.field( + default_factory=lambda: { 'discriminator': { 'AbstractStepMessage': AbstractStepMessage, } } - - class Properties: - Discriminator: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "discriminator": Discriminator, - } - - class AnyOf: - - @staticmethod - def _0() -> typing.Type[AbstractStepMessage]: - return AbstractStepMessage - classes = [ - _0, - ] + ) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + any_of: AnyOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AnyOf)) # type: ignore @property @@ -71,7 +66,7 @@ def description(self) -> schemas.AnyTypeSchema[typing.Union[ return self.__getitem__("description") @property - def discriminator(self) -> Schema_.Properties.Discriminator[str]: + def discriminator(self) -> Discriminator[str]: return self.__getitem__("discriminator") @property @@ -100,7 +95,7 @@ def __getitem__(self, name: typing_extensions.Literal["description"]) -> schemas ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["discriminator"]) -> Schema_.Properties.Discriminator[str]: ... + def __getitem__(self, name: typing_extensions.Literal["discriminator"]) -> Discriminator[str]: ... @typing.overload def __getitem__(self, name: typing_extensions.Literal["sequenceNumber"]) -> schemas.AnyTypeSchema[typing.Union[ @@ -170,7 +165,7 @@ def __new__( io.BufferedReader ], discriminator: typing.Union[ - Schema_.Properties.Discriminator[str], + Discriminator[str], str ], sequenceNumber: typing.Union[ @@ -202,25 +197,7 @@ def __new__( io.BufferedReader ], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> AbstractStepMessage[frozendict.frozendict]: inst = super().__new__( cls, @@ -236,3 +213,7 @@ def __new__( inst ) return inst + +AnyOf = typing.Tuple[ + typing.Type[AbstractStepMessage], +] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/additional_properties_class.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/additional_properties_class.py index adb7a45c29f..a8cc6180c62 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/additional_properties_class.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/additional_properties_class.py @@ -10,6 +10,268 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +AdditionalProperties: typing_extensions.TypeAlias = schemas.StrSchema[U] + + +class MapProperty( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore + + def __getitem__(self, name: str) -> AdditionalProperties[str]: + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: typing.Union[ + AdditionalProperties[str], + str + ], + ) -> MapProperty[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + MapProperty[frozendict.frozendict], + inst + ) + return inst + +AdditionalProperties3: typing_extensions.TypeAlias = schemas.StrSchema[U] + + +class AdditionalProperties2( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + additional_properties: typing.Type[AdditionalProperties3] = dataclasses.field(default_factory=lambda: AdditionalProperties3) # type: ignore + + def __getitem__(self, name: str) -> AdditionalProperties3[str]: + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: typing.Union[ + AdditionalProperties3[str], + str + ], + ) -> AdditionalProperties2[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + AdditionalProperties2[frozendict.frozendict], + inst + ) + return inst + + + +class MapOfMapProperty( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + additional_properties: typing.Type[AdditionalProperties2] = dataclasses.field(default_factory=lambda: AdditionalProperties2) # type: ignore + + def __getitem__(self, name: str) -> AdditionalProperties2[frozendict.frozendict]: + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: typing.Union[ + AdditionalProperties2[frozendict.frozendict], + dict, + frozendict.frozendict + ], + ) -> MapOfMapProperty[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + MapOfMapProperty[frozendict.frozendict], + inst + ) + return inst + +Anytype1: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] +MapWithUndeclaredPropertiesAnytype1: typing_extensions.TypeAlias = schemas.DictSchema[U] +MapWithUndeclaredPropertiesAnytype2: typing_extensions.TypeAlias = schemas.DictSchema[U] +AdditionalProperties4: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] + + +class MapWithUndeclaredPropertiesAnytype3( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + additional_properties: typing.Type[AdditionalProperties4] = dataclasses.field(default_factory=lambda: AdditionalProperties4) # type: ignore + + def __getitem__(self, name: str) -> AdditionalProperties4[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: typing.Union[ + AdditionalProperties4[ + schemas.INPUT_BASE_TYPES + ], + dict, + frozendict.frozendict, + str, + datetime.date, + datetime.datetime, + uuid.UUID, + int, + float, + decimal.Decimal, + bool, + None, + list, + tuple, + bytes, + io.FileIO, + io.BufferedReader + ], + ) -> MapWithUndeclaredPropertiesAnytype3[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + MapWithUndeclaredPropertiesAnytype3[frozendict.frozendict], + inst + ) + return inst + +AdditionalProperties5: typing_extensions.TypeAlias = schemas.NotAnyTypeSchema[U] + + +class EmptyMap( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + additional_properties: typing.Type[AdditionalProperties5] = dataclasses.field(default_factory=lambda: AdditionalProperties5) # type: ignore + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> EmptyMap[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + ) + inst = typing.cast( + EmptyMap[frozendict.frozendict], + inst + ) + return inst + +AdditionalProperties6: typing_extensions.TypeAlias = schemas.StrSchema[U] + + +class MapWithUndeclaredPropertiesString( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + additional_properties: typing.Type[AdditionalProperties6] = dataclasses.field(default_factory=lambda: AdditionalProperties6) # type: ignore + + def __getitem__(self, name: str) -> AdditionalProperties6[str]: + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: typing.Union[ + AdditionalProperties6[str], + str + ], + ) -> MapWithUndeclaredPropertiesString[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + MapWithUndeclaredPropertiesString[frozendict.frozendict], + inst + ) + return inst + +Properties = typing_extensions.TypedDict( + 'Properties', + { + "map_property": typing.Type[MapProperty], + "map_of_map_property": typing.Type[MapOfMapProperty], + "anytype_1": typing.Type[Anytype1], + "map_with_undeclared_properties_anytype_1": typing.Type[MapWithUndeclaredPropertiesAnytype1], + "map_with_undeclared_properties_anytype_2": typing.Type[MapWithUndeclaredPropertiesAnytype2], + "map_with_undeclared_properties_anytype_3": typing.Type[MapWithUndeclaredPropertiesAnytype3], + "empty_map": typing.Type[EmptyMap], + "map_with_undeclared_properties_string": typing.Type[MapWithUndeclaredPropertiesString], + } +) + class AdditionalPropertiesClass( schemas.DictSchema[schemas.T] @@ -21,266 +283,19 @@ class AdditionalPropertiesClass( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - - class MapProperty( - schemas.DictSchema[schemas.T] - ): - - - class Schema_: - types = {frozendict.frozendict} - AdditionalProperties: typing_extensions.TypeAlias = schemas.StrSchema[U] - - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[str]: - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[dict, frozendict.frozendict], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - Schema_.AdditionalProperties[str], - str - ], - ) -> AdditionalPropertiesClass.Schema_.Properties.MapProperty[frozendict.frozendict]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AdditionalPropertiesClass.Schema_.Properties.MapProperty[frozendict.frozendict], - inst - ) - return inst - - - class MapOfMapProperty( - schemas.DictSchema[schemas.T] - ): - - - class Schema_: - types = {frozendict.frozendict} - - - class AdditionalProperties( - schemas.DictSchema[schemas.T] - ): - - - class Schema_: - types = {frozendict.frozendict} - AdditionalProperties: typing_extensions.TypeAlias = schemas.StrSchema[U] - - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[str]: - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[dict, frozendict.frozendict], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - Schema_.AdditionalProperties[str], - str - ], - ) -> AdditionalPropertiesClass.Schema_.Properties.MapOfMapProperty.Schema_.AdditionalProperties[frozendict.frozendict]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AdditionalPropertiesClass.Schema_.Properties.MapOfMapProperty.Schema_.AdditionalProperties[frozendict.frozendict], - inst - ) - return inst - - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[frozendict.frozendict]: - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[dict, frozendict.frozendict], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - Schema_.AdditionalProperties[frozendict.frozendict], - dict, - frozendict.frozendict - ], - ) -> AdditionalPropertiesClass.Schema_.Properties.MapOfMapProperty[frozendict.frozendict]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AdditionalPropertiesClass.Schema_.Properties.MapOfMapProperty[frozendict.frozendict], - inst - ) - return inst - Anytype1: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - MapWithUndeclaredPropertiesAnytype1: typing_extensions.TypeAlias = schemas.DictSchema[U] - MapWithUndeclaredPropertiesAnytype2: typing_extensions.TypeAlias = schemas.DictSchema[U] - - - class MapWithUndeclaredPropertiesAnytype3( - schemas.DictSchema[schemas.T] - ): - - - class Schema_: - types = {frozendict.frozendict} - AdditionalProperties: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[dict, frozendict.frozendict], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - Schema_.AdditionalProperties[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - ) -> AdditionalPropertiesClass.Schema_.Properties.MapWithUndeclaredPropertiesAnytype3[frozendict.frozendict]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AdditionalPropertiesClass.Schema_.Properties.MapWithUndeclaredPropertiesAnytype3[frozendict.frozendict], - inst - ) - return inst - - - class EmptyMap( - schemas.DictSchema[schemas.T] - ): - - - class Schema_: - types = {frozendict.frozendict} - AdditionalProperties: typing_extensions.TypeAlias = schemas.NotAnyTypeSchema[U] - - def __new__( - cls, - *args_: typing.Union[dict, frozendict.frozendict], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> AdditionalPropertiesClass.Schema_.Properties.EmptyMap[frozendict.frozendict]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - ) - inst = typing.cast( - AdditionalPropertiesClass.Schema_.Properties.EmptyMap[frozendict.frozendict], - inst - ) - return inst - - - class MapWithUndeclaredPropertiesString( - schemas.DictSchema[schemas.T] - ): - - - class Schema_: - types = {frozendict.frozendict} - AdditionalProperties: typing_extensions.TypeAlias = schemas.StrSchema[U] - - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[str]: - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[dict, frozendict.frozendict], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - Schema_.AdditionalProperties[str], - str - ], - ) -> AdditionalPropertiesClass.Schema_.Properties.MapWithUndeclaredPropertiesString[frozendict.frozendict]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AdditionalPropertiesClass.Schema_.Properties.MapWithUndeclaredPropertiesString[frozendict.frozendict], - inst - ) - return inst - __annotations__ = { - "map_property": MapProperty, - "map_of_map_property": MapOfMapProperty, - "anytype_1": Anytype1, - "map_with_undeclared_properties_anytype_1": MapWithUndeclaredPropertiesAnytype1, - "map_with_undeclared_properties_anytype_2": MapWithUndeclaredPropertiesAnytype2, - "map_with_undeclared_properties_anytype_3": MapWithUndeclaredPropertiesAnytype3, - "empty_map": EmptyMap, - "map_with_undeclared_properties_string": MapWithUndeclaredPropertiesString, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["map_property"]) -> Schema_.Properties.MapProperty[frozendict.frozendict]: ... + def __getitem__(self, name: typing_extensions.Literal["map_property"]) -> MapProperty[frozendict.frozendict]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["map_of_map_property"]) -> Schema_.Properties.MapOfMapProperty[frozendict.frozendict]: ... + def __getitem__(self, name: typing_extensions.Literal["map_of_map_property"]) -> MapOfMapProperty[frozendict.frozendict]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["anytype_1"]) -> Schema_.Properties.Anytype1[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["anytype_1"]) -> Anytype1[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -292,19 +307,19 @@ def __getitem__(self, name: typing_extensions.Literal["anytype_1"]) -> Schema_.P ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["map_with_undeclared_properties_anytype_1"]) -> Schema_.Properties.MapWithUndeclaredPropertiesAnytype1[frozendict.frozendict]: ... + def __getitem__(self, name: typing_extensions.Literal["map_with_undeclared_properties_anytype_1"]) -> MapWithUndeclaredPropertiesAnytype1[frozendict.frozendict]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["map_with_undeclared_properties_anytype_2"]) -> Schema_.Properties.MapWithUndeclaredPropertiesAnytype2[frozendict.frozendict]: ... + def __getitem__(self, name: typing_extensions.Literal["map_with_undeclared_properties_anytype_2"]) -> MapWithUndeclaredPropertiesAnytype2[frozendict.frozendict]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["map_with_undeclared_properties_anytype_3"]) -> Schema_.Properties.MapWithUndeclaredPropertiesAnytype3[frozendict.frozendict]: ... + def __getitem__(self, name: typing_extensions.Literal["map_with_undeclared_properties_anytype_3"]) -> MapWithUndeclaredPropertiesAnytype3[frozendict.frozendict]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["empty_map"]) -> Schema_.Properties.EmptyMap[frozendict.frozendict]: ... + def __getitem__(self, name: typing_extensions.Literal["empty_map"]) -> EmptyMap[frozendict.frozendict]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["map_with_undeclared_properties_string"]) -> Schema_.Properties.MapWithUndeclaredPropertiesString[frozendict.frozendict]: ... + def __getitem__(self, name: typing_extensions.Literal["map_with_undeclared_properties_string"]) -> MapWithUndeclaredPropertiesString[frozendict.frozendict]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -339,28 +354,21 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], map_property: typing.Union[ - Schema_.Properties.MapProperty[frozendict.frozendict], + MapProperty[frozendict.frozendict], schemas.Unset, dict, frozendict.frozendict ] = schemas.unset, map_of_map_property: typing.Union[ - Schema_.Properties.MapOfMapProperty[frozendict.frozendict], + MapOfMapProperty[frozendict.frozendict], schemas.Unset, dict, frozendict.frozendict ] = schemas.unset, anytype_1: typing.Union[ - Schema_.Properties.Anytype1[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + Anytype1[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -380,55 +388,37 @@ def __new__( io.BufferedReader ] = schemas.unset, map_with_undeclared_properties_anytype_1: typing.Union[ - Schema_.Properties.MapWithUndeclaredPropertiesAnytype1[frozendict.frozendict], + MapWithUndeclaredPropertiesAnytype1[frozendict.frozendict], schemas.Unset, dict, frozendict.frozendict ] = schemas.unset, map_with_undeclared_properties_anytype_2: typing.Union[ - Schema_.Properties.MapWithUndeclaredPropertiesAnytype2[frozendict.frozendict], + MapWithUndeclaredPropertiesAnytype2[frozendict.frozendict], schemas.Unset, dict, frozendict.frozendict ] = schemas.unset, map_with_undeclared_properties_anytype_3: typing.Union[ - Schema_.Properties.MapWithUndeclaredPropertiesAnytype3[frozendict.frozendict], + MapWithUndeclaredPropertiesAnytype3[frozendict.frozendict], schemas.Unset, dict, frozendict.frozendict ] = schemas.unset, empty_map: typing.Union[ - Schema_.Properties.EmptyMap[frozendict.frozendict], + EmptyMap[frozendict.frozendict], schemas.Unset, dict, frozendict.frozendict ] = schemas.unset, map_with_undeclared_properties_string: typing.Union[ - Schema_.Properties.MapWithUndeclaredPropertiesString[frozendict.frozendict], + MapWithUndeclaredPropertiesString[frozendict.frozendict], schemas.Unset, dict, frozendict.frozendict ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> AdditionalPropertiesClass[frozendict.frozendict]: inst = super().__new__( cls, @@ -449,3 +439,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/additional_properties_validator.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/additional_properties_validator.py index 9970c8353c6..d9d3144bdde 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/additional_properties_validator.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/additional_properties_validator.py @@ -10,188 +10,109 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +AdditionalProperties: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] -class AdditionalPropertiesValidator( + +class _0( schemas.DictSchema[schemas.T] ): - """NOTE: This class is auto generated by OpenAPI JSON Schema Generator. - Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator - Do not edit the class manually. - """ + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore + + def __getitem__(self, name: str) -> AdditionalProperties[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: + # dict_instance[name] accessor + return super().__getitem__(name) - class Schema_: - types = { + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: typing.Union[ + AdditionalProperties[ + schemas.INPUT_BASE_TYPES + ], + dict, frozendict.frozendict, - } - - class AllOf: - - - class _0( - schemas.DictSchema[schemas.T] - ): - - - class Schema_: - types = {frozendict.frozendict} - AdditionalProperties: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[dict, frozendict.frozendict], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - Schema_.AdditionalProperties[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - ) -> AdditionalPropertiesValidator.Schema_.AllOf._0[frozendict.frozendict]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AdditionalPropertiesValidator.Schema_.AllOf._0[frozendict.frozendict], - inst - ) - return inst - - - class _1( - schemas.DictSchema[schemas.T] - ): - - - class Schema_: - types = {frozendict.frozendict} - - - class AdditionalProperties( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - min_length = 3 - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> AdditionalPropertiesValidator.Schema_.AllOf._1.Schema_.AdditionalProperties[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AdditionalPropertiesValidator.Schema_.AllOf._1.Schema_.AdditionalProperties[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[typing.Union[ + str, + datetime.date, + datetime.datetime, + uuid.UUID, + int, + float, + decimal.Decimal, + bool, + None, + list, + tuple, + bytes, + io.FileIO, + io.BufferedReader + ], + ) -> _0[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _0[frozendict.frozendict], + inst + ) + return inst + + + +class AdditionalProperties2( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + min_length: int = 3 + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> AdditionalProperties2[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + AdditionalProperties2[ + typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -200,151 +121,114 @@ def __getitem__(self, name: str) -> Schema_.AdditionalProperties[typing.Union[ tuple, bytes, schemas.FileIO - ]]: - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[dict, frozendict.frozendict], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - Schema_.AdditionalProperties[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - ) -> AdditionalPropertiesValidator.Schema_.AllOf._1[frozendict.frozendict]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AdditionalPropertiesValidator.Schema_.AllOf._1[frozendict.frozendict], - inst - ) - return inst - - - class _2( - schemas.DictSchema[schemas.T] - ): - - - class Schema_: - types = {frozendict.frozendict} - - - class AdditionalProperties( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - max_length = 5 - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> AdditionalPropertiesValidator.Schema_.AllOf._2.Schema_.AdditionalProperties[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AdditionalPropertiesValidator.Schema_.AllOf._2.Schema_.AdditionalProperties[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[typing.Union[ + ] + ], + inst + ) + return inst + + + +class _1( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + additional_properties: typing.Type[AdditionalProperties2] = dataclasses.field(default_factory=lambda: AdditionalProperties2) # type: ignore + + def __getitem__(self, name: str) -> AdditionalProperties2[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: typing.Union[ + AdditionalProperties2[ + schemas.INPUT_BASE_TYPES + ], + dict, + frozendict.frozendict, + str, + datetime.date, + datetime.datetime, + uuid.UUID, + int, + float, + decimal.Decimal, + bool, + None, + list, + tuple, + bytes, + io.FileIO, + io.BufferedReader + ], + ) -> _1[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _1[frozendict.frozendict], + inst + ) + return inst + + + +class AdditionalProperties3( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + max_length: int = 5 + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> AdditionalProperties3[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + AdditionalProperties3[ + typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -353,84 +237,105 @@ def __getitem__(self, name: str) -> Schema_.AdditionalProperties[typing.Union[ tuple, bytes, schemas.FileIO - ]]: - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[dict, frozendict.frozendict], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - Schema_.AdditionalProperties[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - ) -> AdditionalPropertiesValidator.Schema_.AllOf._2[frozendict.frozendict]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AdditionalPropertiesValidator.Schema_.AllOf._2[frozendict.frozendict], - inst - ) - return inst - classes = [ - _0, - _1, - _2, - ] + ] + ], + inst + ) + return inst + +class _2( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + additional_properties: typing.Type[AdditionalProperties3] = dataclasses.field(default_factory=lambda: AdditionalProperties3) # type: ignore + + def __getitem__(self, name: str) -> AdditionalProperties3[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: + # dict_instance[name] accessor + return super().__getitem__(name) + def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, **kwargs: typing.Union[ + AdditionalProperties3[ + schemas.INPUT_BASE_TYPES + ], dict, frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, str, datetime.date, datetime.datetime, uuid.UUID, + int, + float, + decimal.Decimal, bool, None, + list, + tuple, bytes, io.FileIO, - io.BufferedReader, - schemas.Schema + io.BufferedReader ], + ) -> _2[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _2[frozendict.frozendict], + inst + ) + return inst + +AllOf = typing.Tuple[ + typing.Type[_0[schemas.U]], + typing.Type[_1[schemas.U]], + typing.Type[_2[schemas.U]], +] + + +class AdditionalPropertiesValidator( + schemas.DictSchema[schemas.T] +): + """NOTE: This class is auto generated by OpenAPI JSON Schema Generator. + Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator + + Do not edit the class manually. + """ + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + frozendict.frozendict, + }) + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore + + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> AdditionalPropertiesValidator[frozendict.frozendict]: inst = super().__new__( cls, @@ -443,3 +348,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/additional_properties_with_array_of_enums.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/additional_properties_with_array_of_enums.py index d74a9ac6d23..3bac9db3dca 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/additional_properties_with_array_of_enums.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/additional_properties_with_array_of_enums.py @@ -11,6 +11,43 @@ from petstore_api.shared_imports.schema_imports import * + +class AdditionalProperties( + schemas.ListSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[enum_class.EnumClass] = dataclasses.field(default_factory=lambda: enum_class.EnumClass) # type: ignore + + def __new__( + cls, + arg_: typing.Sequence[ + typing.Union[ + enum_class.EnumClass[str], + str + ] + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> AdditionalProperties[tuple]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + AdditionalProperties[tuple], + inst + ) + return inst + + def __getitem__(self, name: int) -> enum_class.EnumClass[str]: + return super().__getitem__(name) + + + class AdditionalPropertiesWithArrayOfEnums( schemas.DictSchema[schemas.T] ): @@ -21,47 +58,12 @@ class AdditionalPropertiesWithArrayOfEnums( """ - class Schema_: - types = {frozendict.frozendict} - - - class AdditionalProperties( - schemas.ListSchema[schemas.T] - ): - - - class Schema_: - types = {tuple} - - @staticmethod - def items() -> typing.Type[enum_class.EnumClass]: - return enum_class.EnumClass - - def __new__( - cls, - arg_: typing.Sequence[ - typing.Union[ - enum_class.EnumClass[str], - str - ] - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> AdditionalPropertiesWithArrayOfEnums.Schema_.AdditionalProperties[tuple]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - AdditionalPropertiesWithArrayOfEnums.Schema_.AdditionalProperties[tuple], - inst - ) - return inst - - def __getitem__(self, name: int) -> enum_class.EnumClass[str]: - return super().__getitem__(name) + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[tuple]: + def __getitem__(self, name: str) -> AdditionalProperties[tuple]: # dict_instance[name] accessor return super().__getitem__(name) @@ -70,7 +72,7 @@ def __new__( *args_: typing.Union[dict, frozendict.frozendict], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, **kwargs: typing.Union[ - Schema_.AdditionalProperties[tuple], + AdditionalProperties[tuple], list, tuple ], @@ -87,4 +89,5 @@ def __new__( ) return inst + from petstore_api.components.schema import enum_class diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/address.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/address.py index 5b8b02658fc..c83165420fb 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/address.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/address.py @@ -10,6 +10,8 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +AdditionalProperties: typing_extensions.TypeAlias = schemas.IntSchema[U] + class Address( schemas.DictSchema[schemas.T] @@ -21,11 +23,12 @@ class Address( """ - class Schema_: - types = {frozendict.frozendict} - AdditionalProperties: typing_extensions.TypeAlias = schemas.IntSchema[U] + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[decimal.Decimal]: + def __getitem__(self, name: str) -> AdditionalProperties[decimal.Decimal]: # dict_instance[name] accessor return super().__getitem__(name) @@ -34,7 +37,7 @@ def __new__( *args_: typing.Union[dict, frozendict.frozendict], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, **kwargs: typing.Union[ - Schema_.AdditionalProperties[decimal.Decimal], + AdditionalProperties[decimal.Decimal], decimal.Decimal, int ], @@ -50,3 +53,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/animal.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/animal.py index a8fa24bc5e2..2128bb708fb 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/animal.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/animal.py @@ -10,6 +10,28 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +ClassName: typing_extensions.TypeAlias = schemas.StrSchema[U] + + +class Color( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + default: str = "red" +Properties = typing_extensions.TypedDict( + 'Properties', + { + "className": typing.Type[ClassName], + "color": typing.Type[Color], + } +) + class Animal( schemas.DictSchema[schemas.T] @@ -21,49 +43,31 @@ class Animal( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "className", - } - - @staticmethod - def discriminator(): - return { + }) + discriminator: typing.Mapping[str, typing.Mapping[str, typing.Type[schemas.Schema]]] = dataclasses.field( + default_factory=lambda: { 'className': { 'Cat': cat.Cat, 'Dog': dog.Dog, } } - - class Properties: - ClassName: typing_extensions.TypeAlias = schemas.StrSchema[U] - - - class Color( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - default = "red" - __annotations__ = { - "className": ClassName, - "color": Color, - } + ) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @property - def className(self) -> Schema_.Properties.ClassName[str]: + def className(self) -> ClassName[str]: return self.__getitem__("className") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["className"]) -> Schema_.Properties.ClassName[str]: ... + def __getitem__(self, name: typing_extensions.Literal["className"]) -> ClassName[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["color"]) -> Schema_.Properties.Color[str]: ... + def __getitem__(self, name: typing_extensions.Literal["color"]) -> Color[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -92,34 +96,16 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], className: typing.Union[ - Schema_.Properties.ClassName[str], + ClassName[str], str ], color: typing.Union[ - Schema_.Properties.Color[str], + Color[str], schemas.Unset, str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Animal[frozendict.frozendict]: inst = super().__new__( cls, @@ -135,5 +121,6 @@ def __new__( ) return inst + from petstore_api.components.schema import cat from petstore_api.components.schema import dog diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/animal_farm.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/animal_farm.py index e85cf9f254a..aeedce0d9a9 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/animal_farm.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/animal_farm.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class AnimalFarm( schemas.ListSchema[schemas.T] ): @@ -21,12 +22,10 @@ class AnimalFarm( """ - class Schema_: - types = {tuple} - - @staticmethod - def items() -> typing.Type[animal.Animal]: - return animal.Animal + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[animal.Animal] = dataclasses.field(default_factory=lambda: animal.Animal) # type: ignore def __new__( cls, @@ -53,4 +52,5 @@ def __new__( def __getitem__(self, name: int) -> animal.Animal[frozendict.frozendict]: return super().__getitem__(name) + from petstore_api.components.schema import animal diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/any_type_and_format.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/any_type_and_format.py index 5bf7aaafe36..cbbaa77c621 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/any_type_and_format.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/any_type_and_format.py @@ -11,6 +11,502 @@ from petstore_api.shared_imports.schema_imports import * + +class Uuid( + schemas.UUIDBase, + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + format: str = 'uuid' + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> Uuid[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + Uuid[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + + + +class Date( + schemas.DateBase, + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + format: str = 'date' + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> Date[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + Date[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + + + +class DateTime( + schemas.DateTimeBase, + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + format: str = 'date-time' + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> DateTime[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + DateTime[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + + + +class Number( + schemas.DecimalBase, + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + format: str = 'number' + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> Number[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + Number[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + + + +class Binary( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + format: str = 'binary' + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> Binary[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + Binary[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + + + +class Int32( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + format: str = 'int32' + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> Int32[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + Int32[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + + + +class Int64( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + format: str = 'int64' + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> Int64[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + Int64[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + + + +class Double( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + format: str = 'double' + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> Double[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + Double[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + + + +class _Float( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + format: str = 'float' + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _Float[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _Float[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + +Properties = typing_extensions.TypedDict( + 'Properties', + { + "uuid": typing.Type[Uuid], + "date": typing.Type[Date], + "date-time": typing.Type[DateTime], + "number": typing.Type[Number], + "binary": typing.Type[Binary], + "int32": typing.Type[Int32], + "int64": typing.Type[Int64], + "double": typing.Type[Double], + "float": typing.Type[_Float], + } +) + + class AnyTypeAndFormat( schemas.DictSchema[schemas.T] ): @@ -21,802 +517,13 @@ class AnyTypeAndFormat( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - - class Uuid( - schemas.UUIDBase, - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - format = 'uuid' - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> AnyTypeAndFormat.Schema_.Properties.Uuid[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AnyTypeAndFormat.Schema_.Properties.Uuid[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - - - class Date( - schemas.DateBase, - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - format = 'date' - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> AnyTypeAndFormat.Schema_.Properties.Date[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AnyTypeAndFormat.Schema_.Properties.Date[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - - - class DateTime( - schemas.DateTimeBase, - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - format = 'date-time' - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> AnyTypeAndFormat.Schema_.Properties.DateTime[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AnyTypeAndFormat.Schema_.Properties.DateTime[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - - - class Number( - schemas.DecimalBase, - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - format = 'number' - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> AnyTypeAndFormat.Schema_.Properties.Number[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AnyTypeAndFormat.Schema_.Properties.Number[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - - - class Binary( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - format = 'binary' - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> AnyTypeAndFormat.Schema_.Properties.Binary[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AnyTypeAndFormat.Schema_.Properties.Binary[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - - - class Int32( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - format = 'int32' - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> AnyTypeAndFormat.Schema_.Properties.Int32[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AnyTypeAndFormat.Schema_.Properties.Int32[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - - - class Int64( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - format = 'int64' - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> AnyTypeAndFormat.Schema_.Properties.Int64[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AnyTypeAndFormat.Schema_.Properties.Int64[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - - - class Double( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - format = 'double' - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> AnyTypeAndFormat.Schema_.Properties.Double[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AnyTypeAndFormat.Schema_.Properties.Double[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - - - class _Float( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - format = 'float' - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> AnyTypeAndFormat.Schema_.Properties._Float[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - AnyTypeAndFormat.Schema_.Properties._Float[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - __annotations__ = { - "uuid": Uuid, - "date": Date, - "date-time": DateTime, - "number": Number, - "binary": Binary, - "int32": Int32, - "int64": Int64, - "double": Double, - "float": _Float, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["uuid"]) -> Schema_.Properties.Uuid[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["uuid"]) -> Uuid[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -828,7 +535,7 @@ def __getitem__(self, name: typing_extensions.Literal["uuid"]) -> Schema_.Proper ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["date"]) -> Schema_.Properties.Date[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["date"]) -> Date[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -840,7 +547,7 @@ def __getitem__(self, name: typing_extensions.Literal["date"]) -> Schema_.Proper ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["date-time"]) -> Schema_.Properties.DateTime[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["date-time"]) -> DateTime[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -852,7 +559,7 @@ def __getitem__(self, name: typing_extensions.Literal["date-time"]) -> Schema_.P ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["number"]) -> Schema_.Properties.Number[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["number"]) -> Number[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -864,7 +571,7 @@ def __getitem__(self, name: typing_extensions.Literal["number"]) -> Schema_.Prop ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["binary"]) -> Schema_.Properties.Binary[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["binary"]) -> Binary[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -876,7 +583,7 @@ def __getitem__(self, name: typing_extensions.Literal["binary"]) -> Schema_.Prop ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["int32"]) -> Schema_.Properties.Int32[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["int32"]) -> Int32[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -888,7 +595,7 @@ def __getitem__(self, name: typing_extensions.Literal["int32"]) -> Schema_.Prope ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["int64"]) -> Schema_.Properties.Int64[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["int64"]) -> Int64[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -900,7 +607,7 @@ def __getitem__(self, name: typing_extensions.Literal["int64"]) -> Schema_.Prope ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["double"]) -> Schema_.Properties.Double[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["double"]) -> Double[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -912,7 +619,7 @@ def __getitem__(self, name: typing_extensions.Literal["double"]) -> Schema_.Prop ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["float"]) -> Schema_.Properties._Float[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["float"]) -> _Float[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -957,16 +664,9 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], uuid: typing.Union[ - Schema_.Properties.Uuid[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + Uuid[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -986,16 +686,9 @@ def __new__( io.BufferedReader ] = schemas.unset, date: typing.Union[ - Schema_.Properties.Date[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + Date[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -1015,16 +708,9 @@ def __new__( io.BufferedReader ] = schemas.unset, number: typing.Union[ - Schema_.Properties.Number[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + Number[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -1044,16 +730,9 @@ def __new__( io.BufferedReader ] = schemas.unset, binary: typing.Union[ - Schema_.Properties.Binary[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + Binary[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -1073,16 +752,9 @@ def __new__( io.BufferedReader ] = schemas.unset, int32: typing.Union[ - Schema_.Properties.Int32[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + Int32[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -1102,16 +774,9 @@ def __new__( io.BufferedReader ] = schemas.unset, int64: typing.Union[ - Schema_.Properties.Int64[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + Int64[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -1131,16 +796,9 @@ def __new__( io.BufferedReader ] = schemas.unset, double: typing.Union[ - Schema_.Properties.Double[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + Double[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -1160,25 +818,7 @@ def __new__( io.BufferedReader ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> AnyTypeAndFormat[frozendict.frozendict]: inst = super().__new__( cls, @@ -1198,3 +838,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/any_type_not_string.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/any_type_not_string.py index db81e53f39c..3210beb3c3e 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/any_type_not_string.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/any_type_not_string.py @@ -10,6 +10,8 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +_Not: typing_extensions.TypeAlias = schemas.StrSchema[U] + class AnyTypeNotString( schemas.AnyTypeSchema[schemas.T], @@ -21,51 +23,17 @@ class AnyTypeNotString( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - _Not: typing_extensions.TypeAlias = schemas.StrSchema[U] + not_: typing.Type[_Not] = dataclasses.field(default_factory=lambda: _Not) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> AnyTypeNotString[ typing.Union[ frozendict.frozendict, @@ -100,3 +68,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/api_response.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/api_response.py index 85f679d09b8..551caf1e7c8 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/api_response.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/api_response.py @@ -10,6 +10,18 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Code: typing_extensions.TypeAlias = schemas.Int32Schema[U] +Type: typing_extensions.TypeAlias = schemas.StrSchema[U] +Message: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "code": typing.Type[Code], + "type": typing.Type[Type], + "message": typing.Type[Message], + } +) + class ApiResponse( schemas.DictSchema[schemas.T] @@ -21,27 +33,19 @@ class ApiResponse( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - Code: typing_extensions.TypeAlias = schemas.Int32Schema[U] - Type: typing_extensions.TypeAlias = schemas.StrSchema[U] - Message: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "code": Code, - "type": Type, - "message": Message, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["code"]) -> Schema_.Properties.Code[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["code"]) -> Code[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["type"]) -> Schema_.Properties.Type[str]: ... + def __getitem__(self, name: typing_extensions.Literal["type"]) -> Type[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["message"]) -> Schema_.Properties.Message[str]: ... + def __getitem__(self, name: typing_extensions.Literal["message"]) -> Message[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -71,41 +75,23 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], code: typing.Union[ - Schema_.Properties.Code[decimal.Decimal], + Code[decimal.Decimal], schemas.Unset, decimal.Decimal, int ] = schemas.unset, type: typing.Union[ - Schema_.Properties.Type[str], + Type[str], schemas.Unset, str ] = schemas.unset, message: typing.Union[ - Schema_.Properties.Message[str], + Message[str], schemas.Unset, str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ApiResponse[frozendict.frozendict]: inst = super().__new__( cls, @@ -121,3 +107,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/apple.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/apple.py index 9563f71c04d..afc3a527f33 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/apple.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/apple.py @@ -11,6 +11,45 @@ from petstore_api.shared_imports.schema_imports import * + +class Cultivar( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + pattern: schemas.PatternInfo = schemas.PatternInfo( + pattern=r'^[a-zA-Z\s]*$' # noqa: E501 + ) + + +class Origin( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + pattern: schemas.PatternInfo = schemas.PatternInfo( + pattern=r'^[A-Z\s]*$', # noqa: E501 + flags=re.I, + ) +Properties = typing_extensions.TypedDict( + 'Properties', + { + "cultivar": typing.Type[Cultivar], + "origin": typing.Type[Origin], + } +) + + class Apple( schemas.NoneBase, schemas.DictBase, @@ -24,60 +63,27 @@ class Apple( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ schemas.NoneClass, frozendict.frozendict, - } - required = { + }) + required: typing.FrozenSet[str] = frozenset({ "cultivar", - } - - class Properties: - - - class Cultivar( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - regex={ - 'pattern': r'^[a-zA-Z\s]*$', # noqa: E501 - } - - - class Origin( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - regex={ - 'pattern': r'^[A-Z\s]*$', # noqa: E501 - 'flags': re.I, - } - __annotations__ = { - "cultivar": Cultivar, - "origin": Origin, - } + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @property - def cultivar(self) -> Schema_.Properties.Cultivar[str]: + def cultivar(self) -> Cultivar[str]: return self.__getitem__("cultivar") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["cultivar"]) -> Schema_.Properties.Cultivar[str]: ... + def __getitem__(self, name: typing_extensions.Literal["cultivar"]) -> Cultivar[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["origin"]) -> Schema_.Properties.Origin[str]: ... + def __getitem__(self, name: typing_extensions.Literal["origin"]) -> Origin[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -110,30 +116,12 @@ def __new__( frozendict.frozendict ], origin: typing.Union[ - Schema_.Properties.Origin[str], + Origin[str], schemas.Unset, str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Apple[ typing.Union[ schemas.NoneClass, @@ -157,3 +145,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/apple_req.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/apple_req.py index 56858d46e7c..90f0c4a5fef 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/apple_req.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/apple_req.py @@ -10,6 +10,17 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +AdditionalProperties: typing_extensions.TypeAlias = schemas.NotAnyTypeSchema[U] +Cultivar: typing_extensions.TypeAlias = schemas.StrSchema[U] +Mealy: typing_extensions.TypeAlias = schemas.BoolSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "cultivar": typing.Type[Cultivar], + "mealy": typing.Type[Mealy], + } +) + class AppleReq( schemas.DictSchema[schemas.T] @@ -21,30 +32,24 @@ class AppleReq( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "cultivar", - } - - class Properties: - Cultivar: typing_extensions.TypeAlias = schemas.StrSchema[U] - Mealy: typing_extensions.TypeAlias = schemas.BoolSchema[U] - __annotations__ = { - "cultivar": Cultivar, - "mealy": Mealy, - } - AdditionalProperties: typing_extensions.TypeAlias = schemas.NotAnyTypeSchema[U] + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore @property - def cultivar(self) -> Schema_.Properties.Cultivar[str]: + def cultivar(self) -> Cultivar[str]: return self.__getitem__("cultivar") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["cultivar"]) -> Schema_.Properties.Cultivar[str]: ... + def __getitem__(self, name: typing_extensions.Literal["cultivar"]) -> Cultivar[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["mealy"]) -> Schema_.Properties.Mealy[schemas.BoolClass]: ... + def __getitem__(self, name: typing_extensions.Literal["mealy"]) -> Mealy[schemas.BoolClass]: ... def __getitem__( self, @@ -60,11 +65,11 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], cultivar: typing.Union[ - Schema_.Properties.Cultivar[str], + Cultivar[str], str ], mealy: typing.Union[ - Schema_.Properties.Mealy[schemas.BoolClass], + Mealy[schemas.BoolClass], schemas.Unset, bool ] = schemas.unset, @@ -82,3 +87,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/array_holding_any_type.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/array_holding_any_type.py index 1ecb36b4793..bb57f60db29 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/array_holding_any_type.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/array_holding_any_type.py @@ -10,6 +10,8 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Items: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] + class ArrayHoldingAnyType( schemas.ListSchema[schemas.T] @@ -21,24 +23,18 @@ class ArrayHoldingAnyType( """ - class Schema_: - types = {tuple} - Items: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore def __new__( cls, arg_: typing.Sequence[ typing.Union[ - Schema_.Items[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + Items[ + schemas.INPUT_BASE_TYPES + ], dict, frozendict.frozendict, str, @@ -70,7 +66,7 @@ def __new__( ) return inst - def __getitem__(self, name: int) -> Schema_.Items[typing.Union[ + def __getitem__(self, name: int) -> Items[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -81,3 +77,4 @@ def __getitem__(self, name: int) -> Schema_.Items[typing.Union[ schemas.FileIO ]]: return super().__getitem__(name) + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/array_of_array_of_number_only.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/array_of_array_of_number_only.py index 7687d5d484d..bd35129454c 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/array_of_array_of_number_only.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/array_of_array_of_number_only.py @@ -10,6 +10,89 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Items2: typing_extensions.TypeAlias = schemas.NumberSchema[U] + + +class Items( + schemas.ListSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items2] = dataclasses.field(default_factory=lambda: Items2) # type: ignore + + def __new__( + cls, + arg_: typing.Sequence[ + typing.Union[ + Items2[decimal.Decimal], + decimal.Decimal, + int, + float + ] + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> Items[tuple]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + Items[tuple], + inst + ) + return inst + + def __getitem__(self, name: int) -> Items2[decimal.Decimal]: + return super().__getitem__(name) + + + +class ArrayArrayNumber( + schemas.ListSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore + + def __new__( + cls, + arg_: typing.Sequence[ + typing.Union[ + Items[tuple], + list, + tuple + ] + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> ArrayArrayNumber[tuple]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + ArrayArrayNumber[tuple], + inst + ) + return inst + + def __getitem__(self, name: int) -> Items[tuple]: + return super().__getitem__(name) + +Properties = typing_extensions.TypedDict( + 'Properties', + { + "ArrayArrayNumber": typing.Type[ArrayArrayNumber], + } +) + class ArrayOfArrayOfNumberOnly( schemas.DictSchema[schemas.T] @@ -21,86 +104,13 @@ class ArrayOfArrayOfNumberOnly( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - - class ArrayArrayNumber( - schemas.ListSchema[schemas.T] - ): - - - class Schema_: - types = {tuple} - - - class Items( - schemas.ListSchema[schemas.T] - ): - - - class Schema_: - types = {tuple} - Items: typing_extensions.TypeAlias = schemas.NumberSchema[U] - - def __new__( - cls, - arg_: typing.Sequence[ - typing.Union[ - Schema_.Items[decimal.Decimal], - decimal.Decimal, - int, - float - ] - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> ArrayOfArrayOfNumberOnly.Schema_.Properties.ArrayArrayNumber.Schema_.Items[tuple]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - ArrayOfArrayOfNumberOnly.Schema_.Properties.ArrayArrayNumber.Schema_.Items[tuple], - inst - ) - return inst - - def __getitem__(self, name: int) -> Schema_.Items[decimal.Decimal]: - return super().__getitem__(name) - - def __new__( - cls, - arg_: typing.Sequence[ - typing.Union[ - Schema_.Items[tuple], - list, - tuple - ] - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> ArrayOfArrayOfNumberOnly.Schema_.Properties.ArrayArrayNumber[tuple]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - ArrayOfArrayOfNumberOnly.Schema_.Properties.ArrayArrayNumber[tuple], - inst - ) - return inst - - def __getitem__(self, name: int) -> Schema_.Items[tuple]: - return super().__getitem__(name) - __annotations__ = { - "ArrayArrayNumber": ArrayArrayNumber, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["ArrayArrayNumber"]) -> Schema_.Properties.ArrayArrayNumber[tuple]: ... + def __getitem__(self, name: typing_extensions.Literal["ArrayArrayNumber"]) -> ArrayArrayNumber[tuple]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -128,31 +138,13 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], ArrayArrayNumber: typing.Union[ - Schema_.Properties.ArrayArrayNumber[tuple], + ArrayArrayNumber[tuple], schemas.Unset, list, tuple ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ArrayOfArrayOfNumberOnly[frozendict.frozendict]: inst = super().__new__( cls, @@ -166,3 +158,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/array_of_enums.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/array_of_enums.py index bbffd4a0c55..58f15a368ca 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/array_of_enums.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/array_of_enums.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class ArrayOfEnums( schemas.ListSchema[schemas.T] ): @@ -21,12 +22,10 @@ class ArrayOfEnums( """ - class Schema_: - types = {tuple} - - @staticmethod - def items() -> typing.Type[string_enum.StringEnum]: - return string_enum.StringEnum + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[string_enum.StringEnum] = dataclasses.field(default_factory=lambda: string_enum.StringEnum) # type: ignore def __new__( cls, @@ -59,4 +58,5 @@ def __getitem__(self, name: int) -> string_enum.StringEnum[typing.Union[ ]]: return super().__getitem__(name) + from petstore_api.components.schema import string_enum diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/array_of_number_only.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/array_of_number_only.py index e6c70ced7d4..82c6f0c1a18 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/array_of_number_only.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/array_of_number_only.py @@ -10,6 +10,52 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Items: typing_extensions.TypeAlias = schemas.NumberSchema[U] + + +class ArrayNumber( + schemas.ListSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore + + def __new__( + cls, + arg_: typing.Sequence[ + typing.Union[ + Items[decimal.Decimal], + decimal.Decimal, + int, + float + ] + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> ArrayNumber[tuple]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + ArrayNumber[tuple], + inst + ) + return inst + + def __getitem__(self, name: int) -> Items[decimal.Decimal]: + return super().__getitem__(name) + +Properties = typing_extensions.TypedDict( + 'Properties', + { + "ArrayNumber": typing.Type[ArrayNumber], + } +) + class ArrayOfNumberOnly( schemas.DictSchema[schemas.T] @@ -21,52 +67,13 @@ class ArrayOfNumberOnly( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - - class ArrayNumber( - schemas.ListSchema[schemas.T] - ): - - - class Schema_: - types = {tuple} - Items: typing_extensions.TypeAlias = schemas.NumberSchema[U] - - def __new__( - cls, - arg_: typing.Sequence[ - typing.Union[ - Schema_.Items[decimal.Decimal], - decimal.Decimal, - int, - float - ] - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> ArrayOfNumberOnly.Schema_.Properties.ArrayNumber[tuple]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - ArrayOfNumberOnly.Schema_.Properties.ArrayNumber[tuple], - inst - ) - return inst - - def __getitem__(self, name: int) -> Schema_.Items[decimal.Decimal]: - return super().__getitem__(name) - __annotations__ = { - "ArrayNumber": ArrayNumber, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["ArrayNumber"]) -> Schema_.Properties.ArrayNumber[tuple]: ... + def __getitem__(self, name: typing_extensions.Literal["ArrayNumber"]) -> ArrayNumber[tuple]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -94,31 +101,13 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], ArrayNumber: typing.Union[ - Schema_.Properties.ArrayNumber[tuple], + ArrayNumber[tuple], schemas.Unset, list, tuple ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ArrayOfNumberOnly[frozendict.frozendict]: inst = super().__new__( cls, @@ -132,3 +121,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/array_test.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/array_test.py index 1fc7747f40e..b16a0bf9a37 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/array_test.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/array_test.py @@ -10,6 +10,201 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Items: typing_extensions.TypeAlias = schemas.StrSchema[U] + + +class ArrayOfString( + schemas.ListSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore + + def __new__( + cls, + arg_: typing.Sequence[ + typing.Union[ + Items[str], + str + ] + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> ArrayOfString[tuple]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + ArrayOfString[tuple], + inst + ) + return inst + + def __getitem__(self, name: int) -> Items[str]: + return super().__getitem__(name) + +Items3: typing_extensions.TypeAlias = schemas.Int64Schema[U] + + +class Items2( + schemas.ListSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items3] = dataclasses.field(default_factory=lambda: Items3) # type: ignore + + def __new__( + cls, + arg_: typing.Sequence[ + typing.Union[ + Items3[decimal.Decimal], + decimal.Decimal, + int + ] + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> Items2[tuple]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + Items2[tuple], + inst + ) + return inst + + def __getitem__(self, name: int) -> Items3[decimal.Decimal]: + return super().__getitem__(name) + + + +class ArrayArrayOfInteger( + schemas.ListSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items2] = dataclasses.field(default_factory=lambda: Items2) # type: ignore + + def __new__( + cls, + arg_: typing.Sequence[ + typing.Union[ + Items2[tuple], + list, + tuple + ] + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> ArrayArrayOfInteger[tuple]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + ArrayArrayOfInteger[tuple], + inst + ) + return inst + + def __getitem__(self, name: int) -> Items2[tuple]: + return super().__getitem__(name) + + + +class Items4( + schemas.ListSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[read_only_first.ReadOnlyFirst] = dataclasses.field(default_factory=lambda: read_only_first.ReadOnlyFirst) # type: ignore + + def __new__( + cls, + arg_: typing.Sequence[ + typing.Union[ + read_only_first.ReadOnlyFirst[frozendict.frozendict], + dict, + frozendict.frozendict + ] + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> Items4[tuple]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + Items4[tuple], + inst + ) + return inst + + def __getitem__(self, name: int) -> read_only_first.ReadOnlyFirst[frozendict.frozendict]: + return super().__getitem__(name) + + + +class ArrayArrayOfModel( + schemas.ListSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items4] = dataclasses.field(default_factory=lambda: Items4) # type: ignore + + def __new__( + cls, + arg_: typing.Sequence[ + typing.Union[ + Items4[tuple], + list, + tuple + ] + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> ArrayArrayOfModel[tuple]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + ArrayArrayOfModel[tuple], + inst + ) + return inst + + def __getitem__(self, name: int) -> Items4[tuple]: + return super().__getitem__(name) + +Properties = typing_extensions.TypedDict( + 'Properties', + { + "array_of_string": typing.Type[ArrayOfString], + "array_array_of_integer": typing.Type[ArrayArrayOfInteger], + "array_array_of_model": typing.Type[ArrayArrayOfModel], + } +) + class ArrayTest( schemas.DictSchema[schemas.T] @@ -21,199 +216,19 @@ class ArrayTest( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - - class ArrayOfString( - schemas.ListSchema[schemas.T] - ): - - - class Schema_: - types = {tuple} - Items: typing_extensions.TypeAlias = schemas.StrSchema[U] - - def __new__( - cls, - arg_: typing.Sequence[ - typing.Union[ - Schema_.Items[str], - str - ] - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> ArrayTest.Schema_.Properties.ArrayOfString[tuple]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - ArrayTest.Schema_.Properties.ArrayOfString[tuple], - inst - ) - return inst - - def __getitem__(self, name: int) -> Schema_.Items[str]: - return super().__getitem__(name) - - - class ArrayArrayOfInteger( - schemas.ListSchema[schemas.T] - ): - - - class Schema_: - types = {tuple} - - - class Items( - schemas.ListSchema[schemas.T] - ): - - - class Schema_: - types = {tuple} - Items: typing_extensions.TypeAlias = schemas.Int64Schema[U] - - def __new__( - cls, - arg_: typing.Sequence[ - typing.Union[ - Schema_.Items[decimal.Decimal], - decimal.Decimal, - int - ] - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> ArrayTest.Schema_.Properties.ArrayArrayOfInteger.Schema_.Items[tuple]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - ArrayTest.Schema_.Properties.ArrayArrayOfInteger.Schema_.Items[tuple], - inst - ) - return inst - - def __getitem__(self, name: int) -> Schema_.Items[decimal.Decimal]: - return super().__getitem__(name) - - def __new__( - cls, - arg_: typing.Sequence[ - typing.Union[ - Schema_.Items[tuple], - list, - tuple - ] - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> ArrayTest.Schema_.Properties.ArrayArrayOfInteger[tuple]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - ArrayTest.Schema_.Properties.ArrayArrayOfInteger[tuple], - inst - ) - return inst - - def __getitem__(self, name: int) -> Schema_.Items[tuple]: - return super().__getitem__(name) - - - class ArrayArrayOfModel( - schemas.ListSchema[schemas.T] - ): - - - class Schema_: - types = {tuple} - - - class Items( - schemas.ListSchema[schemas.T] - ): - - - class Schema_: - types = {tuple} - - @staticmethod - def items() -> typing.Type[read_only_first.ReadOnlyFirst]: - return read_only_first.ReadOnlyFirst - - def __new__( - cls, - arg_: typing.Sequence[ - typing.Union[ - read_only_first.ReadOnlyFirst[frozendict.frozendict], - dict, - frozendict.frozendict - ] - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> ArrayTest.Schema_.Properties.ArrayArrayOfModel.Schema_.Items[tuple]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - ArrayTest.Schema_.Properties.ArrayArrayOfModel.Schema_.Items[tuple], - inst - ) - return inst - - def __getitem__(self, name: int) -> read_only_first.ReadOnlyFirst[frozendict.frozendict]: - return super().__getitem__(name) - - def __new__( - cls, - arg_: typing.Sequence[ - typing.Union[ - Schema_.Items[tuple], - list, - tuple - ] - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> ArrayTest.Schema_.Properties.ArrayArrayOfModel[tuple]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - ArrayTest.Schema_.Properties.ArrayArrayOfModel[tuple], - inst - ) - return inst - - def __getitem__(self, name: int) -> Schema_.Items[tuple]: - return super().__getitem__(name) - __annotations__ = { - "array_of_string": ArrayOfString, - "array_array_of_integer": ArrayArrayOfInteger, - "array_array_of_model": ArrayArrayOfModel, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["array_of_string"]) -> Schema_.Properties.ArrayOfString[tuple]: ... + def __getitem__(self, name: typing_extensions.Literal["array_of_string"]) -> ArrayOfString[tuple]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["array_array_of_integer"]) -> Schema_.Properties.ArrayArrayOfInteger[tuple]: ... + def __getitem__(self, name: typing_extensions.Literal["array_array_of_integer"]) -> ArrayArrayOfInteger[tuple]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["array_array_of_model"]) -> Schema_.Properties.ArrayArrayOfModel[tuple]: ... + def __getitem__(self, name: typing_extensions.Literal["array_array_of_model"]) -> ArrayArrayOfModel[tuple]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -243,43 +258,25 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], array_of_string: typing.Union[ - Schema_.Properties.ArrayOfString[tuple], + ArrayOfString[tuple], schemas.Unset, list, tuple ] = schemas.unset, array_array_of_integer: typing.Union[ - Schema_.Properties.ArrayArrayOfInteger[tuple], + ArrayArrayOfInteger[tuple], schemas.Unset, list, tuple ] = schemas.unset, array_array_of_model: typing.Union[ - Schema_.Properties.ArrayArrayOfModel[tuple], + ArrayArrayOfModel[tuple], schemas.Unset, list, tuple ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ArrayTest[frozendict.frozendict]: inst = super().__new__( cls, @@ -296,4 +293,5 @@ def __new__( ) return inst + from petstore_api.components.schema import read_only_first diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/array_with_validations_in_items.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/array_with_validations_in_items.py index 76b7d6641e4..4e60458b62f 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/array_with_validations_in_items.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/array_with_validations_in_items.py @@ -11,6 +11,21 @@ from petstore_api.shared_imports.schema_imports import * + +class Items( + schemas.Int64Schema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + decimal.Decimal, + }) + format: str = 'int64' + inclusive_maximum: typing.Union[int, float] = 7 + + class ArrayWithValidationsInItems( schemas.ListSchema[schemas.T] ): @@ -21,28 +36,17 @@ class ArrayWithValidationsInItems( """ - class Schema_: - types = {tuple} - max_items = 2 - - - class Items( - schemas.Int64Schema[schemas.T] - ): - - - class Schema_: - types = { - decimal.Decimal, - } - format = 'int64' - inclusive_maximum = 7 + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + max_items: int = 2 + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore def __new__( cls, arg_: typing.Sequence[ typing.Union[ - Schema_.Items[decimal.Decimal], + Items[decimal.Decimal], decimal.Decimal, int ] @@ -60,5 +64,6 @@ def __new__( ) return inst - def __getitem__(self, name: int) -> Schema_.Items[decimal.Decimal]: + def __getitem__(self, name: int) -> Items[decimal.Decimal]: return super().__getitem__(name) + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/banana.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/banana.py index 2183434680b..f3b3a37b31d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/banana.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/banana.py @@ -10,6 +10,14 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +LengthCm: typing_extensions.TypeAlias = schemas.NumberSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "lengthCm": typing.Type[LengthCm], + } +) + class Banana( schemas.DictSchema[schemas.T] @@ -21,24 +29,20 @@ class Banana( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "lengthCm", - } - - class Properties: - LengthCm: typing_extensions.TypeAlias = schemas.NumberSchema[U] - __annotations__ = { - "lengthCm": LengthCm, - } + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @property - def lengthCm(self) -> Schema_.Properties.LengthCm[decimal.Decimal]: + def lengthCm(self) -> LengthCm[decimal.Decimal]: return self.__getitem__("lengthCm") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["lengthCm"]) -> Schema_.Properties.LengthCm[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["lengthCm"]) -> LengthCm[decimal.Decimal]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -66,31 +70,13 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], lengthCm: typing.Union[ - Schema_.Properties.LengthCm[decimal.Decimal], + LengthCm[decimal.Decimal], decimal.Decimal, int, float ], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Banana[frozendict.frozendict]: inst = super().__new__( cls, @@ -104,3 +90,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/banana_req.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/banana_req.py index 29dd3e22417..13fcf17415f 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/banana_req.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/banana_req.py @@ -10,6 +10,17 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +AdditionalProperties: typing_extensions.TypeAlias = schemas.NotAnyTypeSchema[U] +LengthCm: typing_extensions.TypeAlias = schemas.NumberSchema[U] +Sweet: typing_extensions.TypeAlias = schemas.BoolSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "lengthCm": typing.Type[LengthCm], + "sweet": typing.Type[Sweet], + } +) + class BananaReq( schemas.DictSchema[schemas.T] @@ -21,30 +32,24 @@ class BananaReq( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "lengthCm", - } - - class Properties: - LengthCm: typing_extensions.TypeAlias = schemas.NumberSchema[U] - Sweet: typing_extensions.TypeAlias = schemas.BoolSchema[U] - __annotations__ = { - "lengthCm": LengthCm, - "sweet": Sweet, - } - AdditionalProperties: typing_extensions.TypeAlias = schemas.NotAnyTypeSchema[U] + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore @property - def lengthCm(self) -> Schema_.Properties.LengthCm[decimal.Decimal]: + def lengthCm(self) -> LengthCm[decimal.Decimal]: return self.__getitem__("lengthCm") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["lengthCm"]) -> Schema_.Properties.LengthCm[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["lengthCm"]) -> LengthCm[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["sweet"]) -> Schema_.Properties.Sweet[schemas.BoolClass]: ... + def __getitem__(self, name: typing_extensions.Literal["sweet"]) -> Sweet[schemas.BoolClass]: ... def __getitem__( self, @@ -60,13 +65,13 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], lengthCm: typing.Union[ - Schema_.Properties.LengthCm[decimal.Decimal], + LengthCm[decimal.Decimal], decimal.Decimal, int, float ], sweet: typing.Union[ - Schema_.Properties.Sweet[schemas.BoolClass], + Sweet[schemas.BoolClass], schemas.Unset, bool ] = schemas.unset, @@ -84,3 +89,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/bar.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/bar.py index 271d231384e..fdaa22c4d9e 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/bar.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/bar.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class Bar( schemas.StrSchema[schemas.T] ): @@ -21,8 +22,9 @@ class Bar( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ str, - } - default = "bar" + }) + default: str = "bar" diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/basque_pig.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/basque_pig.py index 4e81c76ce9b..5c10c0d3885 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/basque_pig.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/basque_pig.py @@ -11,6 +11,34 @@ from petstore_api.shared_imports.schema_imports import * + +class ClassName( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "BasquePig": "BASQUE_PIG", + } + ) + + @schemas.classproperty + def BASQUE_PIG(cls) -> ClassName[str]: + return cls("BasquePig") # type: ignore +Properties = typing_extensions.TypedDict( + 'Properties', + { + "className": typing.Type[ClassName], + } +) + + class BasquePig( schemas.DictSchema[schemas.T] ): @@ -21,41 +49,20 @@ class BasquePig( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "className", - } - - class Properties: - - - class ClassName( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - enum_value_to_name = { - "BasquePig": "BASQUE_PIG", - } - - @schemas.classproperty - def BASQUE_PIG(cls): - return cls("BasquePig") # type: ignore - __annotations__ = { - "className": ClassName, - } + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @property - def className(self) -> Schema_.Properties.ClassName[str]: + def className(self) -> ClassName[str]: return self.__getitem__("className") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["className"]) -> Schema_.Properties.ClassName[str]: ... + def __getitem__(self, name: typing_extensions.Literal["className"]) -> ClassName[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -83,29 +90,11 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], className: typing.Union[ - Schema_.Properties.ClassName[str], + ClassName[str], str ], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> BasquePig[frozendict.frozendict]: inst = super().__new__( cls, @@ -119,3 +108,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/boolean.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/boolean.py index e34abf6a729..04cd54e9c82 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/boolean.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/boolean.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Boolean: typing_extensions.TypeAlias = schemas.BoolSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/boolean_enum.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/boolean_enum.py index e78bb7bad40..4e82fcace6c 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/boolean_enum.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/boolean_enum.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class BooleanEnum( schemas.BoolSchema[schemas.T] ): @@ -21,14 +22,17 @@ class BooleanEnum( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ schemas.BoolClass, - } - enum_value_to_name = { - schemas.BoolClass.TRUE: "TRUE", - } + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + schemas.BoolClass.TRUE: "TRUE", + } + ) @schemas.classproperty - def TRUE(cls): + def TRUE(cls) -> BooleanEnum[schemas.BoolClass]: return cls(True) # type: ignore diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/capitalization.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/capitalization.py index 3e4d5304bfd..8367d593df6 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/capitalization.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/capitalization.py @@ -10,6 +10,24 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +SmallCamel: typing_extensions.TypeAlias = schemas.StrSchema[U] +CapitalCamel: typing_extensions.TypeAlias = schemas.StrSchema[U] +SmallSnake: typing_extensions.TypeAlias = schemas.StrSchema[U] +CapitalSnake: typing_extensions.TypeAlias = schemas.StrSchema[U] +SCAETHFlowPoints: typing_extensions.TypeAlias = schemas.StrSchema[U] +ATTNAME: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "smallCamel": typing.Type[SmallCamel], + "CapitalCamel": typing.Type[CapitalCamel], + "small_Snake": typing.Type[SmallSnake], + "Capital_Snake": typing.Type[CapitalSnake], + "SCA_ETH_Flow_Points": typing.Type[SCAETHFlowPoints], + "ATT_NAME": typing.Type[ATTNAME], + } +) + class Capitalization( schemas.DictSchema[schemas.T] @@ -21,42 +39,28 @@ class Capitalization( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - SmallCamel: typing_extensions.TypeAlias = schemas.StrSchema[U] - CapitalCamel: typing_extensions.TypeAlias = schemas.StrSchema[U] - SmallSnake: typing_extensions.TypeAlias = schemas.StrSchema[U] - CapitalSnake: typing_extensions.TypeAlias = schemas.StrSchema[U] - SCAETHFlowPoints: typing_extensions.TypeAlias = schemas.StrSchema[U] - ATTNAME: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "smallCamel": SmallCamel, - "CapitalCamel": CapitalCamel, - "small_Snake": SmallSnake, - "Capital_Snake": CapitalSnake, - "SCA_ETH_Flow_Points": SCAETHFlowPoints, - "ATT_NAME": ATTNAME, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["smallCamel"]) -> Schema_.Properties.SmallCamel[str]: ... + def __getitem__(self, name: typing_extensions.Literal["smallCamel"]) -> SmallCamel[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["CapitalCamel"]) -> Schema_.Properties.CapitalCamel[str]: ... + def __getitem__(self, name: typing_extensions.Literal["CapitalCamel"]) -> CapitalCamel[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["small_Snake"]) -> Schema_.Properties.SmallSnake[str]: ... + def __getitem__(self, name: typing_extensions.Literal["small_Snake"]) -> SmallSnake[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["Capital_Snake"]) -> Schema_.Properties.CapitalSnake[str]: ... + def __getitem__(self, name: typing_extensions.Literal["Capital_Snake"]) -> CapitalSnake[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["SCA_ETH_Flow_Points"]) -> Schema_.Properties.SCAETHFlowPoints[str]: ... + def __getitem__(self, name: typing_extensions.Literal["SCA_ETH_Flow_Points"]) -> SCAETHFlowPoints[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["ATT_NAME"]) -> Schema_.Properties.ATTNAME[str]: ... + def __getitem__(self, name: typing_extensions.Literal["ATT_NAME"]) -> ATTNAME[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -89,55 +93,37 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], smallCamel: typing.Union[ - Schema_.Properties.SmallCamel[str], + SmallCamel[str], schemas.Unset, str ] = schemas.unset, CapitalCamel: typing.Union[ - Schema_.Properties.CapitalCamel[str], + CapitalCamel[str], schemas.Unset, str ] = schemas.unset, small_Snake: typing.Union[ - Schema_.Properties.SmallSnake[str], + SmallSnake[str], schemas.Unset, str ] = schemas.unset, Capital_Snake: typing.Union[ - Schema_.Properties.CapitalSnake[str], + CapitalSnake[str], schemas.Unset, str ] = schemas.unset, SCA_ETH_Flow_Points: typing.Union[ - Schema_.Properties.SCAETHFlowPoints[str], + SCAETHFlowPoints[str], schemas.Unset, str ] = schemas.unset, ATT_NAME: typing.Union[ - Schema_.Properties.ATTNAME[str], + ATTNAME[str], schemas.Unset, str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Capitalization[frozendict.frozendict]: inst = super().__new__( cls, @@ -156,3 +142,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/cat.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/cat.py index e32d9792f19..cc4957aa2a2 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/cat.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/cat.py @@ -10,6 +10,75 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Declawed: typing_extensions.TypeAlias = schemas.BoolSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "declawed": typing.Type[Declawed], + } +) + + +class _1( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["declawed"]) -> Declawed[schemas.BoolClass]: ... + + @typing.overload + def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + def __getitem__( + self, + name: typing.Union[ + typing_extensions.Literal["declawed"], + str + ] + ): + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + declawed: typing.Union[ + Declawed[schemas.BoolClass], + schemas.Unset, + bool + ] = schemas.unset, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _1[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + declawed=declawed, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _1[frozendict.frozendict], + inst + ) + return inst + + class Cat( schemas.AnyTypeSchema[schemas.T], @@ -21,142 +90,17 @@ class Cat( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AllOf: - - @staticmethod - def _0() -> typing.Type[animal.Animal]: - return animal.Animal - - - class _1( - schemas.DictSchema[schemas.T] - ): - - - class Schema_: - types = {frozendict.frozendict} - - class Properties: - Declawed: typing_extensions.TypeAlias = schemas.BoolSchema[U] - __annotations__ = { - "declawed": Declawed, - } - - @typing.overload - def __getitem__(self, name: typing_extensions.Literal["declawed"]) -> Schema_.Properties.Declawed[schemas.BoolClass]: ... - - @typing.overload - def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: ... - - def __getitem__( - self, - name: typing.Union[ - typing_extensions.Literal["declawed"], - str - ] - ): - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[dict, frozendict.frozendict], - declawed: typing.Union[ - Schema_.Properties.Declawed[schemas.BoolClass], - schemas.Unset, - bool - ] = schemas.unset, - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> Cat.Schema_.AllOf._1[frozendict.frozendict]: - inst = super().__new__( - cls, - *args_, - declawed=declawed, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - Cat.Schema_.AllOf._1[frozendict.frozendict], - inst - ) - return inst - classes = [ - _0, - _1, - ] + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Cat[ typing.Union[ frozendict.frozendict, @@ -192,4 +136,9 @@ def __new__( ) return inst + from petstore_api.components.schema import animal +AllOf = typing.Tuple[ + typing.Type[animal.Animal], + typing.Type[_1[schemas.U]], +] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/category.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/category.py index 13a7d58a493..7d0ea441e94 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/category.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/category.py @@ -10,6 +10,28 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Id: typing_extensions.TypeAlias = schemas.Int64Schema[U] + + +class Name( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + default: str = "default-name" +Properties = typing_extensions.TypedDict( + 'Properties', + { + "id": typing.Type[Id], + "name": typing.Type[Name], + } +) + class Category( schemas.DictSchema[schemas.T] @@ -21,40 +43,23 @@ class Category( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "name", - } - - class Properties: - Id: typing_extensions.TypeAlias = schemas.Int64Schema[U] - - - class Name( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - default = "default-name" - __annotations__ = { - "id": Id, - "name": Name, - } + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @property - def name(self) -> Schema_.Properties.Name[str]: + def name(self) -> Name[str]: return self.__getitem__("name") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["name"]) -> Schema_.Properties.Name[str]: ... + def __getitem__(self, name: typing_extensions.Literal["name"]) -> Name[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["id"]) -> Schema_.Properties.Id[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["id"]) -> Id[decimal.Decimal]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -83,35 +88,17 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], name: typing.Union[ - Schema_.Properties.Name[str], + Name[str], str ], id: typing.Union[ - Schema_.Properties.Id[decimal.Decimal], + Id[decimal.Decimal], schemas.Unset, decimal.Decimal, int ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Category[frozendict.frozendict]: inst = super().__new__( cls, @@ -126,3 +113,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/child_cat.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/child_cat.py index 27df325cc42..ea50ca14e28 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/child_cat.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/child_cat.py @@ -10,6 +10,75 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Name: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "name": typing.Type[Name], + } +) + + +class _1( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["name"]) -> Name[str]: ... + + @typing.overload + def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + def __getitem__( + self, + name: typing.Union[ + typing_extensions.Literal["name"], + str + ] + ): + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + name: typing.Union[ + Name[str], + schemas.Unset, + str + ] = schemas.unset, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _1[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + name=name, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _1[frozendict.frozendict], + inst + ) + return inst + + class ChildCat( schemas.AnyTypeSchema[schemas.T], @@ -21,142 +90,17 @@ class ChildCat( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AllOf: - - @staticmethod - def _0() -> typing.Type[parent_pet.ParentPet]: - return parent_pet.ParentPet - - - class _1( - schemas.DictSchema[schemas.T] - ): - - - class Schema_: - types = {frozendict.frozendict} - - class Properties: - Name: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "name": Name, - } - - @typing.overload - def __getitem__(self, name: typing_extensions.Literal["name"]) -> Schema_.Properties.Name[str]: ... - - @typing.overload - def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: ... - - def __getitem__( - self, - name: typing.Union[ - typing_extensions.Literal["name"], - str - ] - ): - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[dict, frozendict.frozendict], - name: typing.Union[ - Schema_.Properties.Name[str], - schemas.Unset, - str - ] = schemas.unset, - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> ChildCat.Schema_.AllOf._1[frozendict.frozendict]: - inst = super().__new__( - cls, - *args_, - name=name, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - ChildCat.Schema_.AllOf._1[frozendict.frozendict], - inst - ) - return inst - classes = [ - _0, - _1, - ] + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ChildCat[ typing.Union[ frozendict.frozendict, @@ -192,4 +136,9 @@ def __new__( ) return inst + from petstore_api.components.schema import parent_pet +AllOf = typing.Tuple[ + typing.Type[parent_pet.ParentPet], + typing.Type[_1[schemas.U]], +] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/class_model.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/class_model.py index 5084a186ce1..a236f190df5 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/class_model.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/class_model.py @@ -10,6 +10,14 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +_Class: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "_class": typing.Type[_Class], + } +) + class ClassModel( schemas.AnyTypeSchema[schemas.T], @@ -23,18 +31,14 @@ class ClassModel( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class Properties: - _Class: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "_class": _Class, - } + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["_class"]) -> Schema_.Properties._Class[str]: ... + def __getitem__(self, name: typing_extensions.Literal["_class"]) -> _Class[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -60,49 +64,14 @@ def __getitem__( def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, _class: typing.Union[ - Schema_.Properties._Class[str], + _Class[str], schemas.Unset, str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ClassModel[ typing.Union[ frozendict.frozendict, @@ -138,3 +107,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/client.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/client.py index e3721135298..f9be85553e5 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/client.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/client.py @@ -10,6 +10,14 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Client: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "client": typing.Type[Client], + } +) + class Client( schemas.DictSchema[schemas.T] @@ -21,17 +29,13 @@ class Client( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - Client: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "client": Client, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["client"]) -> Schema_.Properties.Client[str]: ... + def __getitem__(self, name: typing_extensions.Literal["client"]) -> Client[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -59,30 +63,12 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], client: typing.Union[ - Schema_.Properties.Client[str], + Client[str], schemas.Unset, str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Client[frozendict.frozendict]: inst = super().__new__( cls, @@ -96,3 +82,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/complex_quadrilateral.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/complex_quadrilateral.py index cf42295f8ca..1d541b5c1d4 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/complex_quadrilateral.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/complex_quadrilateral.py @@ -11,6 +11,95 @@ from petstore_api.shared_imports.schema_imports import * + +class QuadrilateralType( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "ComplexQuadrilateral": "COMPLEX_QUADRILATERAL", + } + ) + + @schemas.classproperty + def COMPLEX_QUADRILATERAL(cls) -> QuadrilateralType[str]: + return cls("ComplexQuadrilateral") # type: ignore +Properties = typing_extensions.TypedDict( + 'Properties', + { + "quadrilateralType": typing.Type[QuadrilateralType], + } +) + + +class _1( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["quadrilateralType"]) -> QuadrilateralType[str]: ... + + @typing.overload + def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + def __getitem__( + self, + name: typing.Union[ + typing_extensions.Literal["quadrilateralType"], + str + ] + ): + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + quadrilateralType: typing.Union[ + QuadrilateralType[str], + schemas.Unset, + str + ] = schemas.unset, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _1[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + quadrilateralType=quadrilateralType, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _1[frozendict.frozendict], + inst + ) + return inst + + + class ComplexQuadrilateral( schemas.AnyTypeSchema[schemas.T], ): @@ -21,159 +110,17 @@ class ComplexQuadrilateral( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AllOf: - - @staticmethod - def _0() -> typing.Type[quadrilateral_interface.QuadrilateralInterface]: - return quadrilateral_interface.QuadrilateralInterface - - - class _1( - schemas.DictSchema[schemas.T] - ): - - - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - - class QuadrilateralType( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - enum_value_to_name = { - "ComplexQuadrilateral": "COMPLEX_QUADRILATERAL", - } - - @schemas.classproperty - def COMPLEX_QUADRILATERAL(cls): - return cls("ComplexQuadrilateral") # type: ignore - __annotations__ = { - "quadrilateralType": QuadrilateralType, - } - - @typing.overload - def __getitem__(self, name: typing_extensions.Literal["quadrilateralType"]) -> Schema_.Properties.QuadrilateralType[str]: ... - - @typing.overload - def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: ... - - def __getitem__( - self, - name: typing.Union[ - typing_extensions.Literal["quadrilateralType"], - str - ] - ): - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[dict, frozendict.frozendict], - quadrilateralType: typing.Union[ - Schema_.Properties.QuadrilateralType[str], - schemas.Unset, - str - ] = schemas.unset, - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> ComplexQuadrilateral.Schema_.AllOf._1[frozendict.frozendict]: - inst = super().__new__( - cls, - *args_, - quadrilateralType=quadrilateralType, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - ComplexQuadrilateral.Schema_.AllOf._1[frozendict.frozendict], - inst - ) - return inst - classes = [ - _0, - _1, - ] + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ComplexQuadrilateral[ typing.Union[ frozendict.frozendict, @@ -209,4 +156,9 @@ def __new__( ) return inst + from petstore_api.components.schema import quadrilateral_interface +AllOf = typing.Tuple[ + typing.Type[quadrilateral_interface.QuadrilateralInterface], + typing.Type[_1[schemas.U]], +] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_any_of_different_types_no_validations.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_any_of_different_types_no_validations.py index 23093685bee..5fbbf42358b 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_any_of_different_types_no_validations.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_any_of_different_types_no_validations.py @@ -10,6 +10,103 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +_0: typing_extensions.TypeAlias = schemas.DictSchema[U] +_1: typing_extensions.TypeAlias = schemas.DateSchema[U] +_2: typing_extensions.TypeAlias = schemas.DateTimeSchema[U] +_3: typing_extensions.TypeAlias = schemas.BinarySchema[U] +_4: typing_extensions.TypeAlias = schemas.StrSchema[U] +_5: typing_extensions.TypeAlias = schemas.StrSchema[U] +_6: typing_extensions.TypeAlias = schemas.DictSchema[U] +_7: typing_extensions.TypeAlias = schemas.BoolSchema[U] +_8: typing_extensions.TypeAlias = schemas.NoneSchema[U] +Items: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] + + +class _9( + schemas.ListSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore + + def __new__( + cls, + arg_: typing.Sequence[ + typing.Union[ + Items[ + schemas.INPUT_BASE_TYPES + ], + dict, + frozendict.frozendict, + str, + datetime.date, + datetime.datetime, + uuid.UUID, + int, + float, + decimal.Decimal, + bool, + None, + list, + tuple, + bytes, + io.FileIO, + io.BufferedReader + ] + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> _9[tuple]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + _9[tuple], + inst + ) + return inst + + def __getitem__(self, name: int) -> Items[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: + return super().__getitem__(name) + +_10: typing_extensions.TypeAlias = schemas.NumberSchema[U] +_11: typing_extensions.TypeAlias = schemas.Float32Schema[U] +_12: typing_extensions.TypeAlias = schemas.Float64Schema[U] +_13: typing_extensions.TypeAlias = schemas.IntSchema[U] +_14: typing_extensions.TypeAlias = schemas.Int32Schema[U] +_15: typing_extensions.TypeAlias = schemas.Int64Schema[U] +AnyOf = typing.Tuple[ + typing.Type[_0[schemas.U]], + typing.Type[_1[schemas.U]], + typing.Type[_2[schemas.U]], + typing.Type[_3[schemas.U]], + typing.Type[_4[schemas.U]], + typing.Type[_5[schemas.U]], + typing.Type[_6[schemas.U]], + typing.Type[_7[schemas.U]], + typing.Type[_8[schemas.U]], + typing.Type[_9[schemas.U]], + typing.Type[_10[schemas.U]], + typing.Type[_11[schemas.U]], + typing.Type[_12[schemas.U]], + typing.Type[_13[schemas.U]], + typing.Type[_14[schemas.U]], + typing.Type[_15[schemas.U]], +] + class ComposedAnyOfDifferentTypesNoValidations( schemas.AnyTypeSchema[schemas.T], @@ -21,152 +118,17 @@ class ComposedAnyOfDifferentTypesNoValidations( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AnyOf: - _0: typing_extensions.TypeAlias = schemas.DictSchema[U] - _1: typing_extensions.TypeAlias = schemas.DateSchema[U] - _2: typing_extensions.TypeAlias = schemas.DateTimeSchema[U] - _3: typing_extensions.TypeAlias = schemas.BinarySchema[U] - _4: typing_extensions.TypeAlias = schemas.StrSchema[U] - _5: typing_extensions.TypeAlias = schemas.StrSchema[U] - _6: typing_extensions.TypeAlias = schemas.DictSchema[U] - _7: typing_extensions.TypeAlias = schemas.BoolSchema[U] - _8: typing_extensions.TypeAlias = schemas.NoneSchema[U] - - - class _9( - schemas.ListSchema[schemas.T] - ): - - - class Schema_: - types = {tuple} - Items: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - - def __new__( - cls, - arg_: typing.Sequence[ - typing.Union[ - Schema_.Items[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ] - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> ComposedAnyOfDifferentTypesNoValidations.Schema_.AnyOf._9[tuple]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - ComposedAnyOfDifferentTypesNoValidations.Schema_.AnyOf._9[tuple], - inst - ) - return inst - - def __getitem__(self, name: int) -> Schema_.Items[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: - return super().__getitem__(name) - _10: typing_extensions.TypeAlias = schemas.NumberSchema[U] - _11: typing_extensions.TypeAlias = schemas.Float32Schema[U] - _12: typing_extensions.TypeAlias = schemas.Float64Schema[U] - _13: typing_extensions.TypeAlias = schemas.IntSchema[U] - _14: typing_extensions.TypeAlias = schemas.Int32Schema[U] - _15: typing_extensions.TypeAlias = schemas.Int64Schema[U] - classes = [ - _0, - _1, - _2, - _3, - _4, - _5, - _6, - _7, - _8, - _9, - _10, - _11, - _12, - _13, - _14, - _15, - ] + any_of: AnyOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AnyOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ComposedAnyOfDifferentTypesNoValidations[ typing.Union[ frozendict.frozendict, @@ -201,3 +163,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_array.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_array.py index 455e4c96f2a..75ccad31077 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_array.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_array.py @@ -10,6 +10,8 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Items: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] + class ComposedArray( schemas.ListSchema[schemas.T] @@ -21,24 +23,18 @@ class ComposedArray( """ - class Schema_: - types = {tuple} - Items: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore def __new__( cls, arg_: typing.Sequence[ typing.Union[ - Schema_.Items[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + Items[ + schemas.INPUT_BASE_TYPES + ], dict, frozendict.frozendict, str, @@ -70,7 +66,7 @@ def __new__( ) return inst - def __getitem__(self, name: int) -> Schema_.Items[typing.Union[ + def __getitem__(self, name: int) -> Items[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -81,3 +77,4 @@ def __getitem__(self, name: int) -> Schema_.Items[typing.Union[ schemas.FileIO ]]: return super().__getitem__(name) + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_bool.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_bool.py index 9793dd0cf26..ca526bdf863 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_bool.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_bool.py @@ -10,6 +10,11 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +_0: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] +AllOf = typing.Tuple[ + typing.Type[_0[schemas.U]], +] + class ComposedBool( schemas.BoolSchema[schemas.T] @@ -21,16 +26,12 @@ class ComposedBool( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ schemas.BoolClass, - } - - class AllOf: - _0: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - classes = [ - _0, - ] + }) + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore def __new__( @@ -48,3 +49,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_none.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_none.py index 4bbce9a9f9f..ed12b7c4ff9 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_none.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_none.py @@ -10,6 +10,11 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +_0: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] +AllOf = typing.Tuple[ + typing.Type[_0[schemas.U]], +] + class ComposedNone( schemas.NoneSchema[schemas.T] @@ -21,16 +26,12 @@ class ComposedNone( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ schemas.NoneClass, - } - - class AllOf: - _0: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - classes = [ - _0, - ] + }) + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore def __new__( @@ -48,3 +49,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_number.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_number.py index 7fec5602894..c44b3235d52 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_number.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_number.py @@ -10,6 +10,11 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +_0: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] +AllOf = typing.Tuple[ + typing.Type[_0[schemas.U]], +] + class ComposedNumber( schemas.NumberSchema[schemas.T] @@ -21,16 +26,12 @@ class ComposedNumber( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ decimal.Decimal, - } - - class AllOf: - _0: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - classes = [ - _0, - ] + }) + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore def __new__( @@ -48,3 +49,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_object.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_object.py index e7c2701d1ae..d84e2de021a 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_object.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_object.py @@ -10,6 +10,11 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +_0: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] +AllOf = typing.Tuple[ + typing.Type[_0[schemas.U]], +] + class ComposedObject( schemas.DictSchema[schemas.T] @@ -21,41 +26,19 @@ class ComposedObject( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ frozendict.frozendict, - } - - class AllOf: - _0: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - classes = [ - _0, - ] + }) + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ComposedObject[frozendict.frozendict]: inst = super().__new__( cls, @@ -68,3 +51,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_one_of_different_types.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_one_of_different_types.py index b5e73633fe7..209af72b29e 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_one_of_different_types.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_one_of_different_types.py @@ -10,6 +10,121 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +_2: typing_extensions.TypeAlias = schemas.NoneSchema[U] +_3: typing_extensions.TypeAlias = schemas.DateSchema[U] + + +class _4( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + max_properties: int = 4 + min_properties: int = 4 + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _4[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _4[frozendict.frozendict], + inst + ) + return inst + +Items: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] + + +class _5( + schemas.ListSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + max_items: int = 4 + min_items: int = 4 + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore + + def __new__( + cls, + arg_: typing.Sequence[ + typing.Union[ + Items[ + schemas.INPUT_BASE_TYPES + ], + dict, + frozendict.frozendict, + str, + datetime.date, + datetime.datetime, + uuid.UUID, + int, + float, + decimal.Decimal, + bool, + None, + list, + tuple, + bytes, + io.FileIO, + io.BufferedReader + ] + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> _5[tuple]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + _5[tuple], + inst + ) + return inst + + def __getitem__(self, name: int) -> Items[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: + return super().__getitem__(name) + + + +class _6( + schemas.DateTimeSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + format: str = 'date-time' + pattern: schemas.PatternInfo = schemas.PatternInfo( + pattern=r'^2020.*' # noqa: E501 + ) + class ComposedOneOfDifferentTypes( schemas.AnyTypeSchema[schemas.T], @@ -23,202 +138,17 @@ class ComposedOneOfDifferentTypes( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class OneOf: - - @staticmethod - def _0() -> typing.Type[number_with_validations.NumberWithValidations]: - return number_with_validations.NumberWithValidations - - @staticmethod - def _1() -> typing.Type[animal.Animal]: - return animal.Animal - _2: typing_extensions.TypeAlias = schemas.NoneSchema[U] - _3: typing_extensions.TypeAlias = schemas.DateSchema[U] - - - class _4( - schemas.DictSchema[schemas.T] - ): - - - class Schema_: - types = {frozendict.frozendict} - max_properties = 4 - min_properties = 4 - - def __new__( - cls, - *args_: typing.Union[dict, frozendict.frozendict], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> ComposedOneOfDifferentTypes.Schema_.OneOf._4[frozendict.frozendict]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - ComposedOneOfDifferentTypes.Schema_.OneOf._4[frozendict.frozendict], - inst - ) - return inst - - - class _5( - schemas.ListSchema[schemas.T] - ): - - - class Schema_: - types = {tuple} - max_items = 4 - min_items = 4 - Items: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - - def __new__( - cls, - arg_: typing.Sequence[ - typing.Union[ - Schema_.Items[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ] - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> ComposedOneOfDifferentTypes.Schema_.OneOf._5[tuple]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - ComposedOneOfDifferentTypes.Schema_.OneOf._5[tuple], - inst - ) - return inst - - def __getitem__(self, name: int) -> Schema_.Items[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: - return super().__getitem__(name) - - - class _6( - schemas.DateTimeSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - format = 'date-time' - regex={ - 'pattern': r'^2020.*', # noqa: E501 - } - classes = [ - _0, - _1, - _2, - _3, - _4, - _5, - _6, - ] + one_of: OneOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(OneOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ComposedOneOfDifferentTypes[ typing.Union[ frozendict.frozendict, @@ -254,5 +184,15 @@ def __new__( ) return inst + from petstore_api.components.schema import animal from petstore_api.components.schema import number_with_validations +OneOf = typing.Tuple[ + typing.Type[number_with_validations.NumberWithValidations], + typing.Type[animal.Animal], + typing.Type[_2[schemas.U]], + typing.Type[_3[schemas.U]], + typing.Type[_4[schemas.U]], + typing.Type[_5[schemas.U]], + typing.Type[_6[schemas.U]], +] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_string.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_string.py index 60b6a7cc1ed..5126a5ba104 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_string.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/composed_string.py @@ -10,6 +10,11 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +_0: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] +AllOf = typing.Tuple[ + typing.Type[_0[schemas.U]], +] + class ComposedString( schemas.StrSchema[schemas.T] @@ -21,16 +26,12 @@ class ComposedString( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ str, - } - - class AllOf: - _0: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - classes = [ - _0, - ] + }) + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore def __new__( @@ -48,3 +49,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/currency.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/currency.py index c434b611fe7..9bb07dbaf6c 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/currency.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/currency.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class Currency( schemas.StrSchema[schemas.T] ): @@ -21,19 +22,22 @@ class Currency( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ str, - } - enum_value_to_name = { - "eur": "EUR", - "usd": "USD", - } + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "eur": "EUR", + "usd": "USD", + } + ) @schemas.classproperty - def EUR(cls): + def EUR(cls) -> Currency[str]: return cls("eur") # type: ignore @schemas.classproperty - def USD(cls): + def USD(cls) -> Currency[str]: return cls("usd") # type: ignore diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/danish_pig.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/danish_pig.py index 704fccd52fc..af4be54d3eb 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/danish_pig.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/danish_pig.py @@ -11,6 +11,34 @@ from petstore_api.shared_imports.schema_imports import * + +class ClassName( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "DanishPig": "DANISH_PIG", + } + ) + + @schemas.classproperty + def DANISH_PIG(cls) -> ClassName[str]: + return cls("DanishPig") # type: ignore +Properties = typing_extensions.TypedDict( + 'Properties', + { + "className": typing.Type[ClassName], + } +) + + class DanishPig( schemas.DictSchema[schemas.T] ): @@ -21,41 +49,20 @@ class DanishPig( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "className", - } - - class Properties: - - - class ClassName( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - enum_value_to_name = { - "DanishPig": "DANISH_PIG", - } - - @schemas.classproperty - def DANISH_PIG(cls): - return cls("DanishPig") # type: ignore - __annotations__ = { - "className": ClassName, - } + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @property - def className(self) -> Schema_.Properties.ClassName[str]: + def className(self) -> ClassName[str]: return self.__getitem__("className") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["className"]) -> Schema_.Properties.ClassName[str]: ... + def __getitem__(self, name: typing_extensions.Literal["className"]) -> ClassName[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -83,29 +90,11 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], className: typing.Union[ - Schema_.Properties.ClassName[str], + ClassName[str], str ], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> DanishPig[frozendict.frozendict]: inst = super().__new__( cls, @@ -119,3 +108,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/date_time_test.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/date_time_test.py index 76f6bc03629..afc7412ca35 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/date_time_test.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/date_time_test.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class DateTimeTest( schemas.DateTimeSchema[schemas.T] ): @@ -21,8 +22,9 @@ class DateTimeTest( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ str, - } - format = 'date-time' + }) + format: str = 'date-time' diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/date_time_with_validations.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/date_time_with_validations.py index 0d32ff06493..9482d8c17e0 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/date_time_with_validations.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/date_time_with_validations.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class DateTimeWithValidations( schemas.DateTimeSchema[schemas.T] ): @@ -21,11 +22,12 @@ class DateTimeWithValidations( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ str, - } - format = 'date-time' - regex={ - 'pattern': r'^2020.*', # noqa: E501 - } + }) + format: str = 'date-time' + pattern: schemas.PatternInfo = schemas.PatternInfo( + pattern=r'^2020.*' # noqa: E501 + ) diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/date_with_validations.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/date_with_validations.py index 3bf6ec7fed6..9cc20254e25 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/date_with_validations.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/date_with_validations.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class DateWithValidations( schemas.DateSchema[schemas.T] ): @@ -21,11 +22,12 @@ class DateWithValidations( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ str, - } - format = 'date' - regex={ - 'pattern': r'^2020.*', # noqa: E501 - } + }) + format: str = 'date' + pattern: schemas.PatternInfo = schemas.PatternInfo( + pattern=r'^2020.*' # noqa: E501 + ) diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/decimal_payload.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/decimal_payload.py index a49d226a22b..bd611d27d8e 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/decimal_payload.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/decimal_payload.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + DecimalPayload: typing_extensions.TypeAlias = schemas.DecimalSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/dog.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/dog.py index 7f41fb2da24..58df66168bf 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/dog.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/dog.py @@ -10,6 +10,75 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Breed: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "breed": typing.Type[Breed], + } +) + + +class _1( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["breed"]) -> Breed[str]: ... + + @typing.overload + def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + def __getitem__( + self, + name: typing.Union[ + typing_extensions.Literal["breed"], + str + ] + ): + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + breed: typing.Union[ + Breed[str], + schemas.Unset, + str + ] = schemas.unset, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _1[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + breed=breed, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _1[frozendict.frozendict], + inst + ) + return inst + + class Dog( schemas.AnyTypeSchema[schemas.T], @@ -21,142 +90,17 @@ class Dog( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AllOf: - - @staticmethod - def _0() -> typing.Type[animal.Animal]: - return animal.Animal - - - class _1( - schemas.DictSchema[schemas.T] - ): - - - class Schema_: - types = {frozendict.frozendict} - - class Properties: - Breed: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "breed": Breed, - } - - @typing.overload - def __getitem__(self, name: typing_extensions.Literal["breed"]) -> Schema_.Properties.Breed[str]: ... - - @typing.overload - def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: ... - - def __getitem__( - self, - name: typing.Union[ - typing_extensions.Literal["breed"], - str - ] - ): - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[dict, frozendict.frozendict], - breed: typing.Union[ - Schema_.Properties.Breed[str], - schemas.Unset, - str - ] = schemas.unset, - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> Dog.Schema_.AllOf._1[frozendict.frozendict]: - inst = super().__new__( - cls, - *args_, - breed=breed, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - Dog.Schema_.AllOf._1[frozendict.frozendict], - inst - ) - return inst - classes = [ - _0, - _1, - ] + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Dog[ typing.Union[ frozendict.frozendict, @@ -192,4 +136,9 @@ def __new__( ) return inst + from petstore_api.components.schema import animal +AllOf = typing.Tuple[ + typing.Type[animal.Animal], + typing.Type[_1[schemas.U]], +] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/drawing.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/drawing.py index 77d1f5dba17..933e6e50e9a 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/drawing.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/drawing.py @@ -11,6 +11,69 @@ from petstore_api.shared_imports.schema_imports import * + +class Shapes( + schemas.ListSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[shape.Shape] = dataclasses.field(default_factory=lambda: shape.Shape) # type: ignore + + def __new__( + cls, + arg_: typing.Sequence[ + typing.Union[ + shape.Shape[ + schemas.INPUT_BASE_TYPES + ], + dict, + frozendict.frozendict, + str, + datetime.date, + datetime.datetime, + uuid.UUID, + int, + float, + decimal.Decimal, + bool, + None, + list, + tuple, + bytes, + io.FileIO, + io.BufferedReader + ] + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> Shapes[tuple]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + Shapes[tuple], + inst + ) + return inst + + def __getitem__(self, name: int) -> shape.Shape[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: + return super().__getitem__(name) + + + class Drawing( schemas.DictSchema[schemas.T] ): @@ -21,102 +84,11 @@ class Drawing( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - @staticmethod - def main_shape() -> typing.Type[shape.Shape]: - return shape.Shape - - @staticmethod - def shape_or_null() -> typing.Type[shape_or_null.ShapeOrNull]: - return shape_or_null.ShapeOrNull - - @staticmethod - def nullable_shape() -> typing.Type[nullable_shape.NullableShape]: - return nullable_shape.NullableShape - - - class Shapes( - schemas.ListSchema[schemas.T] - ): - - - class Schema_: - types = {tuple} - - @staticmethod - def items() -> typing.Type[shape.Shape]: - return shape.Shape - - def __new__( - cls, - arg_: typing.Sequence[ - typing.Union[ - shape.Shape[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ] - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> Drawing.Schema_.Properties.Shapes[tuple]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - Drawing.Schema_.Properties.Shapes[tuple], - inst - ) - return inst - - def __getitem__(self, name: int) -> shape.Shape[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: - return super().__getitem__(name) - __annotations__ = { - "mainShape": main_shape, - "shapeOrNull": shape_or_null, - "nullableShape": nullable_shape, - "shapes": Shapes, - } - - @staticmethod - def additional_properties() -> typing.Type[fruit.Fruit]: - return fruit.Fruit + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + additional_properties: typing.Type[fruit.Fruit] = dataclasses.field(default_factory=lambda: fruit.Fruit) # type: ignore @typing.overload def __getitem__(self, name: typing_extensions.Literal["mainShape"]) -> shape.Shape[typing.Union[ @@ -155,7 +127,7 @@ def __getitem__(self, name: typing_extensions.Literal["nullableShape"]) -> nulla ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["shapes"]) -> Schema_.Properties.Shapes[tuple]: ... + def __getitem__(self, name: typing_extensions.Literal["shapes"]) -> Shapes[tuple]: ... @typing.overload def __getitem__(self, name: str) -> fruit.Fruit[typing.Union[ @@ -186,16 +158,9 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], mainShape: typing.Union[ - shape.Shape[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + shape.Shape[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -215,16 +180,9 @@ def __new__( io.BufferedReader ] = schemas.unset, shapeOrNull: typing.Union[ - shape_or_null.ShapeOrNull[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + shape_or_null.ShapeOrNull[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -244,16 +202,9 @@ def __new__( io.BufferedReader ] = schemas.unset, nullableShape: typing.Union[ - nullable_shape.NullableShape[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + nullable_shape.NullableShape[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -273,23 +224,16 @@ def __new__( io.BufferedReader ] = schemas.unset, shapes: typing.Union[ - Schema_.Properties.Shapes[tuple], + Shapes[tuple], schemas.Unset, list, tuple ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, **kwargs: typing.Union[ - fruit.Fruit[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + fruit.Fruit[ + schemas.INPUT_BASE_TYPES + ], dict, frozendict.frozendict, str, @@ -324,7 +268,17 @@ def __new__( ) return inst + from petstore_api.components.schema import fruit from petstore_api.components.schema import nullable_shape from petstore_api.components.schema import shape from petstore_api.components.schema import shape_or_null +Properties = typing_extensions.TypedDict( + 'Properties', + { + "mainShape": typing.Type[shape.Shape], + "shapeOrNull": typing.Type[shape_or_null.ShapeOrNull], + "nullableShape": typing.Type[nullable_shape.NullableShape], + "shapes": typing.Type[Shapes], + } +) diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/enum_arrays.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/enum_arrays.py index 2bcaa870312..3eeeb44a273 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/enum_arrays.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/enum_arrays.py @@ -11,6 +11,102 @@ from petstore_api.shared_imports.schema_imports import * + +class JustSymbol( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + ">=": "GREATER_THAN_SIGN_EQUALS_SIGN", + "$": "DOLLAR_SIGN", + } + ) + + @schemas.classproperty + def GREATER_THAN_SIGN_EQUALS_SIGN(cls) -> JustSymbol[str]: + return cls(">=") # type: ignore + + @schemas.classproperty + def DOLLAR_SIGN(cls) -> JustSymbol[str]: + return cls("$") # type: ignore + + +class Items( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "fish": "FISH", + "crab": "CRAB", + } + ) + + @schemas.classproperty + def FISH(cls) -> Items[str]: + return cls("fish") # type: ignore + + @schemas.classproperty + def CRAB(cls) -> Items[str]: + return cls("crab") # type: ignore + + +class ArrayEnum( + schemas.ListSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore + + def __new__( + cls, + arg_: typing.Sequence[ + typing.Union[ + Items[str], + str + ] + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> ArrayEnum[tuple]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + ArrayEnum[tuple], + inst + ) + return inst + + def __getitem__(self, name: int) -> Items[str]: + return super().__getitem__(name) + +Properties = typing_extensions.TypedDict( + 'Properties', + { + "just_symbol": typing.Type[JustSymbol], + "array_enum": typing.Type[ArrayEnum], + } +) + + class EnumArrays( schemas.DictSchema[schemas.T] ): @@ -21,99 +117,16 @@ class EnumArrays( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - - class JustSymbol( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - enum_value_to_name = { - ">=": "GREATER_THAN_SIGN_EQUALS_SIGN", - "$": "DOLLAR_SIGN", - } - - @schemas.classproperty - def GREATER_THAN_SIGN_EQUALS_SIGN(cls): - return cls(">=") # type: ignore - - @schemas.classproperty - def DOLLAR_SIGN(cls): - return cls("$") # type: ignore - - - class ArrayEnum( - schemas.ListSchema[schemas.T] - ): - - - class Schema_: - types = {tuple} - - - class Items( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - enum_value_to_name = { - "fish": "FISH", - "crab": "CRAB", - } - - @schemas.classproperty - def FISH(cls): - return cls("fish") # type: ignore - - @schemas.classproperty - def CRAB(cls): - return cls("crab") # type: ignore - - def __new__( - cls, - arg_: typing.Sequence[ - typing.Union[ - Schema_.Items[str], - str - ] - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> EnumArrays.Schema_.Properties.ArrayEnum[tuple]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - EnumArrays.Schema_.Properties.ArrayEnum[tuple], - inst - ) - return inst - - def __getitem__(self, name: int) -> Schema_.Items[str]: - return super().__getitem__(name) - __annotations__ = { - "just_symbol": JustSymbol, - "array_enum": ArrayEnum, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["just_symbol"]) -> Schema_.Properties.JustSymbol[str]: ... + def __getitem__(self, name: typing_extensions.Literal["just_symbol"]) -> JustSymbol[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["array_enum"]) -> Schema_.Properties.ArrayEnum[tuple]: ... + def __getitem__(self, name: typing_extensions.Literal["array_enum"]) -> ArrayEnum[tuple]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -142,36 +155,18 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], just_symbol: typing.Union[ - Schema_.Properties.JustSymbol[str], + JustSymbol[str], schemas.Unset, str ] = schemas.unset, array_enum: typing.Union[ - Schema_.Properties.ArrayEnum[tuple], + ArrayEnum[tuple], schemas.Unset, list, tuple ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> EnumArrays[frozendict.frozendict]: inst = super().__new__( cls, @@ -186,3 +181,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/enum_class.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/enum_class.py index 168d3e9713b..2c5bb7f1db7 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/enum_class.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/enum_class.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class EnumClass( schemas.StrSchema[schemas.T] ): @@ -21,35 +22,38 @@ class EnumClass( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ str, - } - default = "-efg" - enum_value_to_name = { - "_abc": "_ABC", - "-efg": "HYPHEN_MINUS_EFG", - "(xyz)": "LEFT_PARENTHESIS_XYZ_RIGHT_PARENTHESIS", - "COUNT_1M": "COUNT_1M", - "COUNT_50M": "COUNT_50M", - } + }) + default: str = "-efg" + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "_abc": "_ABC", + "-efg": "HYPHEN_MINUS_EFG", + "(xyz)": "LEFT_PARENTHESIS_XYZ_RIGHT_PARENTHESIS", + "COUNT_1M": "COUNT_1M", + "COUNT_50M": "COUNT_50M", + } + ) @schemas.classproperty - def _ABC(cls): + def _ABC(cls) -> EnumClass[str]: return cls("_abc") # type: ignore @schemas.classproperty - def HYPHEN_MINUS_EFG(cls): + def HYPHEN_MINUS_EFG(cls) -> EnumClass[str]: return cls("-efg") # type: ignore @schemas.classproperty - def LEFT_PARENTHESIS_XYZ_RIGHT_PARENTHESIS(cls): + def LEFT_PARENTHESIS_XYZ_RIGHT_PARENTHESIS(cls) -> EnumClass[str]: return cls("(xyz)") # type: ignore @schemas.classproperty - def COUNT_1M(cls): + def COUNT_1M(cls) -> EnumClass[str]: return cls("COUNT_1M") # type: ignore @schemas.classproperty - def COUNT_50M(cls): + def COUNT_50M(cls) -> EnumClass[str]: return cls("COUNT_50M") # type: ignore diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/enum_test.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/enum_test.py index cfbf1e28418..d4a927fc1c3 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/enum_test.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/enum_test.py @@ -11,6 +11,123 @@ from petstore_api.shared_imports.schema_imports import * + +class EnumString( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "UPPER": "UPPER", + "lower": "LOWER", + "": "EMPTY", + } + ) + + @schemas.classproperty + def UPPER(cls) -> EnumString[str]: + return cls("UPPER") # type: ignore + + @schemas.classproperty + def LOWER(cls) -> EnumString[str]: + return cls("lower") # type: ignore + + @schemas.classproperty + def EMPTY(cls) -> EnumString[str]: + return cls("") # type: ignore + + +class EnumStringRequired( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "UPPER": "UPPER", + "lower": "LOWER", + "": "EMPTY", + } + ) + + @schemas.classproperty + def UPPER(cls) -> EnumStringRequired[str]: + return cls("UPPER") # type: ignore + + @schemas.classproperty + def LOWER(cls) -> EnumStringRequired[str]: + return cls("lower") # type: ignore + + @schemas.classproperty + def EMPTY(cls) -> EnumStringRequired[str]: + return cls("") # type: ignore + + +class EnumInteger( + schemas.Int32Schema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + decimal.Decimal, + }) + format: str = 'int32' + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + 1: "POSITIVE_1", + -1: "NEGATIVE_1", + } + ) + + @schemas.classproperty + def POSITIVE_1(cls) -> EnumInteger[decimal.Decimal]: + return cls(1) # type: ignore + + @schemas.classproperty + def NEGATIVE_1(cls) -> EnumInteger[decimal.Decimal]: + return cls(-1) # type: ignore + + +class EnumNumber( + schemas.Float64Schema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + decimal.Decimal, + }) + format: str = 'double' + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + 1.1: "POSITIVE_1_PT_1", + -1.2: "NEGATIVE_1_PT_2", + } + ) + + @schemas.classproperty + def POSITIVE_1_PT_1(cls) -> EnumNumber[decimal.Decimal]: + return cls(1.1) # type: ignore + + @schemas.classproperty + def NEGATIVE_1_PT_2(cls) -> EnumNumber[decimal.Decimal]: + return cls(-1.2) # type: ignore + + class EnumTest( schemas.DictSchema[schemas.T] ): @@ -21,164 +138,29 @@ class EnumTest( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "enum_string_required", - } - - class Properties: - - - class EnumString( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - enum_value_to_name = { - "UPPER": "UPPER", - "lower": "LOWER", - "": "EMPTY", - } - - @schemas.classproperty - def UPPER(cls): - return cls("UPPER") # type: ignore - - @schemas.classproperty - def LOWER(cls): - return cls("lower") # type: ignore - - @schemas.classproperty - def EMPTY(cls): - return cls("") # type: ignore - - - class EnumStringRequired( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - enum_value_to_name = { - "UPPER": "UPPER", - "lower": "LOWER", - "": "EMPTY", - } - - @schemas.classproperty - def UPPER(cls): - return cls("UPPER") # type: ignore - - @schemas.classproperty - def LOWER(cls): - return cls("lower") # type: ignore - - @schemas.classproperty - def EMPTY(cls): - return cls("") # type: ignore - - - class EnumInteger( - schemas.Int32Schema[schemas.T] - ): - - - class Schema_: - types = { - decimal.Decimal, - } - format = 'int32' - enum_value_to_name = { - 1: "POSITIVE_1", - -1: "NEGATIVE_1", - } - - @schemas.classproperty - def POSITIVE_1(cls): - return cls(1) # type: ignore - - @schemas.classproperty - def NEGATIVE_1(cls): - return cls(-1) # type: ignore - - - class EnumNumber( - schemas.Float64Schema[schemas.T] - ): - - - class Schema_: - types = { - decimal.Decimal, - } - format = 'double' - enum_value_to_name = { - 1.1: "POSITIVE_1_PT_1", - -1.2: "NEGATIVE_1_PT_2", - } - - @schemas.classproperty - def POSITIVE_1_PT_1(cls): - return cls(1.1) # type: ignore - - @schemas.classproperty - def NEGATIVE_1_PT_2(cls): - return cls(-1.2) # type: ignore - - @staticmethod - def string_enum() -> typing.Type[string_enum.StringEnum]: - return string_enum.StringEnum - - @staticmethod - def integer_enum() -> typing.Type[integer_enum.IntegerEnum]: - return integer_enum.IntegerEnum - - @staticmethod - def string_enum_with_default_value() -> typing.Type[string_enum_with_default_value.StringEnumWithDefaultValue]: - return string_enum_with_default_value.StringEnumWithDefaultValue - - @staticmethod - def integer_enum_with_default_value() -> typing.Type[integer_enum_with_default_value.IntegerEnumWithDefaultValue]: - return integer_enum_with_default_value.IntegerEnumWithDefaultValue - - @staticmethod - def integer_enum_one_value() -> typing.Type[integer_enum_one_value.IntegerEnumOneValue]: - return integer_enum_one_value.IntegerEnumOneValue - __annotations__ = { - "enum_string": EnumString, - "enum_string_required": EnumStringRequired, - "enum_integer": EnumInteger, - "enum_number": EnumNumber, - "stringEnum": string_enum, - "IntegerEnum": integer_enum, - "StringEnumWithDefaultValue": string_enum_with_default_value, - "IntegerEnumWithDefaultValue": integer_enum_with_default_value, - "IntegerEnumOneValue": integer_enum_one_value, - } + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @property - def enum_string_required(self) -> Schema_.Properties.EnumStringRequired[str]: + def enum_string_required(self) -> EnumStringRequired[str]: return self.__getitem__("enum_string_required") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["enum_string_required"]) -> Schema_.Properties.EnumStringRequired[str]: ... + def __getitem__(self, name: typing_extensions.Literal["enum_string_required"]) -> EnumStringRequired[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["enum_string"]) -> Schema_.Properties.EnumString[str]: ... + def __getitem__(self, name: typing_extensions.Literal["enum_string"]) -> EnumString[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["enum_integer"]) -> Schema_.Properties.EnumInteger[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["enum_integer"]) -> EnumInteger[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["enum_number"]) -> Schema_.Properties.EnumNumber[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["enum_number"]) -> EnumNumber[decimal.Decimal]: ... @typing.overload def __getitem__(self, name: typing_extensions.Literal["stringEnum"]) -> string_enum.StringEnum[typing.Union[ @@ -232,22 +214,22 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], enum_string_required: typing.Union[ - Schema_.Properties.EnumStringRequired[str], + EnumStringRequired[str], str ], enum_string: typing.Union[ - Schema_.Properties.EnumString[str], + EnumString[str], schemas.Unset, str ] = schemas.unset, enum_integer: typing.Union[ - Schema_.Properties.EnumInteger[decimal.Decimal], + EnumInteger[decimal.Decimal], schemas.Unset, decimal.Decimal, int ] = schemas.unset, enum_number: typing.Union[ - Schema_.Properties.EnumNumber[decimal.Decimal], + EnumNumber[decimal.Decimal], schemas.Unset, decimal.Decimal, int, @@ -286,25 +268,7 @@ def __new__( int ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> EnumTest[frozendict.frozendict]: inst = super().__new__( cls, @@ -327,8 +291,23 @@ def __new__( ) return inst + from petstore_api.components.schema import integer_enum from petstore_api.components.schema import integer_enum_one_value from petstore_api.components.schema import integer_enum_with_default_value from petstore_api.components.schema import string_enum from petstore_api.components.schema import string_enum_with_default_value +Properties = typing_extensions.TypedDict( + 'Properties', + { + "enum_string": typing.Type[EnumString], + "enum_string_required": typing.Type[EnumStringRequired], + "enum_integer": typing.Type[EnumInteger], + "enum_number": typing.Type[EnumNumber], + "stringEnum": typing.Type[string_enum.StringEnum], + "IntegerEnum": typing.Type[integer_enum.IntegerEnum], + "StringEnumWithDefaultValue": typing.Type[string_enum_with_default_value.StringEnumWithDefaultValue], + "IntegerEnumWithDefaultValue": typing.Type[integer_enum_with_default_value.IntegerEnumWithDefaultValue], + "IntegerEnumOneValue": typing.Type[integer_enum_one_value.IntegerEnumOneValue], + } +) diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/equilateral_triangle.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/equilateral_triangle.py index d7a531a1de9..8cbc713dbd2 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/equilateral_triangle.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/equilateral_triangle.py @@ -11,6 +11,95 @@ from petstore_api.shared_imports.schema_imports import * + +class TriangleType( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "EquilateralTriangle": "EQUILATERAL_TRIANGLE", + } + ) + + @schemas.classproperty + def EQUILATERAL_TRIANGLE(cls) -> TriangleType[str]: + return cls("EquilateralTriangle") # type: ignore +Properties = typing_extensions.TypedDict( + 'Properties', + { + "triangleType": typing.Type[TriangleType], + } +) + + +class _1( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["triangleType"]) -> TriangleType[str]: ... + + @typing.overload + def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + def __getitem__( + self, + name: typing.Union[ + typing_extensions.Literal["triangleType"], + str + ] + ): + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + triangleType: typing.Union[ + TriangleType[str], + schemas.Unset, + str + ] = schemas.unset, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _1[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + triangleType=triangleType, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _1[frozendict.frozendict], + inst + ) + return inst + + + class EquilateralTriangle( schemas.AnyTypeSchema[schemas.T], ): @@ -21,159 +110,17 @@ class EquilateralTriangle( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AllOf: - - @staticmethod - def _0() -> typing.Type[triangle_interface.TriangleInterface]: - return triangle_interface.TriangleInterface - - - class _1( - schemas.DictSchema[schemas.T] - ): - - - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - - class TriangleType( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - enum_value_to_name = { - "EquilateralTriangle": "EQUILATERAL_TRIANGLE", - } - - @schemas.classproperty - def EQUILATERAL_TRIANGLE(cls): - return cls("EquilateralTriangle") # type: ignore - __annotations__ = { - "triangleType": TriangleType, - } - - @typing.overload - def __getitem__(self, name: typing_extensions.Literal["triangleType"]) -> Schema_.Properties.TriangleType[str]: ... - - @typing.overload - def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: ... - - def __getitem__( - self, - name: typing.Union[ - typing_extensions.Literal["triangleType"], - str - ] - ): - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[dict, frozendict.frozendict], - triangleType: typing.Union[ - Schema_.Properties.TriangleType[str], - schemas.Unset, - str - ] = schemas.unset, - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> EquilateralTriangle.Schema_.AllOf._1[frozendict.frozendict]: - inst = super().__new__( - cls, - *args_, - triangleType=triangleType, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - EquilateralTriangle.Schema_.AllOf._1[frozendict.frozendict], - inst - ) - return inst - classes = [ - _0, - _1, - ] + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> EquilateralTriangle[ typing.Union[ frozendict.frozendict, @@ -209,4 +156,9 @@ def __new__( ) return inst + from petstore_api.components.schema import triangle_interface +AllOf = typing.Tuple[ + typing.Type[triangle_interface.TriangleInterface], + typing.Type[_1[schemas.U]], +] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/file.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/file.py index 7b0e391b61f..c1d358ff6d2 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/file.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/file.py @@ -10,6 +10,14 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +SourceURI: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "sourceURI": typing.Type[SourceURI], + } +) + class File( schemas.DictSchema[schemas.T] @@ -23,17 +31,13 @@ class File( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - SourceURI: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "sourceURI": SourceURI, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["sourceURI"]) -> Schema_.Properties.SourceURI[str]: ... + def __getitem__(self, name: typing_extensions.Literal["sourceURI"]) -> SourceURI[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -61,30 +65,12 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], sourceURI: typing.Union[ - Schema_.Properties.SourceURI[str], + SourceURI[str], schemas.Unset, str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> File[frozendict.frozendict]: inst = super().__new__( cls, @@ -98,3 +84,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/file_schema_test_class.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/file_schema_test_class.py index 9d1e9137a03..228daa71c06 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/file_schema_test_class.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/file_schema_test_class.py @@ -11,6 +11,44 @@ from petstore_api.shared_imports.schema_imports import * + +class Files( + schemas.ListSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[file.File] = dataclasses.field(default_factory=lambda: file.File) # type: ignore + + def __new__( + cls, + arg_: typing.Sequence[ + typing.Union[ + file.File[frozendict.frozendict], + dict, + frozendict.frozendict + ] + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> Files[tuple]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + Files[tuple], + inst + ) + return inst + + def __getitem__(self, name: int) -> file.File[frozendict.frozendict]: + return super().__getitem__(name) + + + class FileSchemaTestClass( schemas.DictSchema[schemas.T] ): @@ -21,62 +59,16 @@ class FileSchemaTestClass( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - @staticmethod - def file() -> typing.Type[file.File]: - return file.File - - - class Files( - schemas.ListSchema[schemas.T] - ): - - - class Schema_: - types = {tuple} - - @staticmethod - def items() -> typing.Type[file.File]: - return file.File - - def __new__( - cls, - arg_: typing.Sequence[ - typing.Union[ - file.File[frozendict.frozendict], - dict, - frozendict.frozendict - ] - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> FileSchemaTestClass.Schema_.Properties.Files[tuple]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - FileSchemaTestClass.Schema_.Properties.Files[tuple], - inst - ) - return inst - - def __getitem__(self, name: int) -> file.File[frozendict.frozendict]: - return super().__getitem__(name) - __annotations__ = { - "file": file, - "files": Files, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload def __getitem__(self, name: typing_extensions.Literal["file"]) -> file.File[frozendict.frozendict]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["files"]) -> Schema_.Properties.Files[tuple]: ... + def __getitem__(self, name: typing_extensions.Literal["files"]) -> Files[tuple]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -111,31 +103,13 @@ def __new__( frozendict.frozendict ] = schemas.unset, files: typing.Union[ - Schema_.Properties.Files[tuple], + Files[tuple], schemas.Unset, list, tuple ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> FileSchemaTestClass[frozendict.frozendict]: inst = super().__new__( cls, @@ -151,4 +125,12 @@ def __new__( ) return inst + from petstore_api.components.schema import file +Properties = typing_extensions.TypedDict( + 'Properties', + { + "file": typing.Type[file.File], + "files": typing.Type[Files], + } +) diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/foo.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/foo.py index 8f65054530a..b755df3831b 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/foo.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/foo.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class Foo( schemas.DictSchema[schemas.T] ): @@ -21,17 +22,10 @@ class Foo( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - @staticmethod - def bar() -> typing.Type[bar.Bar]: - return bar.Bar - __annotations__ = { - "bar": bar, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload def __getitem__(self, name: typing_extensions.Literal["bar"]) -> bar.Bar[str]: ... @@ -67,25 +61,7 @@ def __new__( str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Foo[frozendict.frozendict]: inst = super().__new__( cls, @@ -100,4 +76,11 @@ def __new__( ) return inst + from petstore_api.components.schema import bar +Properties = typing_extensions.TypedDict( + 'Properties', + { + "bar": typing.Type[bar.Bar], + } +) diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/format_test.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/format_test.py index f8d64a6032e..f4d36455f76 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/format_test.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/format_test.py @@ -11,6 +11,222 @@ from petstore_api.shared_imports.schema_imports import * + +class Integer( + schemas.IntSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + decimal.Decimal, + }) + format: str = 'int' + inclusive_maximum: typing.Union[int, float] = 100 + inclusive_minimum: typing.Union[int, float] = 10 + multiple_of: typing.Union[int, float] = 2 +Int32: typing_extensions.TypeAlias = schemas.Int32Schema[U] + + +class Int32withValidations( + schemas.Int32Schema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + decimal.Decimal, + }) + format: str = 'int32' + inclusive_maximum: typing.Union[int, float] = 200 + inclusive_minimum: typing.Union[int, float] = 20 +Int64: typing_extensions.TypeAlias = schemas.Int64Schema[U] + + +class Number( + schemas.NumberSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + decimal.Decimal, + }) + inclusive_maximum: typing.Union[int, float] = 543.2 + inclusive_minimum: typing.Union[int, float] = 32.1 + multiple_of: typing.Union[int, float] = 32.5 + + +class _Float( + schemas.Float32Schema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + decimal.Decimal, + }) + format: str = 'float' + inclusive_maximum: typing.Union[int, float] = 987.6 + inclusive_minimum: typing.Union[int, float] = 54.3 +Float32: typing_extensions.TypeAlias = schemas.Float32Schema[U] + + +class Double( + schemas.Float64Schema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + decimal.Decimal, + }) + format: str = 'double' + inclusive_maximum: typing.Union[int, float] = 123.4 + inclusive_minimum: typing.Union[int, float] = 67.8 +Float64: typing_extensions.TypeAlias = schemas.Float64Schema[U] +Items: typing_extensions.TypeAlias = schemas.NumberSchema[U] + + +class ArrayWithUniqueItems( + schemas.ListSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + unique_items: bool = True + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore + + def __new__( + cls, + arg_: typing.Sequence[ + typing.Union[ + Items[decimal.Decimal], + decimal.Decimal, + int, + float + ] + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> ArrayWithUniqueItems[tuple]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + ArrayWithUniqueItems[tuple], + inst + ) + return inst + + def __getitem__(self, name: int) -> Items[decimal.Decimal]: + return super().__getitem__(name) + + + +class String( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + pattern: schemas.PatternInfo = schemas.PatternInfo( + pattern=r'[a-z]', # noqa: E501 + flags=re.I, + ) +Byte: typing_extensions.TypeAlias = schemas.StrSchema[U] +Binary: typing_extensions.TypeAlias = schemas.BinarySchema[U] +Date: typing_extensions.TypeAlias = schemas.DateSchema[U] +DateTime: typing_extensions.TypeAlias = schemas.DateTimeSchema[U] +Uuid: typing_extensions.TypeAlias = schemas.UUIDSchema[U] +UuidNoExample: typing_extensions.TypeAlias = schemas.UUIDSchema[U] + + +class Password( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + format: str = 'password' + max_length: int = 64 + min_length: int = 10 + + +class PatternWithDigits( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + pattern: schemas.PatternInfo = schemas.PatternInfo( + pattern=r'^\d{10}$' # noqa: E501 + ) + + +class PatternWithDigitsAndDelimiter( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + pattern: schemas.PatternInfo = schemas.PatternInfo( + pattern=r'^image_\d{1,3}$', # noqa: E501 + flags=re.I, + ) +NoneProp: typing_extensions.TypeAlias = schemas.NoneSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "integer": typing.Type[Integer], + "int32": typing.Type[Int32], + "int32withValidations": typing.Type[Int32withValidations], + "int64": typing.Type[Int64], + "number": typing.Type[Number], + "float": typing.Type[_Float], + "float32": typing.Type[Float32], + "double": typing.Type[Double], + "float64": typing.Type[Float64], + "arrayWithUniqueItems": typing.Type[ArrayWithUniqueItems], + "string": typing.Type[String], + "byte": typing.Type[Byte], + "binary": typing.Type[Binary], + "date": typing.Type[Date], + "dateTime": typing.Type[DateTime], + "uuid": typing.Type[Uuid], + "uuidNoExample": typing.Type[UuidNoExample], + "password": typing.Type[Password], + "pattern_with_digits": typing.Type[PatternWithDigits], + "pattern_with_digits_and_delimiter": typing.Type[PatternWithDigitsAndDelimiter], + "noneProp": typing.Type[NoneProp], + } +) + + class FormatTest( schemas.DictSchema[schemas.T] ): @@ -21,295 +237,95 @@ class FormatTest( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "byte", "date", "number", "password", - } - - class Properties: - - - class Integer( - schemas.IntSchema[schemas.T] - ): - - - class Schema_: - types = { - decimal.Decimal, - } - format = 'int' - inclusive_maximum = 100 - inclusive_minimum = 10 - multiple_of = 2 - Int32: typing_extensions.TypeAlias = schemas.Int32Schema[U] - - - class Int32withValidations( - schemas.Int32Schema[schemas.T] - ): - - - class Schema_: - types = { - decimal.Decimal, - } - format = 'int32' - inclusive_maximum = 200 - inclusive_minimum = 20 - Int64: typing_extensions.TypeAlias = schemas.Int64Schema[U] - - - class Number( - schemas.NumberSchema[schemas.T] - ): - - - class Schema_: - types = { - decimal.Decimal, - } - inclusive_maximum = 543.2 - inclusive_minimum = 32.1 - multiple_of = 32.5 - - - class _Float( - schemas.Float32Schema[schemas.T] - ): - - - class Schema_: - types = { - decimal.Decimal, - } - format = 'float' - inclusive_maximum = 987.6 - inclusive_minimum = 54.3 - Float32: typing_extensions.TypeAlias = schemas.Float32Schema[U] - - - class Double( - schemas.Float64Schema[schemas.T] - ): - - - class Schema_: - types = { - decimal.Decimal, - } - format = 'double' - inclusive_maximum = 123.4 - inclusive_minimum = 67.8 - Float64: typing_extensions.TypeAlias = schemas.Float64Schema[U] - - - class ArrayWithUniqueItems( - schemas.ListSchema[schemas.T] - ): - - - class Schema_: - types = {tuple} - unique_items = True - Items: typing_extensions.TypeAlias = schemas.NumberSchema[U] - - def __new__( - cls, - arg_: typing.Sequence[ - typing.Union[ - Schema_.Items[decimal.Decimal], - decimal.Decimal, - int, - float - ] - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> FormatTest.Schema_.Properties.ArrayWithUniqueItems[tuple]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - FormatTest.Schema_.Properties.ArrayWithUniqueItems[tuple], - inst - ) - return inst - - def __getitem__(self, name: int) -> Schema_.Items[decimal.Decimal]: - return super().__getitem__(name) - - - class String( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - regex={ - 'pattern': r'[a-z]', # noqa: E501 - 'flags': re.I, - } - Byte: typing_extensions.TypeAlias = schemas.StrSchema[U] - Binary: typing_extensions.TypeAlias = schemas.BinarySchema[U] - Date: typing_extensions.TypeAlias = schemas.DateSchema[U] - DateTime: typing_extensions.TypeAlias = schemas.DateTimeSchema[U] - Uuid: typing_extensions.TypeAlias = schemas.UUIDSchema[U] - UuidNoExample: typing_extensions.TypeAlias = schemas.UUIDSchema[U] - - - class Password( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - format = 'password' - max_length = 64 - min_length = 10 - - - class PatternWithDigits( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - regex={ - 'pattern': r'^\d{10}$', # noqa: E501 - } - - - class PatternWithDigitsAndDelimiter( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - regex={ - 'pattern': r'^image_\d{1,3}$', # noqa: E501 - 'flags': re.I, - } - NoneProp: typing_extensions.TypeAlias = schemas.NoneSchema[U] - __annotations__ = { - "integer": Integer, - "int32": Int32, - "int32withValidations": Int32withValidations, - "int64": Int64, - "number": Number, - "float": _Float, - "float32": Float32, - "double": Double, - "float64": Float64, - "arrayWithUniqueItems": ArrayWithUniqueItems, - "string": String, - "byte": Byte, - "binary": Binary, - "date": Date, - "dateTime": DateTime, - "uuid": Uuid, - "uuidNoExample": UuidNoExample, - "password": Password, - "pattern_with_digits": PatternWithDigits, - "pattern_with_digits_and_delimiter": PatternWithDigitsAndDelimiter, - "noneProp": NoneProp, - } + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @property - def byte(self) -> Schema_.Properties.Byte[str]: + def byte(self) -> Byte[str]: return self.__getitem__("byte") @property - def date(self) -> Schema_.Properties.Date[str]: + def date(self) -> Date[str]: return self.__getitem__("date") @property - def number(self) -> Schema_.Properties.Number[decimal.Decimal]: + def number(self) -> Number[decimal.Decimal]: return self.__getitem__("number") @property - def password(self) -> Schema_.Properties.Password[str]: + def password(self) -> Password[str]: return self.__getitem__("password") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["byte"]) -> Schema_.Properties.Byte[str]: ... + def __getitem__(self, name: typing_extensions.Literal["byte"]) -> Byte[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["date"]) -> Schema_.Properties.Date[str]: ... + def __getitem__(self, name: typing_extensions.Literal["date"]) -> Date[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["number"]) -> Schema_.Properties.Number[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["number"]) -> Number[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["password"]) -> Schema_.Properties.Password[str]: ... + def __getitem__(self, name: typing_extensions.Literal["password"]) -> Password[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["integer"]) -> Schema_.Properties.Integer[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["integer"]) -> Integer[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["int32"]) -> Schema_.Properties.Int32[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["int32"]) -> Int32[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["int32withValidations"]) -> Schema_.Properties.Int32withValidations[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["int32withValidations"]) -> Int32withValidations[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["int64"]) -> Schema_.Properties.Int64[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["int64"]) -> Int64[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["float"]) -> Schema_.Properties._Float[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["float"]) -> _Float[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["float32"]) -> Schema_.Properties.Float32[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["float32"]) -> Float32[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["double"]) -> Schema_.Properties.Double[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["double"]) -> Double[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["float64"]) -> Schema_.Properties.Float64[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["float64"]) -> Float64[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["arrayWithUniqueItems"]) -> Schema_.Properties.ArrayWithUniqueItems[tuple]: ... + def __getitem__(self, name: typing_extensions.Literal["arrayWithUniqueItems"]) -> ArrayWithUniqueItems[tuple]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["string"]) -> Schema_.Properties.String[str]: ... + def __getitem__(self, name: typing_extensions.Literal["string"]) -> String[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["binary"]) -> Schema_.Properties.Binary[typing.Union[bytes, schemas.FileIO]]: ... + def __getitem__(self, name: typing_extensions.Literal["binary"]) -> Binary[typing.Union[bytes, schemas.FileIO]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["dateTime"]) -> Schema_.Properties.DateTime[str]: ... + def __getitem__(self, name: typing_extensions.Literal["dateTime"]) -> DateTime[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["uuid"]) -> Schema_.Properties.Uuid[str]: ... + def __getitem__(self, name: typing_extensions.Literal["uuid"]) -> Uuid[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["uuidNoExample"]) -> Schema_.Properties.UuidNoExample[str]: ... + def __getitem__(self, name: typing_extensions.Literal["uuidNoExample"]) -> UuidNoExample[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["pattern_with_digits"]) -> Schema_.Properties.PatternWithDigits[str]: ... + def __getitem__(self, name: typing_extensions.Literal["pattern_with_digits"]) -> PatternWithDigits[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["pattern_with_digits_and_delimiter"]) -> Schema_.Properties.PatternWithDigitsAndDelimiter[str]: ... + def __getitem__(self, name: typing_extensions.Literal["pattern_with_digits_and_delimiter"]) -> PatternWithDigitsAndDelimiter[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["noneProp"]) -> Schema_.Properties.NoneProp[schemas.NoneClass]: ... + def __getitem__(self, name: typing_extensions.Literal["noneProp"]) -> NoneProp[schemas.NoneClass]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -357,140 +373,122 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], byte: typing.Union[ - Schema_.Properties.Byte[str], + Byte[str], str ], date: typing.Union[ - Schema_.Properties.Date[str], + Date[str], str, datetime.date ], number: typing.Union[ - Schema_.Properties.Number[decimal.Decimal], + Number[decimal.Decimal], decimal.Decimal, int, float ], password: typing.Union[ - Schema_.Properties.Password[str], + Password[str], str ], integer: typing.Union[ - Schema_.Properties.Integer[decimal.Decimal], + Integer[decimal.Decimal], schemas.Unset, decimal.Decimal, int ] = schemas.unset, int32: typing.Union[ - Schema_.Properties.Int32[decimal.Decimal], + Int32[decimal.Decimal], schemas.Unset, decimal.Decimal, int ] = schemas.unset, int32withValidations: typing.Union[ - Schema_.Properties.Int32withValidations[decimal.Decimal], + Int32withValidations[decimal.Decimal], schemas.Unset, decimal.Decimal, int ] = schemas.unset, int64: typing.Union[ - Schema_.Properties.Int64[decimal.Decimal], + Int64[decimal.Decimal], schemas.Unset, decimal.Decimal, int ] = schemas.unset, float32: typing.Union[ - Schema_.Properties.Float32[decimal.Decimal], + Float32[decimal.Decimal], schemas.Unset, decimal.Decimal, int, float ] = schemas.unset, double: typing.Union[ - Schema_.Properties.Double[decimal.Decimal], + Double[decimal.Decimal], schemas.Unset, decimal.Decimal, int, float ] = schemas.unset, float64: typing.Union[ - Schema_.Properties.Float64[decimal.Decimal], + Float64[decimal.Decimal], schemas.Unset, decimal.Decimal, int, float ] = schemas.unset, arrayWithUniqueItems: typing.Union[ - Schema_.Properties.ArrayWithUniqueItems[tuple], + ArrayWithUniqueItems[tuple], schemas.Unset, list, tuple ] = schemas.unset, string: typing.Union[ - Schema_.Properties.String[str], + String[str], schemas.Unset, str ] = schemas.unset, binary: typing.Union[ - Schema_.Properties.Binary[typing.Union[bytes, schemas.FileIO]], + Binary[typing.Union[bytes, schemas.FileIO]], schemas.Unset, bytes, io.FileIO, io.BufferedReader ] = schemas.unset, dateTime: typing.Union[ - Schema_.Properties.DateTime[str], + DateTime[str], schemas.Unset, str, datetime.datetime ] = schemas.unset, uuid: typing.Union[ - Schema_.Properties.Uuid[str], + Uuid[str], schemas.Unset, str, uuid.UUID ] = schemas.unset, uuidNoExample: typing.Union[ - Schema_.Properties.UuidNoExample[str], + UuidNoExample[str], schemas.Unset, str, uuid.UUID ] = schemas.unset, pattern_with_digits: typing.Union[ - Schema_.Properties.PatternWithDigits[str], + PatternWithDigits[str], schemas.Unset, str ] = schemas.unset, pattern_with_digits_and_delimiter: typing.Union[ - Schema_.Properties.PatternWithDigitsAndDelimiter[str], + PatternWithDigitsAndDelimiter[str], schemas.Unset, str ] = schemas.unset, noneProp: typing.Union[ - Schema_.Properties.NoneProp[schemas.NoneClass], + NoneProp[schemas.NoneClass], schemas.Unset, None ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> FormatTest[frozendict.frozendict]: inst = super().__new__( cls, @@ -523,3 +521,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/from_schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/from_schema.py index 3a14b0c3916..1210e6c65ff 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/from_schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/from_schema.py @@ -10,6 +10,16 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Data: typing_extensions.TypeAlias = schemas.StrSchema[U] +Id: typing_extensions.TypeAlias = schemas.IntSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "data": typing.Type[Data], + "id": typing.Type[Id], + } +) + class FromSchema( schemas.DictSchema[schemas.T] @@ -21,22 +31,16 @@ class FromSchema( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - Data: typing_extensions.TypeAlias = schemas.StrSchema[U] - Id: typing_extensions.TypeAlias = schemas.IntSchema[U] - __annotations__ = { - "data": Data, - "id": Id, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["data"]) -> Schema_.Properties.Data[str]: ... + def __getitem__(self, name: typing_extensions.Literal["data"]) -> Data[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["id"]) -> Schema_.Properties.Id[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["id"]) -> Id[decimal.Decimal]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -65,36 +69,18 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], data: typing.Union[ - Schema_.Properties.Data[str], + Data[str], schemas.Unset, str ] = schemas.unset, id: typing.Union[ - Schema_.Properties.Id[decimal.Decimal], + Id[decimal.Decimal], schemas.Unset, decimal.Decimal, int ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> FromSchema[frozendict.frozendict]: inst = super().__new__( cls, @@ -109,3 +95,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/fruit.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/fruit.py index 318d575ec54..804e64737b3 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/fruit.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/fruit.py @@ -10,6 +10,14 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Color: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "color": typing.Type[Color], + } +) + class Fruit( schemas.AnyTypeSchema[schemas.T], @@ -21,32 +29,15 @@ class Fruit( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class Properties: - Color: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "color": Color, - } - - class OneOf: - - @staticmethod - def _0() -> typing.Type[apple.Apple]: - return apple.Apple - - @staticmethod - def _1() -> typing.Type[banana.Banana]: - return banana.Banana - classes = [ - _0, - _1, - ] + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + one_of: OneOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(OneOf)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["color"]) -> Schema_.Properties.Color[str]: ... + def __getitem__(self, name: typing_extensions.Literal["color"]) -> Color[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -72,49 +63,14 @@ def __getitem__( def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, color: typing.Union[ - Schema_.Properties.Color[str], + Color[str], schemas.Unset, str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Fruit[ typing.Union[ frozendict.frozendict, @@ -151,5 +107,10 @@ def __new__( ) return inst + from petstore_api.components.schema import apple from petstore_api.components.schema import banana +OneOf = typing.Tuple[ + typing.Type[apple.Apple], + typing.Type[banana.Banana], +] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/fruit_req.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/fruit_req.py index e69a4c751b0..49f1d316c86 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/fruit_req.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/fruit_req.py @@ -10,6 +10,8 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +_0: typing_extensions.TypeAlias = schemas.NoneSchema[U] + class FruitReq( schemas.AnyTypeSchema[schemas.T], @@ -21,66 +23,17 @@ class FruitReq( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class OneOf: - _0: typing_extensions.TypeAlias = schemas.NoneSchema[U] - - @staticmethod - def _1() -> typing.Type[apple_req.AppleReq]: - return apple_req.AppleReq - - @staticmethod - def _2() -> typing.Type[banana_req.BananaReq]: - return banana_req.BananaReq - classes = [ - _0, - _1, - _2, - ] + one_of: OneOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(OneOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> FruitReq[ typing.Union[ frozendict.frozendict, @@ -116,5 +69,11 @@ def __new__( ) return inst + from petstore_api.components.schema import apple_req from petstore_api.components.schema import banana_req +OneOf = typing.Tuple[ + typing.Type[_0[schemas.U]], + typing.Type[apple_req.AppleReq], + typing.Type[banana_req.BananaReq], +] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/gm_fruit.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/gm_fruit.py index cafacf1540b..033997bcc0a 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/gm_fruit.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/gm_fruit.py @@ -10,6 +10,14 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Color: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "color": typing.Type[Color], + } +) + class GmFruit( schemas.AnyTypeSchema[schemas.T], @@ -21,32 +29,15 @@ class GmFruit( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class Properties: - Color: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "color": Color, - } - - class AnyOf: - - @staticmethod - def _0() -> typing.Type[apple.Apple]: - return apple.Apple - - @staticmethod - def _1() -> typing.Type[banana.Banana]: - return banana.Banana - classes = [ - _0, - _1, - ] + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + any_of: AnyOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AnyOf)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["color"]) -> Schema_.Properties.Color[str]: ... + def __getitem__(self, name: typing_extensions.Literal["color"]) -> Color[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -72,49 +63,14 @@ def __getitem__( def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, color: typing.Union[ - Schema_.Properties.Color[str], + Color[str], schemas.Unset, str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> GmFruit[ typing.Union[ frozendict.frozendict, @@ -151,5 +107,10 @@ def __new__( ) return inst + from petstore_api.components.schema import apple from petstore_api.components.schema import banana +AnyOf = typing.Tuple[ + typing.Type[apple.Apple], + typing.Type[banana.Banana], +] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/grandparent_animal.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/grandparent_animal.py index 7ac63cff463..a30a98afe56 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/grandparent_animal.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/grandparent_animal.py @@ -10,6 +10,14 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +PetType: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "pet_type": typing.Type[PetType], + } +) + class GrandparentAnimal( schemas.DictSchema[schemas.T] @@ -21,33 +29,28 @@ class GrandparentAnimal( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "pet_type", - } - - @staticmethod - def discriminator(): - return { + }) + discriminator: typing.Mapping[str, typing.Mapping[str, typing.Type[schemas.Schema]]] = dataclasses.field( + default_factory=lambda: { 'pet_type': { 'ChildCat': child_cat.ChildCat, 'ParentPet': parent_pet.ParentPet, } } - - class Properties: - PetType: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "pet_type": PetType, - } + ) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @property - def pet_type(self) -> Schema_.Properties.PetType[str]: + def pet_type(self) -> PetType[str]: return self.__getitem__("pet_type") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["pet_type"]) -> Schema_.Properties.PetType[str]: ... + def __getitem__(self, name: typing_extensions.Literal["pet_type"]) -> PetType[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -75,29 +78,11 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], pet_type: typing.Union[ - Schema_.Properties.PetType[str], + PetType[str], str ], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> GrandparentAnimal[frozendict.frozendict]: inst = super().__new__( cls, @@ -112,5 +97,6 @@ def __new__( ) return inst + from petstore_api.components.schema import child_cat from petstore_api.components.schema import parent_pet diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/has_only_read_only.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/has_only_read_only.py index daa6d32dce8..a2ade7f99bb 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/has_only_read_only.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/has_only_read_only.py @@ -10,6 +10,16 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Bar: typing_extensions.TypeAlias = schemas.StrSchema[U] +Foo: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "bar": typing.Type[Bar], + "foo": typing.Type[Foo], + } +) + class HasOnlyReadOnly( schemas.DictSchema[schemas.T] @@ -21,22 +31,16 @@ class HasOnlyReadOnly( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - Bar: typing_extensions.TypeAlias = schemas.StrSchema[U] - Foo: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "bar": Bar, - "foo": Foo, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["bar"]) -> Schema_.Properties.Bar[str]: ... + def __getitem__(self, name: typing_extensions.Literal["bar"]) -> Bar[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Schema_.Properties.Foo[str]: ... + def __getitem__(self, name: typing_extensions.Literal["foo"]) -> Foo[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -65,35 +69,17 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], bar: typing.Union[ - Schema_.Properties.Bar[str], + Bar[str], schemas.Unset, str ] = schemas.unset, foo: typing.Union[ - Schema_.Properties.Foo[str], + Foo[str], schemas.Unset, str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> HasOnlyReadOnly[frozendict.frozendict]: inst = super().__new__( cls, @@ -108,3 +94,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/health_check_result.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/health_check_result.py index c5d5b790089..0b711093800 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/health_check_result.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/health_check_result.py @@ -11,6 +11,60 @@ from petstore_api.shared_imports.schema_imports import * + +class NullableMessage( + schemas.NoneBase, + schemas.StrBase, + schemas.Schema[schemas.T], + schemas.NoneStrMixin +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + schemas.NoneClass, + str, + }) + + + def __new__( + cls, + arg_: typing.Union[ + None, + str + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> NullableMessage[ + typing.Union[ + schemas.NoneClass, + str + ] + ]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + NullableMessage[ + typing.Union[ + schemas.NoneClass, + str + ] + ], + inst + ) + return inst + +Properties = typing_extensions.TypedDict( + 'Properties', + { + "NullableMessage": typing.Type[NullableMessage], + } +) + + class HealthCheckResult( schemas.DictSchema[schemas.T] ): @@ -23,61 +77,13 @@ class HealthCheckResult( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - - class NullableMessage( - schemas.NoneBase, - schemas.StrBase, - schemas.Schema[schemas.T], - schemas.NoneStrMixin - ): - - - class Schema_: - types = { - schemas.NoneClass, - str, - } - - - def __new__( - cls, - arg_: typing.Union[ - None, - str - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> HealthCheckResult.Schema_.Properties.NullableMessage[ - typing.Union[ - schemas.NoneClass, - str - ] - ]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - HealthCheckResult.Schema_.Properties.NullableMessage[ - typing.Union[ - schemas.NoneClass, - str - ] - ], - inst - ) - return inst - __annotations__ = { - "NullableMessage": NullableMessage, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["NullableMessage"]) -> Schema_.Properties.NullableMessage[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["NullableMessage"]) -> NullableMessage[typing.Union[ schemas.NoneClass, str ]]: ... @@ -108,7 +114,7 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], NullableMessage: typing.Union[ - Schema_.Properties.NullableMessage[typing.Union[ + NullableMessage[typing.Union[ schemas.NoneClass, str ]], @@ -117,25 +123,7 @@ def __new__( str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> HealthCheckResult[frozendict.frozendict]: inst = super().__new__( cls, @@ -149,3 +137,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/integer_enum.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/integer_enum.py index 9d9a5205a03..ffdb3682e9c 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/integer_enum.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/integer_enum.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class IntegerEnum( schemas.IntSchema[schemas.T] ): @@ -21,25 +22,28 @@ class IntegerEnum( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ decimal.Decimal, - } - format = 'int' - enum_value_to_name = { - 0: "POSITIVE_0", - 1: "POSITIVE_1", - 2: "POSITIVE_2", - } + }) + format: str = 'int' + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + 0: "POSITIVE_0", + 1: "POSITIVE_1", + 2: "POSITIVE_2", + } + ) @schemas.classproperty - def POSITIVE_0(cls): + def POSITIVE_0(cls) -> IntegerEnum[decimal.Decimal]: return cls(0) # type: ignore @schemas.classproperty - def POSITIVE_1(cls): + def POSITIVE_1(cls) -> IntegerEnum[decimal.Decimal]: return cls(1) # type: ignore @schemas.classproperty - def POSITIVE_2(cls): + def POSITIVE_2(cls) -> IntegerEnum[decimal.Decimal]: return cls(2) # type: ignore diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/integer_enum_big.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/integer_enum_big.py index d277679a8b1..5bc35b3ff36 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/integer_enum_big.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/integer_enum_big.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class IntegerEnumBig( schemas.IntSchema[schemas.T] ): @@ -21,25 +22,28 @@ class IntegerEnumBig( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ decimal.Decimal, - } - format = 'int' - enum_value_to_name = { - 10: "POSITIVE_10", - 11: "POSITIVE_11", - 12: "POSITIVE_12", - } + }) + format: str = 'int' + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + 10: "POSITIVE_10", + 11: "POSITIVE_11", + 12: "POSITIVE_12", + } + ) @schemas.classproperty - def POSITIVE_10(cls): + def POSITIVE_10(cls) -> IntegerEnumBig[decimal.Decimal]: return cls(10) # type: ignore @schemas.classproperty - def POSITIVE_11(cls): + def POSITIVE_11(cls) -> IntegerEnumBig[decimal.Decimal]: return cls(11) # type: ignore @schemas.classproperty - def POSITIVE_12(cls): + def POSITIVE_12(cls) -> IntegerEnumBig[decimal.Decimal]: return cls(12) # type: ignore diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/integer_enum_one_value.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/integer_enum_one_value.py index 2b93fb978c7..6d6de983418 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/integer_enum_one_value.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/integer_enum_one_value.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class IntegerEnumOneValue( schemas.IntSchema[schemas.T] ): @@ -21,15 +22,18 @@ class IntegerEnumOneValue( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ decimal.Decimal, - } - format = 'int' - enum_value_to_name = { - 0: "POSITIVE_0", - } + }) + format: str = 'int' + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + 0: "POSITIVE_0", + } + ) @schemas.classproperty - def POSITIVE_0(cls): + def POSITIVE_0(cls) -> IntegerEnumOneValue[decimal.Decimal]: return cls(0) # type: ignore diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/integer_enum_with_default_value.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/integer_enum_with_default_value.py index bb7f5bbf35a..fc043b6aac4 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/integer_enum_with_default_value.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/integer_enum_with_default_value.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class IntegerEnumWithDefaultValue( schemas.IntSchema[schemas.T] ): @@ -21,26 +22,29 @@ class IntegerEnumWithDefaultValue( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ decimal.Decimal, - } - format = 'int' - default = 0 - enum_value_to_name = { - 0: "POSITIVE_0", - 1: "POSITIVE_1", - 2: "POSITIVE_2", - } + }) + format: str = 'int' + default: int = 0 + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + 0: "POSITIVE_0", + 1: "POSITIVE_1", + 2: "POSITIVE_2", + } + ) @schemas.classproperty - def POSITIVE_0(cls): + def POSITIVE_0(cls) -> IntegerEnumWithDefaultValue[decimal.Decimal]: return cls(0) # type: ignore @schemas.classproperty - def POSITIVE_1(cls): + def POSITIVE_1(cls) -> IntegerEnumWithDefaultValue[decimal.Decimal]: return cls(1) # type: ignore @schemas.classproperty - def POSITIVE_2(cls): + def POSITIVE_2(cls) -> IntegerEnumWithDefaultValue[decimal.Decimal]: return cls(2) # type: ignore diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/integer_max10.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/integer_max10.py index f45dccf0637..1577a992b9c 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/integer_max10.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/integer_max10.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class IntegerMax10( schemas.Int64Schema[schemas.T] ): @@ -21,9 +22,10 @@ class IntegerMax10( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ decimal.Decimal, - } - format = 'int64' - inclusive_maximum = 10 + }) + format: str = 'int64' + inclusive_maximum: typing.Union[int, float] = 10 diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/integer_min15.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/integer_min15.py index c239d94a1f0..3450802af3f 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/integer_min15.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/integer_min15.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class IntegerMin15( schemas.Int64Schema[schemas.T] ): @@ -21,9 +22,10 @@ class IntegerMin15( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ decimal.Decimal, - } - format = 'int64' - inclusive_minimum = 15 + }) + format: str = 'int64' + inclusive_minimum: typing.Union[int, float] = 15 diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/isosceles_triangle.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/isosceles_triangle.py index 22d4a7192be..9165ab760c1 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/isosceles_triangle.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/isosceles_triangle.py @@ -11,6 +11,95 @@ from petstore_api.shared_imports.schema_imports import * + +class TriangleType( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "IsoscelesTriangle": "ISOSCELES_TRIANGLE", + } + ) + + @schemas.classproperty + def ISOSCELES_TRIANGLE(cls) -> TriangleType[str]: + return cls("IsoscelesTriangle") # type: ignore +Properties = typing_extensions.TypedDict( + 'Properties', + { + "triangleType": typing.Type[TriangleType], + } +) + + +class _1( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["triangleType"]) -> TriangleType[str]: ... + + @typing.overload + def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + def __getitem__( + self, + name: typing.Union[ + typing_extensions.Literal["triangleType"], + str + ] + ): + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + triangleType: typing.Union[ + TriangleType[str], + schemas.Unset, + str + ] = schemas.unset, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _1[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + triangleType=triangleType, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _1[frozendict.frozendict], + inst + ) + return inst + + + class IsoscelesTriangle( schemas.AnyTypeSchema[schemas.T], ): @@ -21,159 +110,17 @@ class IsoscelesTriangle( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AllOf: - - @staticmethod - def _0() -> typing.Type[triangle_interface.TriangleInterface]: - return triangle_interface.TriangleInterface - - - class _1( - schemas.DictSchema[schemas.T] - ): - - - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - - class TriangleType( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - enum_value_to_name = { - "IsoscelesTriangle": "ISOSCELES_TRIANGLE", - } - - @schemas.classproperty - def ISOSCELES_TRIANGLE(cls): - return cls("IsoscelesTriangle") # type: ignore - __annotations__ = { - "triangleType": TriangleType, - } - - @typing.overload - def __getitem__(self, name: typing_extensions.Literal["triangleType"]) -> Schema_.Properties.TriangleType[str]: ... - - @typing.overload - def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: ... - - def __getitem__( - self, - name: typing.Union[ - typing_extensions.Literal["triangleType"], - str - ] - ): - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[dict, frozendict.frozendict], - triangleType: typing.Union[ - Schema_.Properties.TriangleType[str], - schemas.Unset, - str - ] = schemas.unset, - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> IsoscelesTriangle.Schema_.AllOf._1[frozendict.frozendict]: - inst = super().__new__( - cls, - *args_, - triangleType=triangleType, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - IsoscelesTriangle.Schema_.AllOf._1[frozendict.frozendict], - inst - ) - return inst - classes = [ - _0, - _1, - ] + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> IsoscelesTriangle[ typing.Union[ frozendict.frozendict, @@ -209,4 +156,9 @@ def __new__( ) return inst + from petstore_api.components.schema import triangle_interface +AllOf = typing.Tuple[ + typing.Type[triangle_interface.TriangleInterface], + typing.Type[_1[schemas.U]], +] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/items.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/items.py index fb976fa1ef5..acc467fda71 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/items.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/items.py @@ -10,6 +10,8 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Items: typing_extensions.TypeAlias = schemas.DictSchema[U] + class Items( schemas.ListSchema[schemas.T] @@ -23,15 +25,16 @@ class Items( """ - class Schema_: - types = {tuple} - Items: typing_extensions.TypeAlias = schemas.DictSchema[U] + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore def __new__( cls, arg_: typing.Sequence[ typing.Union[ - Schema_.Items[frozendict.frozendict], + Items[frozendict.frozendict], dict, frozendict.frozendict ] @@ -49,5 +52,6 @@ def __new__( ) return inst - def __getitem__(self, name: int) -> Schema_.Items[frozendict.frozendict]: + def __getitem__(self, name: int) -> Items[frozendict.frozendict]: return super().__getitem__(name) + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/json_patch_request.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/json_patch_request.py index 08bd3bea570..a730a044e0f 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/json_patch_request.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/json_patch_request.py @@ -11,89 +11,43 @@ from petstore_api.shared_imports.schema_imports import * -class JSONPatchRequest( - schemas.ListSchema[schemas.T] + +class Items( + schemas.AnyTypeSchema[schemas.T], ): - """NOTE: This class is auto generated by OpenAPI JSON Schema Generator. - Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator - Do not edit the class manually. - """ + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + one_of: OneOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(OneOf)) # type: ignore - class Schema_: - types = {tuple} - - - class Items( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - - class OneOf: - - @staticmethod - def _0() -> typing.Type[json_patch_request_add_replace_test.JSONPatchRequestAddReplaceTest]: - return json_patch_request_add_replace_test.JSONPatchRequestAddReplaceTest - - @staticmethod - def _1() -> typing.Type[json_patch_request_remove.JSONPatchRequestRemove]: - return json_patch_request_remove.JSONPatchRequestRemove - - @staticmethod - def _2() -> typing.Type[json_patch_request_move_copy.JSONPatchRequestMoveCopy]: - return json_patch_request_move_copy.JSONPatchRequestMoveCopy - classes = [ - _0, - _1, - _2, - ] - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> JSONPatchRequest.Schema_.Items[ + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> Items[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + Items[ typing.Union[ frozendict.frozendict, str, @@ -104,44 +58,35 @@ def __new__( bytes, schemas.FileIO ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - JSONPatchRequest.Schema_.Items[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst + ], + inst + ) + return inst + + + +class JSONPatchRequest( + schemas.ListSchema[schemas.T] +): + """NOTE: This class is auto generated by OpenAPI JSON Schema Generator. + Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator + + Do not edit the class manually. + """ + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore def __new__( cls, arg_: typing.Sequence[ typing.Union[ - Schema_.Items[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + Items[ + schemas.INPUT_BASE_TYPES + ], dict, frozendict.frozendict, str, @@ -173,7 +118,7 @@ def __new__( ) return inst - def __getitem__(self, name: int) -> Schema_.Items[typing.Union[ + def __getitem__(self, name: int) -> Items[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -185,6 +130,12 @@ def __getitem__(self, name: int) -> Schema_.Items[typing.Union[ ]]: return super().__getitem__(name) + from petstore_api.components.schema import json_patch_request_add_replace_test from petstore_api.components.schema import json_patch_request_move_copy from petstore_api.components.schema import json_patch_request_remove +OneOf = typing.Tuple[ + typing.Type[json_patch_request_add_replace_test.JSONPatchRequestAddReplaceTest], + typing.Type[json_patch_request_remove.JSONPatchRequestRemove], + typing.Type[json_patch_request_move_copy.JSONPatchRequestMoveCopy], +] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/json_patch_request_add_replace_test.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/json_patch_request_add_replace_test.py index 15818afec3b..c8dcc208f34 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/json_patch_request_add_replace_test.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/json_patch_request_add_replace_test.py @@ -10,6 +10,49 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +AdditionalProperties: typing_extensions.TypeAlias = schemas.NotAnyTypeSchema[U] +Path: typing_extensions.TypeAlias = schemas.StrSchema[U] +Value: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] + + +class Op( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "add": "ADD", + "replace": "REPLACE", + "test": "TEST", + } + ) + + @schemas.classproperty + def ADD(cls) -> Op[str]: + return cls("add") # type: ignore + + @schemas.classproperty + def REPLACE(cls) -> Op[str]: + return cls("replace") # type: ignore + + @schemas.classproperty + def TEST(cls) -> Op[str]: + return cls("test") # type: ignore +Properties = typing_extensions.TypedDict( + 'Properties', + { + "path": typing.Type[Path], + "value": typing.Type[Value], + "op": typing.Type[Op], + } +) + class JSONPatchRequestAddReplaceTest( schemas.DictSchema[schemas.T] @@ -21,62 +64,27 @@ class JSONPatchRequestAddReplaceTest( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "op", "path", "value", - } - - class Properties: - Path: typing_extensions.TypeAlias = schemas.StrSchema[U] - Value: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - - - class Op( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - enum_value_to_name = { - "add": "ADD", - "replace": "REPLACE", - "test": "TEST", - } - - @schemas.classproperty - def ADD(cls): - return cls("add") # type: ignore - - @schemas.classproperty - def REPLACE(cls): - return cls("replace") # type: ignore - - @schemas.classproperty - def TEST(cls): - return cls("test") # type: ignore - __annotations__ = { - "path": Path, - "value": Value, - "op": Op, - } - AdditionalProperties: typing_extensions.TypeAlias = schemas.NotAnyTypeSchema[U] + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore @property - def op(self) -> Schema_.Properties.Op[str]: + def op(self) -> Op[str]: return self.__getitem__("op") @property - def path(self) -> Schema_.Properties.Path[str]: + def path(self) -> Path[str]: return self.__getitem__("path") @property - def value(self) -> Schema_.Properties.Value[typing.Union[ + def value(self) -> Value[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -89,13 +97,13 @@ def value(self) -> Schema_.Properties.Value[typing.Union[ return self.__getitem__("value") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["op"]) -> Schema_.Properties.Op[str]: ... + def __getitem__(self, name: typing_extensions.Literal["op"]) -> Op[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["path"]) -> Schema_.Properties.Path[str]: ... + def __getitem__(self, name: typing_extensions.Literal["path"]) -> Path[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["value"]) -> Schema_.Properties.Value[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["value"]) -> Value[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -121,24 +129,17 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], op: typing.Union[ - Schema_.Properties.Op[str], + Op[str], str ], path: typing.Union[ - Schema_.Properties.Path[str], + Path[str], str ], value: typing.Union[ - Schema_.Properties.Value[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + Value[ + schemas.INPUT_BASE_TYPES + ], dict, frozendict.frozendict, str, @@ -171,3 +172,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/json_patch_request_move_copy.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/json_patch_request_move_copy.py index 972878e563b..fe4db5efa04 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/json_patch_request_move_copy.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/json_patch_request_move_copy.py @@ -10,6 +10,44 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +AdditionalProperties: typing_extensions.TypeAlias = schemas.NotAnyTypeSchema[U] +_From: typing_extensions.TypeAlias = schemas.StrSchema[U] +Path: typing_extensions.TypeAlias = schemas.StrSchema[U] + + +class Op( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "move": "MOVE", + "copy": "COPY", + } + ) + + @schemas.classproperty + def MOVE(cls) -> Op[str]: + return cls("move") # type: ignore + + @schemas.classproperty + def COPY(cls) -> Op[str]: + return cls("copy") # type: ignore +Properties = typing_extensions.TypedDict( + 'Properties', + { + "from": typing.Type[_From], + "path": typing.Type[Path], + "op": typing.Type[Op], + } +) + class JSONPatchRequestMoveCopy( schemas.DictSchema[schemas.T] @@ -21,63 +59,33 @@ class JSONPatchRequestMoveCopy( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "from", "op", "path", - } - - class Properties: - _From: typing_extensions.TypeAlias = schemas.StrSchema[U] - Path: typing_extensions.TypeAlias = schemas.StrSchema[U] - - - class Op( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - enum_value_to_name = { - "move": "MOVE", - "copy": "COPY", - } - - @schemas.classproperty - def MOVE(cls): - return cls("move") # type: ignore - - @schemas.classproperty - def COPY(cls): - return cls("copy") # type: ignore - __annotations__ = { - "from": _From, - "path": Path, - "op": Op, - } - AdditionalProperties: typing_extensions.TypeAlias = schemas.NotAnyTypeSchema[U] + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore @property - def op(self) -> Schema_.Properties.Op[str]: + def op(self) -> Op[str]: return self.__getitem__("op") @property - def path(self) -> Schema_.Properties.Path[str]: + def path(self) -> Path[str]: return self.__getitem__("path") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["from"]) -> Schema_.Properties._From[str]: ... + def __getitem__(self, name: typing_extensions.Literal["from"]) -> _From[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["op"]) -> Schema_.Properties.Op[str]: ... + def __getitem__(self, name: typing_extensions.Literal["op"]) -> Op[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["path"]) -> Schema_.Properties.Path[str]: ... + def __getitem__(self, name: typing_extensions.Literal["path"]) -> Path[str]: ... def __getitem__( self, @@ -94,11 +102,11 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], op: typing.Union[ - Schema_.Properties.Op[str], + Op[str], str ], path: typing.Union[ - Schema_.Properties.Path[str], + Path[str], str ], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, @@ -115,3 +123,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/json_patch_request_remove.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/json_patch_request_remove.py index 348839bb88f..4111ebeb238 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/json_patch_request_remove.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/json_patch_request_remove.py @@ -10,6 +10,37 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +AdditionalProperties: typing_extensions.TypeAlias = schemas.NotAnyTypeSchema[U] +Path: typing_extensions.TypeAlias = schemas.StrSchema[U] + + +class Op( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "remove": "REMOVE", + } + ) + + @schemas.classproperty + def REMOVE(cls) -> Op[str]: + return cls("remove") # type: ignore +Properties = typing_extensions.TypedDict( + 'Properties', + { + "path": typing.Type[Path], + "op": typing.Type[Op], + } +) + class JSONPatchRequestRemove( schemas.DictSchema[schemas.T] @@ -21,52 +52,29 @@ class JSONPatchRequestRemove( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "op", "path", - } - - class Properties: - Path: typing_extensions.TypeAlias = schemas.StrSchema[U] - - - class Op( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - enum_value_to_name = { - "remove": "REMOVE", - } - - @schemas.classproperty - def REMOVE(cls): - return cls("remove") # type: ignore - __annotations__ = { - "path": Path, - "op": Op, - } - AdditionalProperties: typing_extensions.TypeAlias = schemas.NotAnyTypeSchema[U] + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore @property - def op(self) -> Schema_.Properties.Op[str]: + def op(self) -> Op[str]: return self.__getitem__("op") @property - def path(self) -> Schema_.Properties.Path[str]: + def path(self) -> Path[str]: return self.__getitem__("path") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["op"]) -> Schema_.Properties.Op[str]: ... + def __getitem__(self, name: typing_extensions.Literal["op"]) -> Op[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["path"]) -> Schema_.Properties.Path[str]: ... + def __getitem__(self, name: typing_extensions.Literal["path"]) -> Path[str]: ... def __getitem__( self, @@ -82,11 +90,11 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], op: typing.Union[ - Schema_.Properties.Op[str], + Op[str], str ], path: typing.Union[ - Schema_.Properties.Path[str], + Path[str], str ], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, @@ -103,3 +111,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/mammal.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/mammal.py index ac0b0db52b3..5a9cae8d3c1 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/mammal.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/mammal.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class Mammal( schemas.AnyTypeSchema[schemas.T], ): @@ -21,79 +22,26 @@ class Mammal( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - @staticmethod - def discriminator(): - return { + discriminator: typing.Mapping[str, typing.Mapping[str, typing.Type[schemas.Schema]]] = dataclasses.field( + default_factory=lambda: { 'className': { 'Pig': pig.Pig, 'whale': whale.Whale, 'zebra': zebra.Zebra, } } - - class OneOf: - - @staticmethod - def _0() -> typing.Type[whale.Whale]: - return whale.Whale - - @staticmethod - def _1() -> typing.Type[zebra.Zebra]: - return zebra.Zebra - - @staticmethod - def _2() -> typing.Type[pig.Pig]: - return pig.Pig - classes = [ - _0, - _1, - _2, - ] + ) + one_of: OneOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(OneOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Mammal[ typing.Union[ frozendict.frozendict, @@ -129,6 +77,12 @@ def __new__( ) return inst + from petstore_api.components.schema import pig from petstore_api.components.schema import whale from petstore_api.components.schema import zebra +OneOf = typing.Tuple[ + typing.Type[whale.Whale], + typing.Type[zebra.Zebra], + typing.Type[pig.Pig], +] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/map_test.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/map_test.py index 93db7f1c8a1..2c3bc4a01aa 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/map_test.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/map_test.py @@ -10,6 +10,184 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +AdditionalProperties2: typing_extensions.TypeAlias = schemas.StrSchema[U] + + +class AdditionalProperties( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + additional_properties: typing.Type[AdditionalProperties2] = dataclasses.field(default_factory=lambda: AdditionalProperties2) # type: ignore + + def __getitem__(self, name: str) -> AdditionalProperties2[str]: + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: typing.Union[ + AdditionalProperties2[str], + str + ], + ) -> AdditionalProperties[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + AdditionalProperties[frozendict.frozendict], + inst + ) + return inst + + + +class MapMapOfString( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore + + def __getitem__(self, name: str) -> AdditionalProperties[frozendict.frozendict]: + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: typing.Union[ + AdditionalProperties[frozendict.frozendict], + dict, + frozendict.frozendict + ], + ) -> MapMapOfString[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + MapMapOfString[frozendict.frozendict], + inst + ) + return inst + + + +class AdditionalProperties3( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "UPPER": "UPPER", + "lower": "LOWER", + } + ) + + @schemas.classproperty + def UPPER(cls) -> AdditionalProperties3[str]: + return cls("UPPER") # type: ignore + + @schemas.classproperty + def LOWER(cls) -> AdditionalProperties3[str]: + return cls("lower") # type: ignore + + +class MapOfEnumString( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + additional_properties: typing.Type[AdditionalProperties3] = dataclasses.field(default_factory=lambda: AdditionalProperties3) # type: ignore + + def __getitem__(self, name: str) -> AdditionalProperties3[str]: + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: typing.Union[ + AdditionalProperties3[str], + str + ], + ) -> MapOfEnumString[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + MapOfEnumString[frozendict.frozendict], + inst + ) + return inst + +AdditionalProperties4: typing_extensions.TypeAlias = schemas.BoolSchema[U] + + +class DirectMap( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + additional_properties: typing.Type[AdditionalProperties4] = dataclasses.field(default_factory=lambda: AdditionalProperties4) # type: ignore + + def __getitem__(self, name: str) -> AdditionalProperties4[schemas.BoolClass]: + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: typing.Union[ + AdditionalProperties4[schemas.BoolClass], + bool + ], + ) -> DirectMap[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + DirectMap[frozendict.frozendict], + inst + ) + return inst + + class MapTest( schemas.DictSchema[schemas.T] @@ -21,191 +199,19 @@ class MapTest( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - - class MapMapOfString( - schemas.DictSchema[schemas.T] - ): - - - class Schema_: - types = {frozendict.frozendict} - - - class AdditionalProperties( - schemas.DictSchema[schemas.T] - ): - - - class Schema_: - types = {frozendict.frozendict} - AdditionalProperties: typing_extensions.TypeAlias = schemas.StrSchema[U] - - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[str]: - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[dict, frozendict.frozendict], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - Schema_.AdditionalProperties[str], - str - ], - ) -> MapTest.Schema_.Properties.MapMapOfString.Schema_.AdditionalProperties[frozendict.frozendict]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - MapTest.Schema_.Properties.MapMapOfString.Schema_.AdditionalProperties[frozendict.frozendict], - inst - ) - return inst - - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[frozendict.frozendict]: - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[dict, frozendict.frozendict], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - Schema_.AdditionalProperties[frozendict.frozendict], - dict, - frozendict.frozendict - ], - ) -> MapTest.Schema_.Properties.MapMapOfString[frozendict.frozendict]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - MapTest.Schema_.Properties.MapMapOfString[frozendict.frozendict], - inst - ) - return inst - - - class MapOfEnumString( - schemas.DictSchema[schemas.T] - ): - - - class Schema_: - types = {frozendict.frozendict} - - - class AdditionalProperties( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - enum_value_to_name = { - "UPPER": "UPPER", - "lower": "LOWER", - } - - @schemas.classproperty - def UPPER(cls): - return cls("UPPER") # type: ignore - - @schemas.classproperty - def LOWER(cls): - return cls("lower") # type: ignore - - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[str]: - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[dict, frozendict.frozendict], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - Schema_.AdditionalProperties[str], - str - ], - ) -> MapTest.Schema_.Properties.MapOfEnumString[frozendict.frozendict]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - MapTest.Schema_.Properties.MapOfEnumString[frozendict.frozendict], - inst - ) - return inst - - - class DirectMap( - schemas.DictSchema[schemas.T] - ): - - - class Schema_: - types = {frozendict.frozendict} - AdditionalProperties: typing_extensions.TypeAlias = schemas.BoolSchema[U] - - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[schemas.BoolClass]: - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[dict, frozendict.frozendict], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - Schema_.AdditionalProperties[schemas.BoolClass], - bool - ], - ) -> MapTest.Schema_.Properties.DirectMap[frozendict.frozendict]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - MapTest.Schema_.Properties.DirectMap[frozendict.frozendict], - inst - ) - return inst - - @staticmethod - def indirect_map() -> typing.Type[string_boolean_map.StringBooleanMap]: - return string_boolean_map.StringBooleanMap - __annotations__ = { - "map_map_of_string": MapMapOfString, - "map_of_enum_string": MapOfEnumString, - "direct_map": DirectMap, - "indirect_map": indirect_map, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["map_map_of_string"]) -> Schema_.Properties.MapMapOfString[frozendict.frozendict]: ... + def __getitem__(self, name: typing_extensions.Literal["map_map_of_string"]) -> MapMapOfString[frozendict.frozendict]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["map_of_enum_string"]) -> Schema_.Properties.MapOfEnumString[frozendict.frozendict]: ... + def __getitem__(self, name: typing_extensions.Literal["map_of_enum_string"]) -> MapOfEnumString[frozendict.frozendict]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["direct_map"]) -> Schema_.Properties.DirectMap[frozendict.frozendict]: ... + def __getitem__(self, name: typing_extensions.Literal["direct_map"]) -> DirectMap[frozendict.frozendict]: ... @typing.overload def __getitem__(self, name: typing_extensions.Literal["indirect_map"]) -> string_boolean_map.StringBooleanMap[frozendict.frozendict]: ... @@ -239,19 +245,19 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], map_map_of_string: typing.Union[ - Schema_.Properties.MapMapOfString[frozendict.frozendict], + MapMapOfString[frozendict.frozendict], schemas.Unset, dict, frozendict.frozendict ] = schemas.unset, map_of_enum_string: typing.Union[ - Schema_.Properties.MapOfEnumString[frozendict.frozendict], + MapOfEnumString[frozendict.frozendict], schemas.Unset, dict, frozendict.frozendict ] = schemas.unset, direct_map: typing.Union[ - Schema_.Properties.DirectMap[frozendict.frozendict], + DirectMap[frozendict.frozendict], schemas.Unset, dict, frozendict.frozendict @@ -263,25 +269,7 @@ def __new__( frozendict.frozendict ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> MapTest[frozendict.frozendict]: inst = super().__new__( cls, @@ -299,4 +287,14 @@ def __new__( ) return inst + from petstore_api.components.schema import string_boolean_map +Properties = typing_extensions.TypedDict( + 'Properties', + { + "map_map_of_string": typing.Type[MapMapOfString], + "map_of_enum_string": typing.Type[MapOfEnumString], + "direct_map": typing.Type[DirectMap], + "indirect_map": typing.Type[string_boolean_map.StringBooleanMap], + } +) diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/mixed_properties_and_additional_properties_class.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/mixed_properties_and_additional_properties_class.py index 3d4c46b1624..6db68c4cd22 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/mixed_properties_and_additional_properties_class.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/mixed_properties_and_additional_properties_class.py @@ -10,6 +10,55 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Uuid: typing_extensions.TypeAlias = schemas.UUIDSchema[U] +DateTime: typing_extensions.TypeAlias = schemas.DateTimeSchema[U] + + +class Map( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + additional_properties: typing.Type[animal.Animal] = dataclasses.field(default_factory=lambda: animal.Animal) # type: ignore + + def __getitem__(self, name: str) -> animal.Animal[frozendict.frozendict]: + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: typing.Union[ + animal.Animal[frozendict.frozendict], + dict, + frozendict.frozendict + ], + ) -> Map[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + Map[frozendict.frozendict], + inst + ) + return inst + +Properties = typing_extensions.TypedDict( + 'Properties', + { + "uuid": typing.Type[Uuid], + "dateTime": typing.Type[DateTime], + "map": typing.Type[Map], + } +) + class MixedPropertiesAndAdditionalPropertiesClass( schemas.DictSchema[schemas.T] @@ -21,65 +70,19 @@ class MixedPropertiesAndAdditionalPropertiesClass( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - Uuid: typing_extensions.TypeAlias = schemas.UUIDSchema[U] - DateTime: typing_extensions.TypeAlias = schemas.DateTimeSchema[U] - - - class Map( - schemas.DictSchema[schemas.T] - ): - - - class Schema_: - types = {frozendict.frozendict} - - @staticmethod - def additional_properties() -> typing.Type[animal.Animal]: - return animal.Animal - - def __getitem__(self, name: str) -> animal.Animal[frozendict.frozendict]: - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[dict, frozendict.frozendict], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - animal.Animal[frozendict.frozendict], - dict, - frozendict.frozendict - ], - ) -> MixedPropertiesAndAdditionalPropertiesClass.Schema_.Properties.Map[frozendict.frozendict]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - MixedPropertiesAndAdditionalPropertiesClass.Schema_.Properties.Map[frozendict.frozendict], - inst - ) - return inst - __annotations__ = { - "uuid": Uuid, - "dateTime": DateTime, - "map": Map, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["uuid"]) -> Schema_.Properties.Uuid[str]: ... + def __getitem__(self, name: typing_extensions.Literal["uuid"]) -> Uuid[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["dateTime"]) -> Schema_.Properties.DateTime[str]: ... + def __getitem__(self, name: typing_extensions.Literal["dateTime"]) -> DateTime[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["map"]) -> Schema_.Properties.Map[frozendict.frozendict]: ... + def __getitem__(self, name: typing_extensions.Literal["map"]) -> Map[frozendict.frozendict]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -109,43 +112,25 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], uuid: typing.Union[ - Schema_.Properties.Uuid[str], + Uuid[str], schemas.Unset, str, uuid.UUID ] = schemas.unset, dateTime: typing.Union[ - Schema_.Properties.DateTime[str], + DateTime[str], schemas.Unset, str, datetime.datetime ] = schemas.unset, map: typing.Union[ - Schema_.Properties.Map[frozendict.frozendict], + Map[frozendict.frozendict], schemas.Unset, dict, frozendict.frozendict ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> MixedPropertiesAndAdditionalPropertiesClass[frozendict.frozendict]: inst = super().__new__( cls, @@ -162,4 +147,5 @@ def __new__( ) return inst + from petstore_api.components.schema import animal diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/money.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/money.py index 58cd138b97e..f7e8622f426 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/money.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/money.py @@ -10,6 +10,8 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Amount: typing_extensions.TypeAlias = schemas.DecimalSchema[U] + class Money( schemas.DictSchema[schemas.T] @@ -21,26 +23,17 @@ class Money( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "amount", "currency", - } - - class Properties: - Amount: typing_extensions.TypeAlias = schemas.DecimalSchema[U] - - @staticmethod - def currency() -> typing.Type[currency.Currency]: - return currency.Currency - __annotations__ = { - "amount": Amount, - "currency": currency, - } + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @property - def amount(self) -> Schema_.Properties.Amount[str]: + def amount(self) -> Amount[str]: return self.__getitem__("amount") @property @@ -48,7 +41,7 @@ def currency(self) -> currency.Currency[str]: return self.__getitem__("currency") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["amount"]) -> Schema_.Properties.Amount[str]: ... + def __getitem__(self, name: typing_extensions.Literal["amount"]) -> Amount[str]: ... @typing.overload def __getitem__(self, name: typing_extensions.Literal["currency"]) -> currency.Currency[str]: ... @@ -80,7 +73,7 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], amount: typing.Union[ - Schema_.Properties.Amount[str], + Amount[str], str ], currency: typing.Union[ @@ -88,25 +81,7 @@ def __new__( str ], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Money[frozendict.frozendict]: inst = super().__new__( cls, @@ -122,4 +97,12 @@ def __new__( ) return inst + from petstore_api.components.schema import currency +Properties = typing_extensions.TypedDict( + 'Properties', + { + "amount": typing.Type[Amount], + "currency": typing.Type[currency.Currency], + } +) diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/name.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/name.py index 71774e1bdac..df87cc9c1dd 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/name.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/name.py @@ -10,6 +10,18 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Name: typing_extensions.TypeAlias = schemas.Int32Schema[U] +SnakeCase: typing_extensions.TypeAlias = schemas.Int32Schema[U] +_Property: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "name": typing.Type[Name], + "snake_case": typing.Type[SnakeCase], + "property": typing.Type[_Property], + } +) + class Name( schemas.AnyTypeSchema[schemas.T], @@ -23,35 +35,27 @@ class Name( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - required = { + required: typing.FrozenSet[str] = frozenset({ "name", - } - - class Properties: - Name: typing_extensions.TypeAlias = schemas.Int32Schema[U] - SnakeCase: typing_extensions.TypeAlias = schemas.Int32Schema[U] - _Property: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "name": Name, - "snake_case": SnakeCase, - "property": _Property, - } + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @property - def name(self) -> Schema_.Properties.Name[decimal.Decimal]: + def name(self) -> Name[decimal.Decimal]: return self.__getitem__("name") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["name"]) -> Schema_.Properties.Name[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["name"]) -> Name[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["snake_case"]) -> Schema_.Properties.SnakeCase[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["snake_case"]) -> SnakeCase[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["property"]) -> Schema_.Properties._Property[str]: ... + def __getitem__(self, name: typing_extensions.Literal["property"]) -> _Property[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -79,50 +83,15 @@ def __getitem__( def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, snake_case: typing.Union[ - Schema_.Properties.SnakeCase[decimal.Decimal], + SnakeCase[decimal.Decimal], schemas.Unset, decimal.Decimal, int ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Name[ typing.Union[ frozendict.frozendict, @@ -158,3 +127,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/no_additional_properties.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/no_additional_properties.py index 35abf35ee22..edb6b032e3d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/no_additional_properties.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/no_additional_properties.py @@ -10,6 +10,17 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +AdditionalProperties: typing_extensions.TypeAlias = schemas.NotAnyTypeSchema[U] +Id: typing_extensions.TypeAlias = schemas.Int64Schema[U] +PetId: typing_extensions.TypeAlias = schemas.Int64Schema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "id": typing.Type[Id], + "petId": typing.Type[PetId], + } +) + class NoAdditionalProperties( schemas.DictSchema[schemas.T] @@ -21,30 +32,24 @@ class NoAdditionalProperties( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "id", - } - - class Properties: - Id: typing_extensions.TypeAlias = schemas.Int64Schema[U] - PetId: typing_extensions.TypeAlias = schemas.Int64Schema[U] - __annotations__ = { - "id": Id, - "petId": PetId, - } - AdditionalProperties: typing_extensions.TypeAlias = schemas.NotAnyTypeSchema[U] + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore @property - def id(self) -> Schema_.Properties.Id[decimal.Decimal]: + def id(self) -> Id[decimal.Decimal]: return self.__getitem__("id") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["id"]) -> Schema_.Properties.Id[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["id"]) -> Id[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["petId"]) -> Schema_.Properties.PetId[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["petId"]) -> PetId[decimal.Decimal]: ... def __getitem__( self, @@ -60,12 +65,12 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], id: typing.Union[ - Schema_.Properties.Id[decimal.Decimal], + Id[decimal.Decimal], decimal.Decimal, int ], petId: typing.Union[ - Schema_.Properties.PetId[decimal.Decimal], + PetId[decimal.Decimal], schemas.Unset, decimal.Decimal, int @@ -84,3 +89,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/nullable_class.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/nullable_class.py index f135d99a9fd..2b8ea6e8279 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/nullable_class.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/nullable_class.py @@ -11,1009 +11,964 @@ from petstore_api.shared_imports.schema_imports import * -class NullableClass( - schemas.DictSchema[schemas.T] + +class AdditionalProperties4( + schemas.NoneBase, + schemas.DictBase, + schemas.Schema[schemas.T], + schemas.NoneFrozenDictMixin +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + schemas.NoneClass, + frozendict.frozendict, + }) + + + def __new__( + cls, + *args_: typing.Union[ + None, + dict, + frozendict.frozendict + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> AdditionalProperties4[ + typing.Union[ + schemas.NoneClass, + frozendict.frozendict + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + AdditionalProperties4[ + typing.Union[ + schemas.NoneClass, + frozendict.frozendict + ] + ], + inst + ) + return inst + + + +class IntegerProp( + schemas.NoneBase, + schemas.IntBase, + schemas.Schema[schemas.T], + schemas.NoneDecimalMixin +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + schemas.NoneClass, + decimal.Decimal, + }) + format: str = 'int' + + + def __new__( + cls, + arg_: typing.Union[ + None, + decimal.Decimal, + int + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> IntegerProp[ + typing.Union[ + schemas.NoneClass, + decimal.Decimal + ] + ]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + IntegerProp[ + typing.Union[ + schemas.NoneClass, + decimal.Decimal + ] + ], + inst + ) + return inst + + + +class NumberProp( + schemas.NoneBase, + schemas.NumberBase, + schemas.Schema[schemas.T], + schemas.NoneDecimalMixin +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + schemas.NoneClass, + decimal.Decimal, + }) + + + def __new__( + cls, + arg_: typing.Union[ + None, + decimal.Decimal, + int, + float + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> NumberProp[ + typing.Union[ + schemas.NoneClass, + decimal.Decimal + ] + ]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + NumberProp[ + typing.Union[ + schemas.NoneClass, + decimal.Decimal + ] + ], + inst + ) + return inst + + + +class BooleanProp( + schemas.NoneBase, + schemas.BoolBase, + schemas.Schema[schemas.T], + schemas.NoneBoolMixin +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + schemas.NoneClass, + schemas.BoolClass, + }) + + + def __new__( + cls, + arg_: typing.Union[ + None, + bool + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> BooleanProp[ + typing.Union[ + schemas.NoneClass, + schemas.BoolClass + ] + ]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + BooleanProp[ + typing.Union[ + schemas.NoneClass, + schemas.BoolClass + ] + ], + inst + ) + return inst + + + +class StringProp( + schemas.NoneBase, + schemas.StrBase, + schemas.Schema[schemas.T], + schemas.NoneStrMixin +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + schemas.NoneClass, + str, + }) + + + def __new__( + cls, + arg_: typing.Union[ + None, + str + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> StringProp[ + typing.Union[ + schemas.NoneClass, + str + ] + ]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + StringProp[ + typing.Union[ + schemas.NoneClass, + str + ] + ], + inst + ) + return inst + + + +class DateProp( + schemas.NoneBase, + schemas.DateBase, + schemas.StrBase, + schemas.Schema[schemas.T], + schemas.NoneStrMixin +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + schemas.NoneClass, + str, + }) + format: str = 'date' + + + def __new__( + cls, + arg_: typing.Union[ + None, + str, + datetime.date + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> DateProp[ + typing.Union[ + schemas.NoneClass, + str + ] + ]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + DateProp[ + typing.Union[ + schemas.NoneClass, + str + ] + ], + inst + ) + return inst + + + +class DatetimeProp( + schemas.NoneBase, + schemas.DateTimeBase, + schemas.StrBase, + schemas.Schema[schemas.T], + schemas.NoneStrMixin +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + schemas.NoneClass, + str, + }) + format: str = 'date-time' + + + def __new__( + cls, + arg_: typing.Union[ + None, + str, + datetime.datetime + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> DatetimeProp[ + typing.Union[ + schemas.NoneClass, + str + ] + ]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + DatetimeProp[ + typing.Union[ + schemas.NoneClass, + str + ] + ], + inst + ) + return inst + +Items: typing_extensions.TypeAlias = schemas.DictSchema[U] + + +class ArrayNullableProp( + schemas.NoneBase, + schemas.ListBase, + schemas.Schema[schemas.T], + schemas.NoneTupleMixin +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + schemas.NoneClass, + tuple, + }) + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore + + + def __new__( + cls, + arg_: typing.Union[ + None, + list, + tuple + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> ArrayNullableProp[ + typing.Union[ + schemas.NoneClass, + tuple + ] + ]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + ArrayNullableProp[ + typing.Union[ + schemas.NoneClass, + tuple + ] + ], + inst + ) + return inst + + + +class Items2( + schemas.NoneBase, + schemas.DictBase, + schemas.Schema[schemas.T], + schemas.NoneFrozenDictMixin +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + schemas.NoneClass, + frozendict.frozendict, + }) + + + def __new__( + cls, + *args_: typing.Union[ + None, + dict, + frozendict.frozendict + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> Items2[ + typing.Union[ + schemas.NoneClass, + frozendict.frozendict + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + Items2[ + typing.Union[ + schemas.NoneClass, + frozendict.frozendict + ] + ], + inst + ) + return inst + + + +class ArrayAndItemsNullableProp( + schemas.NoneBase, + schemas.ListBase, + schemas.Schema[schemas.T], + schemas.NoneTupleMixin +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + schemas.NoneClass, + tuple, + }) + items: typing.Type[Items2] = dataclasses.field(default_factory=lambda: Items2) # type: ignore + + + def __new__( + cls, + arg_: typing.Union[ + None, + list, + tuple + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> ArrayAndItemsNullableProp[ + typing.Union[ + schemas.NoneClass, + tuple + ] + ]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + ArrayAndItemsNullableProp[ + typing.Union[ + schemas.NoneClass, + tuple + ] + ], + inst + ) + return inst + + + +class Items3( + schemas.NoneBase, + schemas.DictBase, + schemas.Schema[schemas.T], + schemas.NoneFrozenDictMixin +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + schemas.NoneClass, + frozendict.frozendict, + }) + + + def __new__( + cls, + *args_: typing.Union[ + None, + dict, + frozendict.frozendict + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> Items3[ + typing.Union[ + schemas.NoneClass, + frozendict.frozendict + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + Items3[ + typing.Union[ + schemas.NoneClass, + frozendict.frozendict + ] + ], + inst + ) + return inst + + + +class ArrayItemsNullable( + schemas.ListSchema[schemas.T] ): - """NOTE: This class is auto generated by OpenAPI JSON Schema Generator. - Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator - Do not edit the class manually. - """ + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items3] = dataclasses.field(default_factory=lambda: Items3) # type: ignore - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - - class IntegerProp( - schemas.NoneBase, - schemas.IntBase, - schemas.Schema[schemas.T], - schemas.NoneDecimalMixin - ): - - - class Schema_: - types = { - schemas.NoneClass, - decimal.Decimal, - } - format = 'int' - - - def __new__( - cls, - arg_: typing.Union[ - None, - decimal.Decimal, - int - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> NullableClass.Schema_.Properties.IntegerProp[ - typing.Union[ - schemas.NoneClass, - decimal.Decimal - ] - ]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - NullableClass.Schema_.Properties.IntegerProp[ - typing.Union[ - schemas.NoneClass, - decimal.Decimal - ] - ], - inst - ) - return inst - - - class NumberProp( - schemas.NoneBase, - schemas.NumberBase, - schemas.Schema[schemas.T], - schemas.NoneDecimalMixin - ): - - - class Schema_: - types = { - schemas.NoneClass, - decimal.Decimal, - } - - - def __new__( - cls, - arg_: typing.Union[ - None, - decimal.Decimal, - int, - float - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> NullableClass.Schema_.Properties.NumberProp[ - typing.Union[ - schemas.NoneClass, - decimal.Decimal - ] - ]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - NullableClass.Schema_.Properties.NumberProp[ - typing.Union[ - schemas.NoneClass, - decimal.Decimal - ] - ], - inst - ) - return inst - - - class BooleanProp( - schemas.NoneBase, - schemas.BoolBase, - schemas.Schema[schemas.T], - schemas.NoneBoolMixin - ): - - - class Schema_: - types = { - schemas.NoneClass, - schemas.BoolClass, - } - - - def __new__( - cls, - arg_: typing.Union[ - None, - bool - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> NullableClass.Schema_.Properties.BooleanProp[ - typing.Union[ - schemas.NoneClass, - schemas.BoolClass - ] - ]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - NullableClass.Schema_.Properties.BooleanProp[ - typing.Union[ - schemas.NoneClass, - schemas.BoolClass - ] - ], - inst - ) - return inst - - - class StringProp( - schemas.NoneBase, - schemas.StrBase, - schemas.Schema[schemas.T], - schemas.NoneStrMixin - ): - - - class Schema_: - types = { - schemas.NoneClass, - str, - } - - - def __new__( - cls, - arg_: typing.Union[ - None, - str - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> NullableClass.Schema_.Properties.StringProp[ - typing.Union[ - schemas.NoneClass, - str - ] - ]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - NullableClass.Schema_.Properties.StringProp[ - typing.Union[ - schemas.NoneClass, - str - ] - ], - inst - ) - return inst - - - class DateProp( - schemas.NoneBase, - schemas.DateBase, - schemas.StrBase, - schemas.Schema[schemas.T], - schemas.NoneStrMixin - ): - - - class Schema_: - types = { - schemas.NoneClass, - str, - } - format = 'date' - - - def __new__( - cls, - arg_: typing.Union[ - None, - str, - datetime.date - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> NullableClass.Schema_.Properties.DateProp[ - typing.Union[ - schemas.NoneClass, - str - ] - ]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - NullableClass.Schema_.Properties.DateProp[ - typing.Union[ - schemas.NoneClass, - str - ] - ], - inst - ) - return inst - - - class DatetimeProp( - schemas.NoneBase, - schemas.DateTimeBase, - schemas.StrBase, - schemas.Schema[schemas.T], - schemas.NoneStrMixin - ): - - - class Schema_: - types = { - schemas.NoneClass, - str, - } - format = 'date-time' - - - def __new__( - cls, - arg_: typing.Union[ - None, - str, - datetime.datetime - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> NullableClass.Schema_.Properties.DatetimeProp[ - typing.Union[ - schemas.NoneClass, - str - ] - ]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - NullableClass.Schema_.Properties.DatetimeProp[ - typing.Union[ - schemas.NoneClass, - str - ] - ], - inst - ) - return inst - - - class ArrayNullableProp( - schemas.NoneBase, - schemas.ListBase, - schemas.Schema[schemas.T], - schemas.NoneTupleMixin - ): - - - class Schema_: - types = { - schemas.NoneClass, - tuple, - } - Items: typing_extensions.TypeAlias = schemas.DictSchema[U] - - - def __new__( - cls, - arg_: typing.Union[ - None, - list, - tuple - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> NullableClass.Schema_.Properties.ArrayNullableProp[ - typing.Union[ - schemas.NoneClass, - tuple - ] - ]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - NullableClass.Schema_.Properties.ArrayNullableProp[ - typing.Union[ - schemas.NoneClass, - tuple - ] - ], - inst - ) - return inst - - - class ArrayAndItemsNullableProp( - schemas.NoneBase, - schemas.ListBase, - schemas.Schema[schemas.T], - schemas.NoneTupleMixin - ): - - - class Schema_: - types = { - schemas.NoneClass, - tuple, - } - - - class Items( - schemas.NoneBase, - schemas.DictBase, - schemas.Schema[schemas.T], - schemas.NoneFrozenDictMixin - ): - - - class Schema_: - types = { - schemas.NoneClass, - frozendict.frozendict, - } - - - def __new__( - cls, - *args_: typing.Union[ - None, - dict, - frozendict.frozendict - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> NullableClass.Schema_.Properties.ArrayAndItemsNullableProp.Schema_.Items[ - typing.Union[ - schemas.NoneClass, - frozendict.frozendict - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - NullableClass.Schema_.Properties.ArrayAndItemsNullableProp.Schema_.Items[ - typing.Union[ - schemas.NoneClass, - frozendict.frozendict - ] - ], - inst - ) - return inst - - - def __new__( - cls, - arg_: typing.Union[ - None, - list, - tuple - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> NullableClass.Schema_.Properties.ArrayAndItemsNullableProp[ - typing.Union[ - schemas.NoneClass, - tuple - ] - ]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - NullableClass.Schema_.Properties.ArrayAndItemsNullableProp[ - typing.Union[ - schemas.NoneClass, - tuple - ] - ], - inst - ) - return inst - - - class ArrayItemsNullable( - schemas.ListSchema[schemas.T] - ): - - - class Schema_: - types = {tuple} - - - class Items( - schemas.NoneBase, - schemas.DictBase, - schemas.Schema[schemas.T], - schemas.NoneFrozenDictMixin - ): - - - class Schema_: - types = { - schemas.NoneClass, - frozendict.frozendict, - } - - - def __new__( - cls, - *args_: typing.Union[ - None, - dict, - frozendict.frozendict - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> NullableClass.Schema_.Properties.ArrayItemsNullable.Schema_.Items[ - typing.Union[ - schemas.NoneClass, - frozendict.frozendict - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - NullableClass.Schema_.Properties.ArrayItemsNullable.Schema_.Items[ - typing.Union[ - schemas.NoneClass, - frozendict.frozendict - ] - ], - inst - ) - return inst - - def __new__( - cls, - arg_: typing.Sequence[ - typing.Union[ - Schema_.Items[typing.Union[ - schemas.NoneClass, - frozendict.frozendict - ]], - None, - dict, - frozendict.frozendict - ] - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> NullableClass.Schema_.Properties.ArrayItemsNullable[tuple]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - NullableClass.Schema_.Properties.ArrayItemsNullable[tuple], - inst - ) - return inst - - def __getitem__(self, name: int) -> Schema_.Items[typing.Union[ + def __new__( + cls, + arg_: typing.Sequence[ + typing.Union[ + Items3[typing.Union[ schemas.NoneClass, frozendict.frozendict - ]]: - return super().__getitem__(name) - - - class ObjectNullableProp( - schemas.NoneBase, - schemas.DictBase, - schemas.Schema[schemas.T], - schemas.NoneFrozenDictMixin - ): - - - class Schema_: - types = { - schemas.NoneClass, - frozendict.frozendict, - } - AdditionalProperties: typing_extensions.TypeAlias = schemas.DictSchema[U] - - - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[frozendict.frozendict]: - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[ - None, - dict, - frozendict.frozendict - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - Schema_.AdditionalProperties[frozendict.frozendict], - dict, - frozendict.frozendict - ], - ) -> NullableClass.Schema_.Properties.ObjectNullableProp[ - typing.Union[ - schemas.NoneClass, - frozendict.frozendict - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - NullableClass.Schema_.Properties.ObjectNullableProp[ - typing.Union[ - schemas.NoneClass, - frozendict.frozendict - ] - ], - inst - ) - return inst - - - class ObjectAndItemsNullableProp( - schemas.NoneBase, - schemas.DictBase, - schemas.Schema[schemas.T], - schemas.NoneFrozenDictMixin - ): - - - class Schema_: - types = { - schemas.NoneClass, - frozendict.frozendict, - } - - - class AdditionalProperties( - schemas.NoneBase, - schemas.DictBase, - schemas.Schema[schemas.T], - schemas.NoneFrozenDictMixin - ): - - - class Schema_: - types = { - schemas.NoneClass, - frozendict.frozendict, - } - - - def __new__( - cls, - *args_: typing.Union[ - None, - dict, - frozendict.frozendict - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> NullableClass.Schema_.Properties.ObjectAndItemsNullableProp.Schema_.AdditionalProperties[ - typing.Union[ - schemas.NoneClass, - frozendict.frozendict - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - NullableClass.Schema_.Properties.ObjectAndItemsNullableProp.Schema_.AdditionalProperties[ - typing.Union[ - schemas.NoneClass, - frozendict.frozendict - ] - ], - inst - ) - return inst - - - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[typing.Union[ + ]], + None, + dict, + frozendict.frozendict + ] + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> ArrayItemsNullable[tuple]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + ArrayItemsNullable[tuple], + inst + ) + return inst + + def __getitem__(self, name: int) -> Items3[typing.Union[ + schemas.NoneClass, + frozendict.frozendict + ]]: + return super().__getitem__(name) + +AdditionalProperties: typing_extensions.TypeAlias = schemas.DictSchema[U] + + +class ObjectNullableProp( + schemas.NoneBase, + schemas.DictBase, + schemas.Schema[schemas.T], + schemas.NoneFrozenDictMixin +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + schemas.NoneClass, + frozendict.frozendict, + }) + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore + + + def __getitem__(self, name: str) -> AdditionalProperties[frozendict.frozendict]: + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[ + None, + dict, + frozendict.frozendict + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: typing.Union[ + AdditionalProperties[frozendict.frozendict], + dict, + frozendict.frozendict + ], + ) -> ObjectNullableProp[ + typing.Union[ + schemas.NoneClass, + frozendict.frozendict + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + ObjectNullableProp[ + typing.Union[ schemas.NoneClass, frozendict.frozendict - ]]: - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[ - None, - dict, - frozendict.frozendict - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - Schema_.AdditionalProperties[typing.Union[ - schemas.NoneClass, - frozendict.frozendict - ]], - None, - dict, - frozendict.frozendict - ], - ) -> NullableClass.Schema_.Properties.ObjectAndItemsNullableProp[ - typing.Union[ - schemas.NoneClass, - frozendict.frozendict - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - NullableClass.Schema_.Properties.ObjectAndItemsNullableProp[ - typing.Union[ - schemas.NoneClass, - frozendict.frozendict - ] - ], - inst - ) - return inst - - - class ObjectItemsNullable( - schemas.DictSchema[schemas.T] - ): - - - class Schema_: - types = {frozendict.frozendict} - - - class AdditionalProperties( - schemas.NoneBase, - schemas.DictBase, - schemas.Schema[schemas.T], - schemas.NoneFrozenDictMixin - ): - - - class Schema_: - types = { - schemas.NoneClass, - frozendict.frozendict, - } - - - def __new__( - cls, - *args_: typing.Union[ - None, - dict, - frozendict.frozendict - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> NullableClass.Schema_.Properties.ObjectItemsNullable.Schema_.AdditionalProperties[ - typing.Union[ - schemas.NoneClass, - frozendict.frozendict - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - NullableClass.Schema_.Properties.ObjectItemsNullable.Schema_.AdditionalProperties[ - typing.Union[ - schemas.NoneClass, - frozendict.frozendict - ] - ], - inst - ) - return inst - - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[typing.Union[ + ] + ], + inst + ) + return inst + + + +class AdditionalProperties2( + schemas.NoneBase, + schemas.DictBase, + schemas.Schema[schemas.T], + schemas.NoneFrozenDictMixin +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + schemas.NoneClass, + frozendict.frozendict, + }) + + + def __new__( + cls, + *args_: typing.Union[ + None, + dict, + frozendict.frozendict + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> AdditionalProperties2[ + typing.Union[ + schemas.NoneClass, + frozendict.frozendict + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + AdditionalProperties2[ + typing.Union[ schemas.NoneClass, frozendict.frozendict - ]]: - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[dict, frozendict.frozendict], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - Schema_.AdditionalProperties[typing.Union[ - schemas.NoneClass, - frozendict.frozendict - ]], - None, - dict, - frozendict.frozendict - ], - ) -> NullableClass.Schema_.Properties.ObjectItemsNullable[frozendict.frozendict]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - NullableClass.Schema_.Properties.ObjectItemsNullable[frozendict.frozendict], - inst - ) - return inst - __annotations__ = { - "integer_prop": IntegerProp, - "number_prop": NumberProp, - "boolean_prop": BooleanProp, - "string_prop": StringProp, - "date_prop": DateProp, - "datetime_prop": DatetimeProp, - "array_nullable_prop": ArrayNullableProp, - "array_and_items_nullable_prop": ArrayAndItemsNullableProp, - "array_items_nullable": ArrayItemsNullable, - "object_nullable_prop": ObjectNullableProp, - "object_and_items_nullable_prop": ObjectAndItemsNullableProp, - "object_items_nullable": ObjectItemsNullable, - } - - - class AdditionalProperties( - schemas.NoneBase, - schemas.DictBase, - schemas.Schema[schemas.T], - schemas.NoneFrozenDictMixin - ): - - - class Schema_: - types = { + ] + ], + inst + ) + return inst + + + +class ObjectAndItemsNullableProp( + schemas.NoneBase, + schemas.DictBase, + schemas.Schema[schemas.T], + schemas.NoneFrozenDictMixin +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + schemas.NoneClass, + frozendict.frozendict, + }) + additional_properties: typing.Type[AdditionalProperties2] = dataclasses.field(default_factory=lambda: AdditionalProperties2) # type: ignore + + + def __getitem__(self, name: str) -> AdditionalProperties2[typing.Union[ + schemas.NoneClass, + frozendict.frozendict + ]]: + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[ + None, + dict, + frozendict.frozendict + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: typing.Union[ + AdditionalProperties2[typing.Union[ + schemas.NoneClass, + frozendict.frozendict + ]], + None, + dict, + frozendict.frozendict + ], + ) -> ObjectAndItemsNullableProp[ + typing.Union[ + schemas.NoneClass, + frozendict.frozendict + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + ObjectAndItemsNullableProp[ + typing.Union[ schemas.NoneClass, - frozendict.frozendict, - } - - - def __new__( - cls, - *args_: typing.Union[ - None, - dict, frozendict.frozendict - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> NullableClass.Schema_.AdditionalProperties[ + ] + ], + inst + ) + return inst + + + +class AdditionalProperties3( + schemas.NoneBase, + schemas.DictBase, + schemas.Schema[schemas.T], + schemas.NoneFrozenDictMixin +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + schemas.NoneClass, + frozendict.frozendict, + }) + + + def __new__( + cls, + *args_: typing.Union[ + None, + dict, + frozendict.frozendict + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> AdditionalProperties3[ + typing.Union[ + schemas.NoneClass, + frozendict.frozendict + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + AdditionalProperties3[ typing.Union[ schemas.NoneClass, frozendict.frozendict ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - NullableClass.Schema_.AdditionalProperties[ - typing.Union[ - schemas.NoneClass, - frozendict.frozendict - ] - ], - inst - ) - return inst + ], + inst + ) + return inst + + + +class ObjectItemsNullable( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + additional_properties: typing.Type[AdditionalProperties3] = dataclasses.field(default_factory=lambda: AdditionalProperties3) # type: ignore + + def __getitem__(self, name: str) -> AdditionalProperties3[typing.Union[ + schemas.NoneClass, + frozendict.frozendict + ]]: + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: typing.Union[ + AdditionalProperties3[typing.Union[ + schemas.NoneClass, + frozendict.frozendict + ]], + None, + dict, + frozendict.frozendict + ], + ) -> ObjectItemsNullable[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + ObjectItemsNullable[frozendict.frozendict], + inst + ) + return inst + +Properties = typing_extensions.TypedDict( + 'Properties', + { + "integer_prop": typing.Type[IntegerProp], + "number_prop": typing.Type[NumberProp], + "boolean_prop": typing.Type[BooleanProp], + "string_prop": typing.Type[StringProp], + "date_prop": typing.Type[DateProp], + "datetime_prop": typing.Type[DatetimeProp], + "array_nullable_prop": typing.Type[ArrayNullableProp], + "array_and_items_nullable_prop": typing.Type[ArrayAndItemsNullableProp], + "array_items_nullable": typing.Type[ArrayItemsNullable], + "object_nullable_prop": typing.Type[ObjectNullableProp], + "object_and_items_nullable_prop": typing.Type[ObjectAndItemsNullableProp], + "object_items_nullable": typing.Type[ObjectItemsNullable], + } +) + + +class NullableClass( + schemas.DictSchema[schemas.T] +): + """NOTE: This class is auto generated by OpenAPI JSON Schema Generator. + Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator + + Do not edit the class manually. + """ + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + additional_properties: typing.Type[AdditionalProperties4] = dataclasses.field(default_factory=lambda: AdditionalProperties4) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["integer_prop"]) -> Schema_.Properties.IntegerProp[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["integer_prop"]) -> IntegerProp[typing.Union[ schemas.NoneClass, decimal.Decimal ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["number_prop"]) -> Schema_.Properties.NumberProp[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["number_prop"]) -> NumberProp[typing.Union[ schemas.NoneClass, decimal.Decimal ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["boolean_prop"]) -> Schema_.Properties.BooleanProp[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["boolean_prop"]) -> BooleanProp[typing.Union[ schemas.NoneClass, schemas.BoolClass ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["string_prop"]) -> Schema_.Properties.StringProp[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["string_prop"]) -> StringProp[typing.Union[ schemas.NoneClass, str ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["date_prop"]) -> Schema_.Properties.DateProp[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["date_prop"]) -> DateProp[typing.Union[ schemas.NoneClass, str ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["datetime_prop"]) -> Schema_.Properties.DatetimeProp[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["datetime_prop"]) -> DatetimeProp[typing.Union[ schemas.NoneClass, str ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["array_nullable_prop"]) -> Schema_.Properties.ArrayNullableProp[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["array_nullable_prop"]) -> ArrayNullableProp[typing.Union[ schemas.NoneClass, tuple ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["array_and_items_nullable_prop"]) -> Schema_.Properties.ArrayAndItemsNullableProp[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["array_and_items_nullable_prop"]) -> ArrayAndItemsNullableProp[typing.Union[ schemas.NoneClass, tuple ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["array_items_nullable"]) -> Schema_.Properties.ArrayItemsNullable[tuple]: ... + def __getitem__(self, name: typing_extensions.Literal["array_items_nullable"]) -> ArrayItemsNullable[tuple]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["object_nullable_prop"]) -> Schema_.Properties.ObjectNullableProp[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["object_nullable_prop"]) -> ObjectNullableProp[typing.Union[ schemas.NoneClass, frozendict.frozendict ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["object_and_items_nullable_prop"]) -> Schema_.Properties.ObjectAndItemsNullableProp[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["object_and_items_nullable_prop"]) -> ObjectAndItemsNullableProp[typing.Union[ schemas.NoneClass, frozendict.frozendict ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["object_items_nullable"]) -> Schema_.Properties.ObjectItemsNullable[frozendict.frozendict]: ... + def __getitem__(self, name: typing_extensions.Literal["object_items_nullable"]) -> ObjectItemsNullable[frozendict.frozendict]: ... @typing.overload - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[typing.Union[ + def __getitem__(self, name: str) -> AdditionalProperties4[typing.Union[ schemas.NoneClass, frozendict.frozendict ]]: ... @@ -1043,7 +998,7 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], integer_prop: typing.Union[ - Schema_.Properties.IntegerProp[typing.Union[ + IntegerProp[typing.Union[ schemas.NoneClass, decimal.Decimal ]], @@ -1053,7 +1008,7 @@ def __new__( int ] = schemas.unset, number_prop: typing.Union[ - Schema_.Properties.NumberProp[typing.Union[ + NumberProp[typing.Union[ schemas.NoneClass, decimal.Decimal ]], @@ -1064,7 +1019,7 @@ def __new__( float ] = schemas.unset, boolean_prop: typing.Union[ - Schema_.Properties.BooleanProp[typing.Union[ + BooleanProp[typing.Union[ schemas.NoneClass, schemas.BoolClass ]], @@ -1073,7 +1028,7 @@ def __new__( bool ] = schemas.unset, string_prop: typing.Union[ - Schema_.Properties.StringProp[typing.Union[ + StringProp[typing.Union[ schemas.NoneClass, str ]], @@ -1082,7 +1037,7 @@ def __new__( str ] = schemas.unset, date_prop: typing.Union[ - Schema_.Properties.DateProp[typing.Union[ + DateProp[typing.Union[ schemas.NoneClass, str ]], @@ -1092,7 +1047,7 @@ def __new__( datetime.date ] = schemas.unset, datetime_prop: typing.Union[ - Schema_.Properties.DatetimeProp[typing.Union[ + DatetimeProp[typing.Union[ schemas.NoneClass, str ]], @@ -1102,7 +1057,7 @@ def __new__( datetime.datetime ] = schemas.unset, array_nullable_prop: typing.Union[ - Schema_.Properties.ArrayNullableProp[typing.Union[ + ArrayNullableProp[typing.Union[ schemas.NoneClass, tuple ]], @@ -1112,7 +1067,7 @@ def __new__( tuple ] = schemas.unset, array_and_items_nullable_prop: typing.Union[ - Schema_.Properties.ArrayAndItemsNullableProp[typing.Union[ + ArrayAndItemsNullableProp[typing.Union[ schemas.NoneClass, tuple ]], @@ -1122,13 +1077,13 @@ def __new__( tuple ] = schemas.unset, array_items_nullable: typing.Union[ - Schema_.Properties.ArrayItemsNullable[tuple], + ArrayItemsNullable[tuple], schemas.Unset, list, tuple ] = schemas.unset, object_nullable_prop: typing.Union[ - Schema_.Properties.ObjectNullableProp[typing.Union[ + ObjectNullableProp[typing.Union[ schemas.NoneClass, frozendict.frozendict ]], @@ -1138,7 +1093,7 @@ def __new__( frozendict.frozendict ] = schemas.unset, object_and_items_nullable_prop: typing.Union[ - Schema_.Properties.ObjectAndItemsNullableProp[typing.Union[ + ObjectAndItemsNullableProp[typing.Union[ schemas.NoneClass, frozendict.frozendict ]], @@ -1148,14 +1103,14 @@ def __new__( frozendict.frozendict ] = schemas.unset, object_items_nullable: typing.Union[ - Schema_.Properties.ObjectItemsNullable[frozendict.frozendict], + ObjectItemsNullable[frozendict.frozendict], schemas.Unset, dict, frozendict.frozendict ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, **kwargs: typing.Union[ - Schema_.AdditionalProperties[typing.Union[ + AdditionalProperties4[typing.Union[ schemas.NoneClass, frozendict.frozendict ]], @@ -1187,3 +1142,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/nullable_shape.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/nullable_shape.py index 5173f0d6e46..865f9fce8af 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/nullable_shape.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/nullable_shape.py @@ -10,6 +10,8 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +_2: typing_extensions.TypeAlias = schemas.NoneSchema[U] + class NullableShape( schemas.AnyTypeSchema[schemas.T], @@ -23,66 +25,17 @@ class NullableShape( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class OneOf: - - @staticmethod - def _0() -> typing.Type[triangle.Triangle]: - return triangle.Triangle - - @staticmethod - def _1() -> typing.Type[quadrilateral.Quadrilateral]: - return quadrilateral.Quadrilateral - _2: typing_extensions.TypeAlias = schemas.NoneSchema[U] - classes = [ - _0, - _1, - _2, - ] + one_of: OneOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(OneOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> NullableShape[ typing.Union[ frozendict.frozendict, @@ -118,5 +71,11 @@ def __new__( ) return inst + from petstore_api.components.schema import quadrilateral from petstore_api.components.schema import triangle +OneOf = typing.Tuple[ + typing.Type[triangle.Triangle], + typing.Type[quadrilateral.Quadrilateral], + typing.Type[_2[schemas.U]], +] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/nullable_string.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/nullable_string.py index 34c036be5c0..370bd0d2e5f 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/nullable_string.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/nullable_string.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class NullableString( schemas.NoneBase, schemas.StrBase, @@ -24,11 +25,12 @@ class NullableString( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ schemas.NoneClass, str, - } + }) def __new__( @@ -59,3 +61,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/number.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/number.py index 7223c781576..286584e8a0d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/number.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/number.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Number: typing_extensions.TypeAlias = schemas.NumberSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/number_only.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/number_only.py index db95837f2d8..8bcece3d2c1 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/number_only.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/number_only.py @@ -10,6 +10,14 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +JustNumber: typing_extensions.TypeAlias = schemas.NumberSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "JustNumber": typing.Type[JustNumber], + } +) + class NumberOnly( schemas.DictSchema[schemas.T] @@ -21,17 +29,13 @@ class NumberOnly( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - JustNumber: typing_extensions.TypeAlias = schemas.NumberSchema[U] - __annotations__ = { - "JustNumber": JustNumber, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["JustNumber"]) -> Schema_.Properties.JustNumber[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["JustNumber"]) -> JustNumber[decimal.Decimal]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -59,32 +63,14 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], JustNumber: typing.Union[ - Schema_.Properties.JustNumber[decimal.Decimal], + JustNumber[decimal.Decimal], schemas.Unset, decimal.Decimal, int, float ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> NumberOnly[frozendict.frozendict]: inst = super().__new__( cls, @@ -98,3 +84,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/number_with_validations.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/number_with_validations.py index e4ecb4068af..3124211076b 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/number_with_validations.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/number_with_validations.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class NumberWithValidations( schemas.NumberSchema[schemas.T] ): @@ -21,9 +22,10 @@ class NumberWithValidations( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ decimal.Decimal, - } - inclusive_maximum = 20 - inclusive_minimum = 10 + }) + inclusive_maximum: typing.Union[int, float] = 20 + inclusive_minimum: typing.Union[int, float] = 10 diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/obj_with_required_props.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/obj_with_required_props.py index 82f155d961d..da03021b6ba 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/obj_with_required_props.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/obj_with_required_props.py @@ -10,6 +10,14 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +A: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "a": typing.Type[A], + } +) + class ObjWithRequiredProps( schemas.DictSchema[schemas.T] @@ -21,36 +29,24 @@ class ObjWithRequiredProps( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ frozendict.frozendict, - } - required = { + }) + required: typing.FrozenSet[str] = frozenset({ "a", - } - - class Properties: - A: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "a": A, - } - - class AllOf: - - @staticmethod - def _0() -> typing.Type[obj_with_required_props_base.ObjWithRequiredPropsBase]: - return obj_with_required_props_base.ObjWithRequiredPropsBase - classes = [ - _0, - ] + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore @property - def a(self) -> Schema_.Properties.A[str]: + def a(self) -> A[str]: return self.__getitem__("a") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["a"]) -> Schema_.Properties.A[str]: ... + def __getitem__(self, name: typing_extensions.Literal["a"]) -> A[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -78,29 +74,11 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], a: typing.Union[ - Schema_.Properties.A[str], + A[str], str ], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ObjWithRequiredProps[frozendict.frozendict]: inst = super().__new__( cls, @@ -115,4 +93,8 @@ def __new__( ) return inst + from petstore_api.components.schema import obj_with_required_props_base +AllOf = typing.Tuple[ + typing.Type[obj_with_required_props_base.ObjWithRequiredPropsBase], +] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/obj_with_required_props_base.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/obj_with_required_props_base.py index e3483dbd79b..590dd9a243a 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/obj_with_required_props_base.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/obj_with_required_props_base.py @@ -10,6 +10,14 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +B: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "b": typing.Type[B], + } +) + class ObjWithRequiredPropsBase( schemas.DictSchema[schemas.T] @@ -21,24 +29,20 @@ class ObjWithRequiredPropsBase( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "b", - } - - class Properties: - B: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "b": B, - } + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @property - def b(self) -> Schema_.Properties.B[str]: + def b(self) -> B[str]: return self.__getitem__("b") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["b"]) -> Schema_.Properties.B[str]: ... + def __getitem__(self, name: typing_extensions.Literal["b"]) -> B[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -66,29 +70,11 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], b: typing.Union[ - Schema_.Properties.B[str], + B[str], str ], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ObjWithRequiredPropsBase[frozendict.frozendict]: inst = super().__new__( cls, @@ -102,3 +88,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_interface.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_interface.py index deb072f7277..1a3c6279e36 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_interface.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_interface.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + ObjectInterface: typing_extensions.TypeAlias = schemas.DictSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_model_with_arg_and_args_properties.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_model_with_arg_and_args_properties.py index f42727d5f13..ead4af0d999 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_model_with_arg_and_args_properties.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_model_with_arg_and_args_properties.py @@ -10,6 +10,16 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Arg: typing_extensions.TypeAlias = schemas.StrSchema[U] +Args: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "arg": typing.Type[Arg], + "args": typing.Type[Args], + } +) + class ObjectModelWithArgAndArgsProperties( schemas.DictSchema[schemas.T] @@ -21,34 +31,28 @@ class ObjectModelWithArgAndArgsProperties( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "arg", "args", - } - - class Properties: - Arg: typing_extensions.TypeAlias = schemas.StrSchema[U] - Args: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "arg": Arg, - "args": Args, - } + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @property - def arg(self) -> Schema_.Properties.Arg[str]: + def arg(self) -> Arg[str]: return self.__getitem__("arg") @property - def args(self) -> Schema_.Properties.Args[str]: + def args(self) -> Args[str]: return self.__getitem__("args") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["arg"]) -> Schema_.Properties.Arg[str]: ... + def __getitem__(self, name: typing_extensions.Literal["arg"]) -> Arg[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["args"]) -> Schema_.Properties.Args[str]: ... + def __getitem__(self, name: typing_extensions.Literal["args"]) -> Args[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -77,33 +81,15 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], arg: typing.Union[ - Schema_.Properties.Arg[str], + Arg[str], str ], args: typing.Union[ - Schema_.Properties.Args[str], + Args[str], str ], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ObjectModelWithArgAndArgsProperties[frozendict.frozendict]: inst = super().__new__( cls, @@ -118,3 +104,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_model_with_ref_props.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_model_with_ref_props.py index e35fd590971..2261f087a7c 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_model_with_ref_props.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_model_with_ref_props.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class ObjectModelWithRefProps( schemas.DictSchema[schemas.T] ): @@ -23,27 +24,10 @@ class ObjectModelWithRefProps( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - @staticmethod - def my_number() -> typing.Type[number_with_validations.NumberWithValidations]: - return number_with_validations.NumberWithValidations - - @staticmethod - def my_string() -> typing.Type[string.String]: - return string.String - - @staticmethod - def my_boolean() -> typing.Type[boolean.Boolean]: - return boolean.Boolean - __annotations__ = { - "myNumber": my_number, - "myString": my_string, - "myBoolean": my_boolean, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload def __getitem__(self, name: typing_extensions.Literal["myNumber"]) -> number_with_validations.NumberWithValidations[decimal.Decimal]: ... @@ -99,25 +83,7 @@ def __new__( bool ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ObjectModelWithRefProps[frozendict.frozendict]: inst = super().__new__( cls, @@ -134,6 +100,15 @@ def __new__( ) return inst + from petstore_api.components.schema import boolean from petstore_api.components.schema import number_with_validations from petstore_api.components.schema import string +Properties = typing_extensions.TypedDict( + 'Properties', + { + "myNumber": typing.Type[number_with_validations.NumberWithValidations], + "myString": typing.Type[string.String], + "myBoolean": typing.Type[boolean.Boolean], + } +) diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_all_of_with_req_test_prop_from_unset_add_prop.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_all_of_with_req_test_prop_from_unset_add_prop.py index 0ffaf4c6890..130b8c010df 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_all_of_with_req_test_prop_from_unset_add_prop.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_all_of_with_req_test_prop_from_unset_add_prop.py @@ -10,164 +10,89 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Name: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "name": typing.Type[Name], + } +) -class ObjectWithAllOfWithReqTestPropFromUnsetAddProp( - schemas.AnyTypeSchema[schemas.T], -): - """NOTE: This class is auto generated by OpenAPI JSON Schema Generator. - Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator - Do not edit the class manually. - """ +class _1( + schemas.DictSchema[schemas.T] +): - class Schema_: - # any type - - class AllOf: - - @staticmethod - def _0() -> typing.Type[object_with_optional_test_prop.ObjectWithOptionalTestProp]: - return object_with_optional_test_prop.ObjectWithOptionalTestProp - - - class _1( - schemas.DictSchema[schemas.T] - ): - - - class Schema_: - types = {frozendict.frozendict} - required = { - "test", - } - - class Properties: - Name: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "name": Name, - } - - @property - def test(self) -> schemas.AnyTypeSchema[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: - return self.__getitem__("test") - - @typing.overload - def __getitem__(self, name: typing_extensions.Literal["test"]) -> schemas.AnyTypeSchema[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: ... - - @typing.overload - def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: ... - - def __getitem__( - self, - name: typing.Union[ - typing_extensions.Literal["test"], - str - ] - ): - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[dict, frozendict.frozendict], - test: typing.Union[ - schemas.AnyTypeSchema[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> ObjectWithAllOfWithReqTestPropFromUnsetAddProp.Schema_.AllOf._1[frozendict.frozendict]: - inst = super().__new__( - cls, - *args_, - test=test, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - ObjectWithAllOfWithReqTestPropFromUnsetAddProp.Schema_.AllOf._1[frozendict.frozendict], - inst - ) - return inst - classes = [ - _0, - _1, - ] - + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ + "test", + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + + @property + def test(self) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: + return self.__getitem__("test") + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["test"]) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + @typing.overload + def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + def __getitem__( + self, + name: typing.Union[ + typing_extensions.Literal["test"], + str + ] + ): + # dict_instance[name] accessor + return super().__getitem__(name) def __new__( cls, - *args_: typing.Union[ + *args_: typing.Union[dict, frozendict.frozendict], + test: typing.Union[ + schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]], dict, frozendict.frozendict, str, @@ -186,25 +111,44 @@ def __new__( io.BufferedReader ], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _1[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + test=test, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _1[frozendict.frozendict], + inst + ) + return inst + + + +class ObjectWithAllOfWithReqTestPropFromUnsetAddProp( + schemas.AnyTypeSchema[schemas.T], +): + """NOTE: This class is auto generated by OpenAPI JSON Schema Generator. + Ref: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator + + Do not edit the class manually. + """ + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ObjectWithAllOfWithReqTestPropFromUnsetAddProp[ typing.Union[ frozendict.frozendict, @@ -240,4 +184,9 @@ def __new__( ) return inst + from petstore_api.components.schema import object_with_optional_test_prop +AllOf = typing.Tuple[ + typing.Type[object_with_optional_test_prop.ObjectWithOptionalTestProp], + typing.Type[_1[schemas.U]], +] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_colliding_properties.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_colliding_properties.py index 6692d939808..7798070f06c 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_colliding_properties.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_colliding_properties.py @@ -10,6 +10,16 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +SomeProp: typing_extensions.TypeAlias = schemas.DictSchema[U] +Someprop: typing_extensions.TypeAlias = schemas.DictSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "someProp": typing.Type[SomeProp], + "someprop": typing.Type[Someprop], + } +) + class ObjectWithCollidingProperties( schemas.DictSchema[schemas.T] @@ -23,22 +33,16 @@ class ObjectWithCollidingProperties( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - SomeProp: typing_extensions.TypeAlias = schemas.DictSchema[U] - Someprop: typing_extensions.TypeAlias = schemas.DictSchema[U] - __annotations__ = { - "someProp": SomeProp, - "someprop": Someprop, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["someProp"]) -> Schema_.Properties.SomeProp[frozendict.frozendict]: ... + def __getitem__(self, name: typing_extensions.Literal["someProp"]) -> SomeProp[frozendict.frozendict]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["someprop"]) -> Schema_.Properties.Someprop[frozendict.frozendict]: ... + def __getitem__(self, name: typing_extensions.Literal["someprop"]) -> Someprop[frozendict.frozendict]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -67,37 +71,19 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], someProp: typing.Union[ - Schema_.Properties.SomeProp[frozendict.frozendict], + SomeProp[frozendict.frozendict], schemas.Unset, dict, frozendict.frozendict ] = schemas.unset, someprop: typing.Union[ - Schema_.Properties.Someprop[frozendict.frozendict], + Someprop[frozendict.frozendict], schemas.Unset, dict, frozendict.frozendict ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ObjectWithCollidingProperties[frozendict.frozendict]: inst = super().__new__( cls, @@ -112,3 +98,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_decimal_properties.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_decimal_properties.py index 90205445f49..eb3591c2111 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_decimal_properties.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_decimal_properties.py @@ -10,6 +10,8 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Width: typing_extensions.TypeAlias = schemas.DecimalSchema[U] + class ObjectWithDecimalProperties( schemas.DictSchema[schemas.T] @@ -21,30 +23,16 @@ class ObjectWithDecimalProperties( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - @staticmethod - def length() -> typing.Type[decimal_payload.DecimalPayload]: - return decimal_payload.DecimalPayload - Width: typing_extensions.TypeAlias = schemas.DecimalSchema[U] - - @staticmethod - def cost() -> typing.Type[money.Money]: - return money.Money - __annotations__ = { - "length": length, - "width": Width, - "cost": cost, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload def __getitem__(self, name: typing_extensions.Literal["length"]) -> decimal_payload.DecimalPayload[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["width"]) -> Schema_.Properties.Width[str]: ... + def __getitem__(self, name: typing_extensions.Literal["width"]) -> Width[str]: ... @typing.overload def __getitem__(self, name: typing_extensions.Literal["cost"]) -> money.Money[frozendict.frozendict]: ... @@ -82,7 +70,7 @@ def __new__( str ] = schemas.unset, width: typing.Union[ - Schema_.Properties.Width[str], + Width[str], schemas.Unset, str ] = schemas.unset, @@ -93,25 +81,7 @@ def __new__( frozendict.frozendict ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ObjectWithDecimalProperties[frozendict.frozendict]: inst = super().__new__( cls, @@ -128,5 +98,14 @@ def __new__( ) return inst + from petstore_api.components.schema import decimal_payload from petstore_api.components.schema import money +Properties = typing_extensions.TypedDict( + 'Properties', + { + "length": typing.Type[decimal_payload.DecimalPayload], + "width": typing.Type[Width], + "cost": typing.Type[money.Money], + } +) diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_difficultly_named_props.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_difficultly_named_props.py index 375f630e55b..42af75085ad 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_difficultly_named_props.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_difficultly_named_props.py @@ -10,6 +10,18 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +SpecialPropertyName: typing_extensions.TypeAlias = schemas.Int64Schema[U] +_123List: typing_extensions.TypeAlias = schemas.StrSchema[U] +_123Number: typing_extensions.TypeAlias = schemas.IntSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "$special[property.name]": typing.Type[SpecialPropertyName], + "123-list": typing.Type[_123List], + "123Number": typing.Type[_123Number], + } +) + class ObjectWithDifficultlyNamedProps( schemas.DictSchema[schemas.T] @@ -23,30 +35,22 @@ class ObjectWithDifficultlyNamedProps( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "123-list", - } - - class Properties: - SpecialPropertyName: typing_extensions.TypeAlias = schemas.Int64Schema[U] - _123List: typing_extensions.TypeAlias = schemas.StrSchema[U] - _123Number: typing_extensions.TypeAlias = schemas.IntSchema[U] - __annotations__ = { - "$special[property.name]": SpecialPropertyName, - "123-list": _123List, - "123Number": _123Number, - } + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["123-list"]) -> Schema_.Properties._123List[str]: ... + def __getitem__(self, name: typing_extensions.Literal["123-list"]) -> _123List[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["$special[property.name]"]) -> Schema_.Properties.SpecialPropertyName[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["$special[property.name]"]) -> SpecialPropertyName[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["123Number"]) -> Schema_.Properties._123Number[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["123Number"]) -> _123Number[decimal.Decimal]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -76,25 +80,7 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ObjectWithDifficultlyNamedProps[frozendict.frozendict]: inst = super().__new__( cls, @@ -107,3 +93,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_inline_composition_property.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_inline_composition_property.py index 61c8b3b21da..b453d2c40a8 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_inline_composition_property.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_inline_composition_property.py @@ -11,6 +11,82 @@ from petstore_api.shared_imports.schema_imports import * + +class _0( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + min_length: int = 1 +AllOf = typing.Tuple[ + typing.Type[_0[schemas.U]], +] + + +class SomeProp( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> SomeProp[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + SomeProp[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + +Properties = typing_extensions.TypedDict( + 'Properties', + { + "someProp": typing.Type[SomeProp], + } +) + + class ObjectWithInlineCompositionProperty( schemas.DictSchema[schemas.T] ): @@ -21,118 +97,13 @@ class ObjectWithInlineCompositionProperty( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - - class SomeProp( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - - class AllOf: - - - class _0( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - min_length = 1 - classes = [ - _0, - ] - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> ObjectWithInlineCompositionProperty.Schema_.Properties.SomeProp[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - ObjectWithInlineCompositionProperty.Schema_.Properties.SomeProp[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - __annotations__ = { - "someProp": SomeProp, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["someProp"]) -> Schema_.Properties.SomeProp[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["someProp"]) -> SomeProp[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -169,16 +140,9 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], someProp: typing.Union[ - Schema_.Properties.SomeProp[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + SomeProp[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -198,25 +162,7 @@ def __new__( io.BufferedReader ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ObjectWithInlineCompositionProperty[frozendict.frozendict]: inst = super().__new__( cls, @@ -230,3 +176,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_invalid_named_refed_properties.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_invalid_named_refed_properties.py index 797bdd494b7..85868d2ac42 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_invalid_named_refed_properties.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_invalid_named_refed_properties.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class ObjectWithInvalidNamedRefedProperties( schemas.DictSchema[schemas.T] ): @@ -21,26 +22,14 @@ class ObjectWithInvalidNamedRefedProperties( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "!reference", "from", - } - - class Properties: - - @staticmethod - def _from() -> typing.Type[from_schema.FromSchema]: - return from_schema.FromSchema - - @staticmethod - def reference() -> typing.Type[array_with_validations_in_items.ArrayWithValidationsInItems]: - return array_with_validations_in_items.ArrayWithValidationsInItems - __annotations__ = { - "from": _from, - "!reference": reference, - } + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload def __getitem__(self, name: typing_extensions.Literal["!reference"]) -> array_with_validations_in_items.ArrayWithValidationsInItems[tuple]: ... @@ -75,25 +64,7 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ObjectWithInvalidNamedRefedProperties[frozendict.frozendict]: inst = super().__new__( cls, @@ -107,5 +78,13 @@ def __new__( ) return inst + from petstore_api.components.schema import array_with_validations_in_items from petstore_api.components.schema import from_schema +Properties = typing_extensions.TypedDict( + 'Properties', + { + "from": typing.Type[from_schema.FromSchema], + "!reference": typing.Type[array_with_validations_in_items.ArrayWithValidationsInItems], + } +) diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_optional_test_prop.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_optional_test_prop.py index fe8cf9985f3..44ec291f01e 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_optional_test_prop.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_optional_test_prop.py @@ -10,6 +10,14 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Test: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "test": typing.Type[Test], + } +) + class ObjectWithOptionalTestProp( schemas.DictSchema[schemas.T] @@ -21,17 +29,13 @@ class ObjectWithOptionalTestProp( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - Test: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "test": Test, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["test"]) -> Schema_.Properties.Test[str]: ... + def __getitem__(self, name: typing_extensions.Literal["test"]) -> Test[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -59,30 +63,12 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], test: typing.Union[ - Schema_.Properties.Test[str], + Test[str], schemas.Unset, str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ObjectWithOptionalTestProp[frozendict.frozendict]: inst = super().__new__( cls, @@ -96,3 +82,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_validations.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_validations.py index ec7fc27394b..5bdfe49fed1 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_validations.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/object_with_validations.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class ObjectWithValidations( schemas.DictSchema[schemas.T] ): @@ -21,33 +22,16 @@ class ObjectWithValidations( """ - class Schema_: - types = {frozendict.frozendict} - min_properties = 2 + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + min_properties: int = 2 def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ObjectWithValidations[frozendict.frozendict]: inst = super().__new__( cls, @@ -60,3 +44,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/order.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/order.py index d2c647606e6..49432fa0f9b 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/order.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/order.py @@ -10,6 +10,66 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Id: typing_extensions.TypeAlias = schemas.Int64Schema[U] +PetId: typing_extensions.TypeAlias = schemas.Int64Schema[U] +Quantity: typing_extensions.TypeAlias = schemas.Int32Schema[U] +ShipDate: typing_extensions.TypeAlias = schemas.DateTimeSchema[U] + + +class Status( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "placed": "PLACED", + "approved": "APPROVED", + "delivered": "DELIVERED", + } + ) + + @schemas.classproperty + def PLACED(cls) -> Status[str]: + return cls("placed") # type: ignore + + @schemas.classproperty + def APPROVED(cls) -> Status[str]: + return cls("approved") # type: ignore + + @schemas.classproperty + def DELIVERED(cls) -> Status[str]: + return cls("delivered") # type: ignore + + +class Complete( + schemas.BoolSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + schemas.BoolClass, + }) + default: schemas.BoolClass = schemas.BoolClass.FALSE +Properties = typing_extensions.TypedDict( + 'Properties', + { + "id": typing.Type[Id], + "petId": typing.Type[PetId], + "quantity": typing.Type[Quantity], + "shipDate": typing.Type[ShipDate], + "status": typing.Type[Status], + "complete": typing.Type[Complete], + } +) + class Order( schemas.DictSchema[schemas.T] @@ -21,80 +81,28 @@ class Order( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - Id: typing_extensions.TypeAlias = schemas.Int64Schema[U] - PetId: typing_extensions.TypeAlias = schemas.Int64Schema[U] - Quantity: typing_extensions.TypeAlias = schemas.Int32Schema[U] - ShipDate: typing_extensions.TypeAlias = schemas.DateTimeSchema[U] - - - class Status( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - enum_value_to_name = { - "placed": "PLACED", - "approved": "APPROVED", - "delivered": "DELIVERED", - } - - @schemas.classproperty - def PLACED(cls): - return cls("placed") # type: ignore - - @schemas.classproperty - def APPROVED(cls): - return cls("approved") # type: ignore - - @schemas.classproperty - def DELIVERED(cls): - return cls("delivered") # type: ignore - - - class Complete( - schemas.BoolSchema[schemas.T] - ): - - - class Schema_: - types = { - schemas.BoolClass, - } - default = schemas.BoolClass.FALSE - __annotations__ = { - "id": Id, - "petId": PetId, - "quantity": Quantity, - "shipDate": ShipDate, - "status": Status, - "complete": Complete, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["id"]) -> Schema_.Properties.Id[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["id"]) -> Id[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["petId"]) -> Schema_.Properties.PetId[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["petId"]) -> PetId[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["quantity"]) -> Schema_.Properties.Quantity[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["quantity"]) -> Quantity[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["shipDate"]) -> Schema_.Properties.ShipDate[str]: ... + def __getitem__(self, name: typing_extensions.Literal["shipDate"]) -> ShipDate[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["status"]) -> Schema_.Properties.Status[str]: ... + def __getitem__(self, name: typing_extensions.Literal["status"]) -> Status[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["complete"]) -> Schema_.Properties.Complete[schemas.BoolClass]: ... + def __getitem__(self, name: typing_extensions.Literal["complete"]) -> Complete[schemas.BoolClass]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -127,59 +135,41 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], id: typing.Union[ - Schema_.Properties.Id[decimal.Decimal], + Id[decimal.Decimal], schemas.Unset, decimal.Decimal, int ] = schemas.unset, petId: typing.Union[ - Schema_.Properties.PetId[decimal.Decimal], + PetId[decimal.Decimal], schemas.Unset, decimal.Decimal, int ] = schemas.unset, quantity: typing.Union[ - Schema_.Properties.Quantity[decimal.Decimal], + Quantity[decimal.Decimal], schemas.Unset, decimal.Decimal, int ] = schemas.unset, shipDate: typing.Union[ - Schema_.Properties.ShipDate[str], + ShipDate[str], schemas.Unset, str, datetime.datetime ] = schemas.unset, status: typing.Union[ - Schema_.Properties.Status[str], + Status[str], schemas.Unset, str ] = schemas.unset, complete: typing.Union[ - Schema_.Properties.Complete[schemas.BoolClass], + Complete[schemas.BoolClass], schemas.Unset, bool ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Order[frozendict.frozendict]: inst = super().__new__( cls, @@ -198,3 +188,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/parent_pet.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/parent_pet.py index 80b036939f4..34022ad2b04 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/parent_pet.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/parent_pet.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class ParentPet( schemas.DictSchema[schemas.T] ): @@ -21,52 +22,26 @@ class ParentPet( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ frozendict.frozendict, - } - - @staticmethod - def discriminator(): - return { + }) + discriminator: typing.Mapping[str, typing.Mapping[str, typing.Type[schemas.Schema]]] = dataclasses.field( + default_factory=lambda: { 'pet_type': { 'ChildCat': child_cat.ChildCat, } } - - class AllOf: - - @staticmethod - def _0() -> typing.Type[grandparent_animal.GrandparentAnimal]: - return grandparent_animal.GrandparentAnimal - classes = [ - _0, - ] + ) + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ParentPet[frozendict.frozendict]: inst = super().__new__( cls, @@ -80,5 +55,9 @@ def __new__( ) return inst + from petstore_api.components.schema import child_cat from petstore_api.components.schema import grandparent_animal +AllOf = typing.Tuple[ + typing.Type[grandparent_animal.GrandparentAnimal], +] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/pet.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/pet.py index 2b03afede87..678ac329d03 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/pet.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/pet.py @@ -10,6 +10,114 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Id: typing_extensions.TypeAlias = schemas.Int64Schema[U] +Name: typing_extensions.TypeAlias = schemas.StrSchema[U] +Items: typing_extensions.TypeAlias = schemas.StrSchema[U] + + +class PhotoUrls( + schemas.ListSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore + + def __new__( + cls, + arg_: typing.Sequence[ + typing.Union[ + Items[str], + str + ] + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> PhotoUrls[tuple]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + PhotoUrls[tuple], + inst + ) + return inst + + def __getitem__(self, name: int) -> Items[str]: + return super().__getitem__(name) + + + +class Tags( + schemas.ListSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[tag.Tag] = dataclasses.field(default_factory=lambda: tag.Tag) # type: ignore + + def __new__( + cls, + arg_: typing.Sequence[ + typing.Union[ + tag.Tag[frozendict.frozendict], + dict, + frozendict.frozendict + ] + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> Tags[tuple]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + Tags[tuple], + inst + ) + return inst + + def __getitem__(self, name: int) -> tag.Tag[frozendict.frozendict]: + return super().__getitem__(name) + + + +class Status( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "available": "AVAILABLE", + "pending": "PENDING", + "sold": "SOLD", + } + ) + + @schemas.classproperty + def AVAILABLE(cls) -> Status[str]: + return cls("available") # type: ignore + + @schemas.classproperty + def PENDING(cls) -> Status[str]: + return cls("pending") # type: ignore + + @schemas.classproperty + def SOLD(cls) -> Status[str]: + return cls("sold") # type: ignore + class Pet( schemas.DictSchema[schemas.T] @@ -23,154 +131,40 @@ class Pet( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "name", "photoUrls", - } - - class Properties: - Id: typing_extensions.TypeAlias = schemas.Int64Schema[U] - - @staticmethod - def category() -> typing.Type[category.Category]: - return category.Category - Name: typing_extensions.TypeAlias = schemas.StrSchema[U] - - - class PhotoUrls( - schemas.ListSchema[schemas.T] - ): - - - class Schema_: - types = {tuple} - Items: typing_extensions.TypeAlias = schemas.StrSchema[U] - - def __new__( - cls, - arg_: typing.Sequence[ - typing.Union[ - Schema_.Items[str], - str - ] - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> Pet.Schema_.Properties.PhotoUrls[tuple]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - Pet.Schema_.Properties.PhotoUrls[tuple], - inst - ) - return inst - - def __getitem__(self, name: int) -> Schema_.Items[str]: - return super().__getitem__(name) - - - class Tags( - schemas.ListSchema[schemas.T] - ): - - - class Schema_: - types = {tuple} - - @staticmethod - def items() -> typing.Type[tag.Tag]: - return tag.Tag - - def __new__( - cls, - arg_: typing.Sequence[ - typing.Union[ - tag.Tag[frozendict.frozendict], - dict, - frozendict.frozendict - ] - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> Pet.Schema_.Properties.Tags[tuple]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - Pet.Schema_.Properties.Tags[tuple], - inst - ) - return inst - - def __getitem__(self, name: int) -> tag.Tag[frozendict.frozendict]: - return super().__getitem__(name) - - - class Status( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - enum_value_to_name = { - "available": "AVAILABLE", - "pending": "PENDING", - "sold": "SOLD", - } - - @schemas.classproperty - def AVAILABLE(cls): - return cls("available") # type: ignore - - @schemas.classproperty - def PENDING(cls): - return cls("pending") # type: ignore - - @schemas.classproperty - def SOLD(cls): - return cls("sold") # type: ignore - __annotations__ = { - "id": Id, - "category": category, - "name": Name, - "photoUrls": PhotoUrls, - "tags": Tags, - "status": Status, - } + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @property - def name(self) -> Schema_.Properties.Name[str]: + def name(self) -> Name[str]: return self.__getitem__("name") @property - def photoUrls(self) -> Schema_.Properties.PhotoUrls[tuple]: + def photoUrls(self) -> PhotoUrls[tuple]: return self.__getitem__("photoUrls") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["name"]) -> Schema_.Properties.Name[str]: ... + def __getitem__(self, name: typing_extensions.Literal["name"]) -> Name[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["photoUrls"]) -> Schema_.Properties.PhotoUrls[tuple]: ... + def __getitem__(self, name: typing_extensions.Literal["photoUrls"]) -> PhotoUrls[tuple]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["id"]) -> Schema_.Properties.Id[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["id"]) -> Id[decimal.Decimal]: ... @typing.overload def __getitem__(self, name: typing_extensions.Literal["category"]) -> category.Category[frozendict.frozendict]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["tags"]) -> Schema_.Properties.Tags[tuple]: ... + def __getitem__(self, name: typing_extensions.Literal["tags"]) -> Tags[tuple]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["status"]) -> Schema_.Properties.Status[str]: ... + def __getitem__(self, name: typing_extensions.Literal["status"]) -> Status[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -203,16 +197,16 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], name: typing.Union[ - Schema_.Properties.Name[str], + Name[str], str ], photoUrls: typing.Union[ - Schema_.Properties.PhotoUrls[tuple], + PhotoUrls[tuple], list, tuple ], id: typing.Union[ - Schema_.Properties.Id[decimal.Decimal], + Id[decimal.Decimal], schemas.Unset, decimal.Decimal, int @@ -224,36 +218,18 @@ def __new__( frozendict.frozendict ] = schemas.unset, tags: typing.Union[ - Schema_.Properties.Tags[tuple], + Tags[tuple], schemas.Unset, list, tuple ] = schemas.unset, status: typing.Union[ - Schema_.Properties.Status[str], + Status[str], schemas.Unset, str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Pet[frozendict.frozendict]: inst = super().__new__( cls, @@ -273,5 +249,17 @@ def __new__( ) return inst + from petstore_api.components.schema import category from petstore_api.components.schema import tag +Properties = typing_extensions.TypedDict( + 'Properties', + { + "id": typing.Type[Id], + "category": typing.Type[category.Category], + "name": typing.Type[Name], + "photoUrls": typing.Type[PhotoUrls], + "tags": typing.Type[Tags], + "status": typing.Type[Status], + } +) diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/pig.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/pig.py index 47493c99607..1c77e72ea3f 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/pig.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/pig.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class Pig( schemas.AnyTypeSchema[schemas.T], ): @@ -21,73 +22,25 @@ class Pig( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - @staticmethod - def discriminator(): - return { + discriminator: typing.Mapping[str, typing.Mapping[str, typing.Type[schemas.Schema]]] = dataclasses.field( + default_factory=lambda: { 'className': { 'BasquePig': basque_pig.BasquePig, 'DanishPig': danish_pig.DanishPig, } } - - class OneOf: - - @staticmethod - def _0() -> typing.Type[basque_pig.BasquePig]: - return basque_pig.BasquePig - - @staticmethod - def _1() -> typing.Type[danish_pig.DanishPig]: - return danish_pig.DanishPig - classes = [ - _0, - _1, - ] + ) + one_of: OneOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(OneOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Pig[ typing.Union[ frozendict.frozendict, @@ -123,5 +76,10 @@ def __new__( ) return inst + from petstore_api.components.schema import basque_pig from petstore_api.components.schema import danish_pig +OneOf = typing.Tuple[ + typing.Type[basque_pig.BasquePig], + typing.Type[danish_pig.DanishPig], +] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/player.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/player.py index a9d294b8b7a..a24157e820d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/player.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/player.py @@ -10,6 +10,8 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Name: typing_extensions.TypeAlias = schemas.StrSchema[U] + class Player( schemas.DictSchema[schemas.T] @@ -23,22 +25,13 @@ class Player( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - Name: typing_extensions.TypeAlias = schemas.StrSchema[U] - - @staticmethod - def enemy_player() -> typing.Type[Player]: - return Player - __annotations__ = { - "name": Name, - "enemyPlayer": enemy_player, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["name"]) -> Schema_.Properties.Name[str]: ... + def __getitem__(self, name: typing_extensions.Literal["name"]) -> Name[str]: ... @typing.overload def __getitem__(self, name: typing_extensions.Literal["enemyPlayer"]) -> Player[frozendict.frozendict]: ... @@ -70,7 +63,7 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], name: typing.Union[ - Schema_.Properties.Name[str], + Name[str], schemas.Unset, str ] = schemas.unset, @@ -81,25 +74,7 @@ def __new__( frozendict.frozendict ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Player[frozendict.frozendict]: inst = super().__new__( cls, @@ -114,3 +89,11 @@ def __new__( inst ) return inst + +Properties = typing_extensions.TypedDict( + 'Properties', + { + "name": typing.Type[Name], + "enemyPlayer": typing.Type[Player], + } +) diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/quadrilateral.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/quadrilateral.py index 98fa8bec599..33e3f1d721b 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/quadrilateral.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/quadrilateral.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class Quadrilateral( schemas.AnyTypeSchema[schemas.T], ): @@ -21,73 +22,25 @@ class Quadrilateral( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - @staticmethod - def discriminator(): - return { + discriminator: typing.Mapping[str, typing.Mapping[str, typing.Type[schemas.Schema]]] = dataclasses.field( + default_factory=lambda: { 'quadrilateralType': { 'ComplexQuadrilateral': complex_quadrilateral.ComplexQuadrilateral, 'SimpleQuadrilateral': simple_quadrilateral.SimpleQuadrilateral, } } - - class OneOf: - - @staticmethod - def _0() -> typing.Type[simple_quadrilateral.SimpleQuadrilateral]: - return simple_quadrilateral.SimpleQuadrilateral - - @staticmethod - def _1() -> typing.Type[complex_quadrilateral.ComplexQuadrilateral]: - return complex_quadrilateral.ComplexQuadrilateral - classes = [ - _0, - _1, - ] + ) + one_of: OneOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(OneOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Quadrilateral[ typing.Union[ frozendict.frozendict, @@ -123,5 +76,10 @@ def __new__( ) return inst + from petstore_api.components.schema import complex_quadrilateral from petstore_api.components.schema import simple_quadrilateral +OneOf = typing.Tuple[ + typing.Type[simple_quadrilateral.SimpleQuadrilateral], + typing.Type[complex_quadrilateral.ComplexQuadrilateral], +] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/quadrilateral_interface.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/quadrilateral_interface.py index 6228c649215..e8dda113f19 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/quadrilateral_interface.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/quadrilateral_interface.py @@ -11,6 +11,36 @@ from petstore_api.shared_imports.schema_imports import * + +class ShapeType( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "Quadrilateral": "QUADRILATERAL", + } + ) + + @schemas.classproperty + def QUADRILATERAL(cls) -> ShapeType[str]: + return cls("Quadrilateral") # type: ignore +QuadrilateralType: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "shapeType": typing.Type[ShapeType], + "quadrilateralType": typing.Type[QuadrilateralType], + } +) + + class QuadrilateralInterface( schemas.AnyTypeSchema[schemas.T], ): @@ -21,52 +51,29 @@ class QuadrilateralInterface( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - required = { + required: typing.FrozenSet[str] = frozenset({ "quadrilateralType", "shapeType", - } - - class Properties: - - - class ShapeType( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - enum_value_to_name = { - "Quadrilateral": "QUADRILATERAL", - } - - @schemas.classproperty - def QUADRILATERAL(cls): - return cls("Quadrilateral") # type: ignore - QuadrilateralType: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "shapeType": ShapeType, - "quadrilateralType": QuadrilateralType, - } + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @property - def quadrilateralType(self) -> Schema_.Properties.QuadrilateralType[str]: + def quadrilateralType(self) -> QuadrilateralType[str]: return self.__getitem__("quadrilateralType") @property - def shapeType(self) -> Schema_.Properties.ShapeType[str]: + def shapeType(self) -> ShapeType[str]: return self.__getitem__("shapeType") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["quadrilateralType"]) -> Schema_.Properties.QuadrilateralType[str]: ... + def __getitem__(self, name: typing_extensions.Literal["quadrilateralType"]) -> QuadrilateralType[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["shapeType"]) -> Schema_.Properties.ShapeType[str]: ... + def __getitem__(self, name: typing_extensions.Literal["shapeType"]) -> ShapeType[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -93,44 +100,9 @@ def __getitem__( def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> QuadrilateralInterface[ typing.Union[ frozendict.frozendict, @@ -165,3 +137,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/read_only_first.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/read_only_first.py index bd7ed788b4e..1ffe81caeb7 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/read_only_first.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/read_only_first.py @@ -10,6 +10,16 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Bar: typing_extensions.TypeAlias = schemas.StrSchema[U] +Baz: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "bar": typing.Type[Bar], + "baz": typing.Type[Baz], + } +) + class ReadOnlyFirst( schemas.DictSchema[schemas.T] @@ -21,22 +31,16 @@ class ReadOnlyFirst( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - Bar: typing_extensions.TypeAlias = schemas.StrSchema[U] - Baz: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "bar": Bar, - "baz": Baz, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["bar"]) -> Schema_.Properties.Bar[str]: ... + def __getitem__(self, name: typing_extensions.Literal["bar"]) -> Bar[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["baz"]) -> Schema_.Properties.Baz[str]: ... + def __getitem__(self, name: typing_extensions.Literal["baz"]) -> Baz[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -65,35 +69,17 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], bar: typing.Union[ - Schema_.Properties.Bar[str], + Bar[str], schemas.Unset, str ] = schemas.unset, baz: typing.Union[ - Schema_.Properties.Baz[str], + Baz[str], schemas.Unset, str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ReadOnlyFirst[frozendict.frozendict]: inst = super().__new__( cls, @@ -108,3 +94,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/req_props_from_explicit_add_props.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/req_props_from_explicit_add_props.py index a9049a2fe73..87c82485378 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/req_props_from_explicit_add_props.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/req_props_from_explicit_add_props.py @@ -10,6 +10,8 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +AdditionalProperties: typing_extensions.TypeAlias = schemas.StrSchema[U] + class ReqPropsFromExplicitAddProps( schemas.DictSchema[schemas.T] @@ -21,26 +23,27 @@ class ReqPropsFromExplicitAddProps( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "invalid-name", "validName", - } - AdditionalProperties: typing_extensions.TypeAlias = schemas.StrSchema[U] + }) + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore @property - def validName(self) -> Schema_.AdditionalProperties[str]: + def validName(self) -> AdditionalProperties[str]: return self.__getitem__("validName") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["invalid-name"]) -> Schema_.AdditionalProperties[str]: ... + def __getitem__(self, name: typing_extensions.Literal["invalid-name"]) -> AdditionalProperties[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["validName"]) -> Schema_.AdditionalProperties[str]: ... + def __getitem__(self, name: typing_extensions.Literal["validName"]) -> AdditionalProperties[str]: ... @typing.overload - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[str]: ... + def __getitem__(self, name: str) -> AdditionalProperties[str]: ... def __getitem__( self, @@ -57,12 +60,12 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], validName: typing.Union[ - Schema_.AdditionalProperties[str], + AdditionalProperties[str], str ], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, **kwargs: typing.Union[ - Schema_.AdditionalProperties[str], + AdditionalProperties[str], str ], ) -> ReqPropsFromExplicitAddProps[frozendict.frozendict]: @@ -78,3 +81,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/req_props_from_true_add_props.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/req_props_from_true_add_props.py index ec6a08871cb..e9478b50876 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/req_props_from_true_add_props.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/req_props_from_true_add_props.py @@ -10,6 +10,8 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +AdditionalProperties: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] + class ReqPropsFromTrueAddProps( schemas.DictSchema[schemas.T] @@ -21,16 +23,17 @@ class ReqPropsFromTrueAddProps( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "invalid-name", "validName", - } - AdditionalProperties: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] + }) + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore @property - def validName(self) -> Schema_.AdditionalProperties[typing.Union[ + def validName(self) -> AdditionalProperties[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -43,7 +46,7 @@ def validName(self) -> Schema_.AdditionalProperties[typing.Union[ return self.__getitem__("validName") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["invalid-name"]) -> Schema_.AdditionalProperties[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["invalid-name"]) -> AdditionalProperties[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -55,7 +58,7 @@ def __getitem__(self, name: typing_extensions.Literal["invalid-name"]) -> Schema ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["validName"]) -> Schema_.AdditionalProperties[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["validName"]) -> AdditionalProperties[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -67,7 +70,7 @@ def __getitem__(self, name: typing_extensions.Literal["validName"]) -> Schema_.A ]]: ... @typing.overload - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[typing.Union[ + def __getitem__(self, name: str) -> AdditionalProperties[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -93,16 +96,9 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], validName: typing.Union[ - Schema_.AdditionalProperties[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + AdditionalProperties[ + schemas.INPUT_BASE_TYPES + ], dict, frozendict.frozendict, str, @@ -122,16 +118,9 @@ def __new__( ], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, **kwargs: typing.Union[ - Schema_.AdditionalProperties[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + AdditionalProperties[ + schemas.INPUT_BASE_TYPES + ], dict, frozendict.frozendict, str, @@ -162,3 +151,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/req_props_from_unset_add_props.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/req_props_from_unset_add_props.py index 922083c5374..fc4a9f2f3f7 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/req_props_from_unset_add_props.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/req_props_from_unset_add_props.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class ReqPropsFromUnsetAddProps( schemas.DictSchema[schemas.T] ): @@ -21,12 +22,13 @@ class ReqPropsFromUnsetAddProps( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "invalid-name", "validName", - } + }) @property def validName(self) -> schemas.AnyTypeSchema[typing.Union[ @@ -120,25 +122,7 @@ def __new__( io.BufferedReader ], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ReqPropsFromUnsetAddProps[frozendict.frozendict]: inst = super().__new__( cls, @@ -152,3 +136,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/scalene_triangle.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/scalene_triangle.py index da55a3ef129..62a05d42ce0 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/scalene_triangle.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/scalene_triangle.py @@ -11,6 +11,95 @@ from petstore_api.shared_imports.schema_imports import * + +class TriangleType( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "ScaleneTriangle": "SCALENE_TRIANGLE", + } + ) + + @schemas.classproperty + def SCALENE_TRIANGLE(cls) -> TriangleType[str]: + return cls("ScaleneTriangle") # type: ignore +Properties = typing_extensions.TypedDict( + 'Properties', + { + "triangleType": typing.Type[TriangleType], + } +) + + +class _1( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["triangleType"]) -> TriangleType[str]: ... + + @typing.overload + def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + def __getitem__( + self, + name: typing.Union[ + typing_extensions.Literal["triangleType"], + str + ] + ): + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + triangleType: typing.Union[ + TriangleType[str], + schemas.Unset, + str + ] = schemas.unset, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _1[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + triangleType=triangleType, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _1[frozendict.frozendict], + inst + ) + return inst + + + class ScaleneTriangle( schemas.AnyTypeSchema[schemas.T], ): @@ -21,159 +110,17 @@ class ScaleneTriangle( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AllOf: - - @staticmethod - def _0() -> typing.Type[triangle_interface.TriangleInterface]: - return triangle_interface.TriangleInterface - - - class _1( - schemas.DictSchema[schemas.T] - ): - - - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - - class TriangleType( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - enum_value_to_name = { - "ScaleneTriangle": "SCALENE_TRIANGLE", - } - - @schemas.classproperty - def SCALENE_TRIANGLE(cls): - return cls("ScaleneTriangle") # type: ignore - __annotations__ = { - "triangleType": TriangleType, - } - - @typing.overload - def __getitem__(self, name: typing_extensions.Literal["triangleType"]) -> Schema_.Properties.TriangleType[str]: ... - - @typing.overload - def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: ... - - def __getitem__( - self, - name: typing.Union[ - typing_extensions.Literal["triangleType"], - str - ] - ): - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[dict, frozendict.frozendict], - triangleType: typing.Union[ - Schema_.Properties.TriangleType[str], - schemas.Unset, - str - ] = schemas.unset, - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> ScaleneTriangle.Schema_.AllOf._1[frozendict.frozendict]: - inst = super().__new__( - cls, - *args_, - triangleType=triangleType, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - ScaleneTriangle.Schema_.AllOf._1[frozendict.frozendict], - inst - ) - return inst - classes = [ - _0, - _1, - ] + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ScaleneTriangle[ typing.Union[ frozendict.frozendict, @@ -209,4 +156,9 @@ def __new__( ) return inst + from petstore_api.components.schema import triangle_interface +AllOf = typing.Tuple[ + typing.Type[triangle_interface.TriangleInterface], + typing.Type[_1[schemas.U]], +] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/self_referencing_array_model.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/self_referencing_array_model.py index 6dfafa9f5f7..be5b6e91561 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/self_referencing_array_model.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/self_referencing_array_model.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class SelfReferencingArrayModel( schemas.ListSchema[schemas.T] ): @@ -21,12 +22,10 @@ class SelfReferencingArrayModel( """ - class Schema_: - types = {tuple} - - @staticmethod - def items() -> typing.Type[SelfReferencingArrayModel]: - return SelfReferencingArrayModel + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[SelfReferencingArrayModel] = dataclasses.field(default_factory=lambda: SelfReferencingArrayModel) # type: ignore def __new__( cls, @@ -52,3 +51,4 @@ def __new__( def __getitem__(self, name: int) -> SelfReferencingArrayModel[tuple]: return super().__getitem__(name) + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/self_referencing_object_model.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/self_referencing_object_model.py index 780922a2bbe..b13c211a9c9 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/self_referencing_object_model.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/self_referencing_object_model.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class SelfReferencingObjectModel( schemas.DictSchema[schemas.T] ): @@ -21,21 +22,11 @@ class SelfReferencingObjectModel( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - @staticmethod - def self_ref() -> typing.Type[SelfReferencingObjectModel]: - return SelfReferencingObjectModel - __annotations__ = { - "selfRef": self_ref, - } - - @staticmethod - def additional_properties() -> typing.Type[SelfReferencingObjectModel]: - return SelfReferencingObjectModel + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + additional_properties: typing.Type[SelfReferencingObjectModel] = dataclasses.field(default_factory=lambda: SelfReferencingObjectModel) # type: ignore @typing.overload def __getitem__(self, name: typing_extensions.Literal["selfRef"]) -> SelfReferencingObjectModel[frozendict.frozendict]: ... @@ -81,3 +72,10 @@ def __new__( inst ) return inst + +Properties = typing_extensions.TypedDict( + 'Properties', + { + "selfRef": typing.Type[SelfReferencingObjectModel], + } +) diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/shape.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/shape.py index f3b7ee65299..ff8adaf7bb7 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/shape.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/shape.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class Shape( schemas.AnyTypeSchema[schemas.T], ): @@ -21,73 +22,25 @@ class Shape( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - @staticmethod - def discriminator(): - return { + discriminator: typing.Mapping[str, typing.Mapping[str, typing.Type[schemas.Schema]]] = dataclasses.field( + default_factory=lambda: { 'shapeType': { 'Quadrilateral': quadrilateral.Quadrilateral, 'Triangle': triangle.Triangle, } } - - class OneOf: - - @staticmethod - def _0() -> typing.Type[triangle.Triangle]: - return triangle.Triangle - - @staticmethod - def _1() -> typing.Type[quadrilateral.Quadrilateral]: - return quadrilateral.Quadrilateral - classes = [ - _0, - _1, - ] + ) + one_of: OneOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(OneOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Shape[ typing.Union[ frozendict.frozendict, @@ -123,5 +76,10 @@ def __new__( ) return inst + from petstore_api.components.schema import quadrilateral from petstore_api.components.schema import triangle +OneOf = typing.Tuple[ + typing.Type[triangle.Triangle], + typing.Type[quadrilateral.Quadrilateral], +] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/shape_or_null.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/shape_or_null.py index b1abd2a96c7..164e0ae905c 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/shape_or_null.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/shape_or_null.py @@ -10,6 +10,8 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +_0: typing_extensions.TypeAlias = schemas.NoneSchema[U] + class ShapeOrNull( schemas.AnyTypeSchema[schemas.T], @@ -23,75 +25,25 @@ class ShapeOrNull( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - @staticmethod - def discriminator(): - return { + discriminator: typing.Mapping[str, typing.Mapping[str, typing.Type[schemas.Schema]]] = dataclasses.field( + default_factory=lambda: { 'shapeType': { 'Quadrilateral': quadrilateral.Quadrilateral, 'Triangle': triangle.Triangle, } } - - class OneOf: - _0: typing_extensions.TypeAlias = schemas.NoneSchema[U] - - @staticmethod - def _1() -> typing.Type[triangle.Triangle]: - return triangle.Triangle - - @staticmethod - def _2() -> typing.Type[quadrilateral.Quadrilateral]: - return quadrilateral.Quadrilateral - classes = [ - _0, - _1, - _2, - ] + ) + one_of: OneOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(OneOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> ShapeOrNull[ typing.Union[ frozendict.frozendict, @@ -127,5 +79,11 @@ def __new__( ) return inst + from petstore_api.components.schema import quadrilateral from petstore_api.components.schema import triangle +OneOf = typing.Tuple[ + typing.Type[_0[schemas.U]], + typing.Type[triangle.Triangle], + typing.Type[quadrilateral.Quadrilateral], +] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/simple_quadrilateral.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/simple_quadrilateral.py index 7e7786c516a..e205913132d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/simple_quadrilateral.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/simple_quadrilateral.py @@ -11,6 +11,95 @@ from petstore_api.shared_imports.schema_imports import * + +class QuadrilateralType( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "SimpleQuadrilateral": "SIMPLE_QUADRILATERAL", + } + ) + + @schemas.classproperty + def SIMPLE_QUADRILATERAL(cls) -> QuadrilateralType[str]: + return cls("SimpleQuadrilateral") # type: ignore +Properties = typing_extensions.TypedDict( + 'Properties', + { + "quadrilateralType": typing.Type[QuadrilateralType], + } +) + + +class _1( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["quadrilateralType"]) -> QuadrilateralType[str]: ... + + @typing.overload + def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ]]: ... + + def __getitem__( + self, + name: typing.Union[ + typing_extensions.Literal["quadrilateralType"], + str + ] + ): + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + quadrilateralType: typing.Union[ + QuadrilateralType[str], + schemas.Unset, + str + ] = schemas.unset, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> _1[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + quadrilateralType=quadrilateralType, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + _1[frozendict.frozendict], + inst + ) + return inst + + + class SimpleQuadrilateral( schemas.AnyTypeSchema[schemas.T], ): @@ -21,159 +110,17 @@ class SimpleQuadrilateral( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AllOf: - - @staticmethod - def _0() -> typing.Type[quadrilateral_interface.QuadrilateralInterface]: - return quadrilateral_interface.QuadrilateralInterface - - - class _1( - schemas.DictSchema[schemas.T] - ): - - - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - - class QuadrilateralType( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - enum_value_to_name = { - "SimpleQuadrilateral": "SIMPLE_QUADRILATERAL", - } - - @schemas.classproperty - def SIMPLE_QUADRILATERAL(cls): - return cls("SimpleQuadrilateral") # type: ignore - __annotations__ = { - "quadrilateralType": QuadrilateralType, - } - - @typing.overload - def __getitem__(self, name: typing_extensions.Literal["quadrilateralType"]) -> Schema_.Properties.QuadrilateralType[str]: ... - - @typing.overload - def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]]: ... - - def __getitem__( - self, - name: typing.Union[ - typing_extensions.Literal["quadrilateralType"], - str - ] - ): - # dict_instance[name] accessor - return super().__getitem__(name) - - def __new__( - cls, - *args_: typing.Union[dict, frozendict.frozendict], - quadrilateralType: typing.Union[ - Schema_.Properties.QuadrilateralType[str], - schemas.Unset, - str - ] = schemas.unset, - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> SimpleQuadrilateral.Schema_.AllOf._1[frozendict.frozendict]: - inst = super().__new__( - cls, - *args_, - quadrilateralType=quadrilateralType, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - SimpleQuadrilateral.Schema_.AllOf._1[frozendict.frozendict], - inst - ) - return inst - classes = [ - _0, - _1, - ] + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> SimpleQuadrilateral[ typing.Union[ frozendict.frozendict, @@ -209,4 +156,9 @@ def __new__( ) return inst + from petstore_api.components.schema import quadrilateral_interface +AllOf = typing.Tuple[ + typing.Type[quadrilateral_interface.QuadrilateralInterface], + typing.Type[_1[schemas.U]], +] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/some_object.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/some_object.py index a2ee26dfdd9..1f228a96ed0 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/some_object.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/some_object.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class SomeObject( schemas.AnyTypeSchema[schemas.T], ): @@ -21,59 +22,17 @@ class SomeObject( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AllOf: - - @staticmethod - def _0() -> typing.Type[object_interface.ObjectInterface]: - return object_interface.ObjectInterface - classes = [ - _0, - ] + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> SomeObject[ typing.Union[ frozendict.frozendict, @@ -109,4 +68,8 @@ def __new__( ) return inst + from petstore_api.components.schema import object_interface +AllOf = typing.Tuple[ + typing.Type[object_interface.ObjectInterface], +] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/special_model_name.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/special_model_name.py index 2f038b7d7c6..cd571f231bd 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/special_model_name.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/special_model_name.py @@ -10,6 +10,14 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +A: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "a": typing.Type[A], + } +) + class SpecialModelName( schemas.DictSchema[schemas.T] @@ -23,17 +31,13 @@ class SpecialModelName( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - A: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "a": A, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["a"]) -> Schema_.Properties.A[str]: ... + def __getitem__(self, name: typing_extensions.Literal["a"]) -> A[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -61,30 +65,12 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], a: typing.Union[ - Schema_.Properties.A[str], + A[str], schemas.Unset, str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> SpecialModelName[frozendict.frozendict]: inst = super().__new__( cls, @@ -98,3 +84,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/string.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/string.py index bb7428c5242..0320d99e128 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/string.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/string.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + String: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/string_boolean_map.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/string_boolean_map.py index 352be623353..e2f0b75c4c5 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/string_boolean_map.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/string_boolean_map.py @@ -10,6 +10,8 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +AdditionalProperties: typing_extensions.TypeAlias = schemas.BoolSchema[U] + class StringBooleanMap( schemas.DictSchema[schemas.T] @@ -21,11 +23,12 @@ class StringBooleanMap( """ - class Schema_: - types = {frozendict.frozendict} - AdditionalProperties: typing_extensions.TypeAlias = schemas.BoolSchema[U] + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[schemas.BoolClass]: + def __getitem__(self, name: str) -> AdditionalProperties[schemas.BoolClass]: # dict_instance[name] accessor return super().__getitem__(name) @@ -34,7 +37,7 @@ def __new__( *args_: typing.Union[dict, frozendict.frozendict], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, **kwargs: typing.Union[ - Schema_.AdditionalProperties[schemas.BoolClass], + AdditionalProperties[schemas.BoolClass], bool ], ) -> StringBooleanMap[frozendict.frozendict]: @@ -49,3 +52,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/string_enum.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/string_enum.py index 3d3a3a6d82d..b8150de644e 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/string_enum.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/string_enum.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class StringEnum( schemas.NoneBase, schemas.StrBase, @@ -24,47 +25,50 @@ class StringEnum( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ schemas.NoneClass, str, - } - enum_value_to_name = { - "placed": "PLACED", - "approved": "APPROVED", - "delivered": "DELIVERED", - "single quoted": "SINGLE_QUOTED", - "multiple\nlines": "MULTIPLE_LINE_FEED_LF_LINES", - "double quote \n with newline": "DOUBLE_QUOTE_LINE_FEED_LF_WITH_NEWLINE", - schemas.NoneClass.NONE: "NONE", - } + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "placed": "PLACED", + "approved": "APPROVED", + "delivered": "DELIVERED", + "single quoted": "SINGLE_QUOTED", + "multiple\nlines": "MULTIPLE_LINE_FEED_LF_LINES", + "double quote \n with newline": "DOUBLE_QUOTE_LINE_FEED_LF_WITH_NEWLINE", + schemas.NoneClass.NONE: "NONE", + } + ) @schemas.classproperty - def PLACED(cls): + def PLACED(cls) -> StringEnum[str]: return cls("placed") # type: ignore @schemas.classproperty - def APPROVED(cls): + def APPROVED(cls) -> StringEnum[str]: return cls("approved") # type: ignore @schemas.classproperty - def DELIVERED(cls): + def DELIVERED(cls) -> StringEnum[str]: return cls("delivered") # type: ignore @schemas.classproperty - def SINGLE_QUOTED(cls): + def SINGLE_QUOTED(cls) -> StringEnum[str]: return cls("single quoted") # type: ignore @schemas.classproperty - def MULTIPLE_LINE_FEED_LF_LINES(cls): + def MULTIPLE_LINE_FEED_LF_LINES(cls) -> StringEnum[str]: return cls("multiple\nlines") # type: ignore @schemas.classproperty - def DOUBLE_QUOTE_LINE_FEED_LF_WITH_NEWLINE(cls): + def DOUBLE_QUOTE_LINE_FEED_LF_WITH_NEWLINE(cls) -> StringEnum[str]: return cls("double quote \n with newline") # type: ignore @schemas.classproperty - def NONE(cls): + def NONE(cls) -> StringEnum[schemas.NoneClass]: return cls(None) # type: ignore @@ -96,3 +100,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/string_enum_with_default_value.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/string_enum_with_default_value.py index 7ddcd057da1..b095711545d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/string_enum_with_default_value.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/string_enum_with_default_value.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class StringEnumWithDefaultValue( schemas.StrSchema[schemas.T] ): @@ -21,25 +22,28 @@ class StringEnumWithDefaultValue( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ str, - } - default = "placed" - enum_value_to_name = { - "placed": "PLACED", - "approved": "APPROVED", - "delivered": "DELIVERED", - } + }) + default: str = "placed" + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "placed": "PLACED", + "approved": "APPROVED", + "delivered": "DELIVERED", + } + ) @schemas.classproperty - def PLACED(cls): + def PLACED(cls) -> StringEnumWithDefaultValue[str]: return cls("placed") # type: ignore @schemas.classproperty - def APPROVED(cls): + def APPROVED(cls) -> StringEnumWithDefaultValue[str]: return cls("approved") # type: ignore @schemas.classproperty - def DELIVERED(cls): + def DELIVERED(cls) -> StringEnumWithDefaultValue[str]: return cls("delivered") # type: ignore diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/string_with_validation.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/string_with_validation.py index aac797b4e9f..92bddce0b54 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/string_with_validation.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/string_with_validation.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class StringWithValidation( schemas.StrSchema[schemas.T] ): @@ -21,8 +22,9 @@ class StringWithValidation( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ str, - } - min_length = 7 + }) + min_length: int = 7 diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/tag.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/tag.py index 2e749c27f19..8054dffda3e 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/tag.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/tag.py @@ -10,6 +10,16 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Id: typing_extensions.TypeAlias = schemas.Int64Schema[U] +Name: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "id": typing.Type[Id], + "name": typing.Type[Name], + } +) + class Tag( schemas.DictSchema[schemas.T] @@ -21,22 +31,16 @@ class Tag( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - Id: typing_extensions.TypeAlias = schemas.Int64Schema[U] - Name: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "id": Id, - "name": Name, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["id"]) -> Schema_.Properties.Id[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["id"]) -> Id[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["name"]) -> Schema_.Properties.Name[str]: ... + def __getitem__(self, name: typing_extensions.Literal["name"]) -> Name[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -65,36 +69,18 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], id: typing.Union[ - Schema_.Properties.Id[decimal.Decimal], + Id[decimal.Decimal], schemas.Unset, decimal.Decimal, int ] = schemas.unset, name: typing.Union[ - Schema_.Properties.Name[str], + Name[str], schemas.Unset, str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Tag[frozendict.frozendict]: inst = super().__new__( cls, @@ -109,3 +95,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/triangle.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/triangle.py index a12d4387b7f..5c6322016a0 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/triangle.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/triangle.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class Triangle( schemas.AnyTypeSchema[schemas.T], ): @@ -21,79 +22,26 @@ class Triangle( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - @staticmethod - def discriminator(): - return { + discriminator: typing.Mapping[str, typing.Mapping[str, typing.Type[schemas.Schema]]] = dataclasses.field( + default_factory=lambda: { 'triangleType': { 'EquilateralTriangle': equilateral_triangle.EquilateralTriangle, 'IsoscelesTriangle': isosceles_triangle.IsoscelesTriangle, 'ScaleneTriangle': scalene_triangle.ScaleneTriangle, } } - - class OneOf: - - @staticmethod - def _0() -> typing.Type[equilateral_triangle.EquilateralTriangle]: - return equilateral_triangle.EquilateralTriangle - - @staticmethod - def _1() -> typing.Type[isosceles_triangle.IsoscelesTriangle]: - return isosceles_triangle.IsoscelesTriangle - - @staticmethod - def _2() -> typing.Type[scalene_triangle.ScaleneTriangle]: - return scalene_triangle.ScaleneTriangle - classes = [ - _0, - _1, - _2, - ] + ) + one_of: OneOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(OneOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Triangle[ typing.Union[ frozendict.frozendict, @@ -129,6 +77,12 @@ def __new__( ) return inst + from petstore_api.components.schema import equilateral_triangle from petstore_api.components.schema import isosceles_triangle from petstore_api.components.schema import scalene_triangle +OneOf = typing.Tuple[ + typing.Type[equilateral_triangle.EquilateralTriangle], + typing.Type[isosceles_triangle.IsoscelesTriangle], + typing.Type[scalene_triangle.ScaleneTriangle], +] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/triangle_interface.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/triangle_interface.py index 3cea7493ca7..a36dd2c77ab 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/triangle_interface.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/triangle_interface.py @@ -11,6 +11,36 @@ from petstore_api.shared_imports.schema_imports import * + +class ShapeType( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "Triangle": "TRIANGLE", + } + ) + + @schemas.classproperty + def TRIANGLE(cls) -> ShapeType[str]: + return cls("Triangle") # type: ignore +TriangleType: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "shapeType": typing.Type[ShapeType], + "triangleType": typing.Type[TriangleType], + } +) + + class TriangleInterface( schemas.AnyTypeSchema[schemas.T], ): @@ -21,52 +51,29 @@ class TriangleInterface( """ - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - required = { + required: typing.FrozenSet[str] = frozenset({ "shapeType", "triangleType", - } - - class Properties: - - - class ShapeType( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - enum_value_to_name = { - "Triangle": "TRIANGLE", - } - - @schemas.classproperty - def TRIANGLE(cls): - return cls("Triangle") # type: ignore - TriangleType: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "shapeType": ShapeType, - "triangleType": TriangleType, - } + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @property - def shapeType(self) -> Schema_.Properties.ShapeType[str]: + def shapeType(self) -> ShapeType[str]: return self.__getitem__("shapeType") @property - def triangleType(self) -> Schema_.Properties.TriangleType[str]: + def triangleType(self) -> TriangleType[str]: return self.__getitem__("triangleType") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["shapeType"]) -> Schema_.Properties.ShapeType[str]: ... + def __getitem__(self, name: typing_extensions.Literal["shapeType"]) -> ShapeType[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["triangleType"]) -> Schema_.Properties.TriangleType[str]: ... + def __getitem__(self, name: typing_extensions.Literal["triangleType"]) -> TriangleType[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -93,44 +100,9 @@ def __getitem__( def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> TriangleInterface[ typing.Union[ frozendict.frozendict, @@ -165,3 +137,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/user.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/user.py index 12e24f6bfd2..c0d7b11725a 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/user.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/user.py @@ -10,6 +10,140 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Id: typing_extensions.TypeAlias = schemas.Int64Schema[U] +Username: typing_extensions.TypeAlias = schemas.StrSchema[U] +FirstName: typing_extensions.TypeAlias = schemas.StrSchema[U] +LastName: typing_extensions.TypeAlias = schemas.StrSchema[U] +Email: typing_extensions.TypeAlias = schemas.StrSchema[U] +Password: typing_extensions.TypeAlias = schemas.StrSchema[U] +Phone: typing_extensions.TypeAlias = schemas.StrSchema[U] +UserStatus: typing_extensions.TypeAlias = schemas.Int32Schema[U] +ObjectWithNoDeclaredProps: typing_extensions.TypeAlias = schemas.DictSchema[U] + + +class ObjectWithNoDeclaredPropsNullable( + schemas.NoneBase, + schemas.DictBase, + schemas.Schema[schemas.T], + schemas.NoneFrozenDictMixin +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + schemas.NoneClass, + frozendict.frozendict, + }) + + + def __new__( + cls, + *args_: typing.Union[ + None, + dict, + frozendict.frozendict + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> ObjectWithNoDeclaredPropsNullable[ + typing.Union[ + schemas.NoneClass, + frozendict.frozendict + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + ObjectWithNoDeclaredPropsNullable[ + typing.Union[ + schemas.NoneClass, + frozendict.frozendict + ] + ], + inst + ) + return inst + +AnyTypeProp: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] +_Not: typing_extensions.TypeAlias = schemas.NoneSchema[U] + + +class AnyTypeExceptNullProp( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + not_: typing.Type[_Not] = dataclasses.field(default_factory=lambda: _Not) # type: ignore + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> AnyTypeExceptNullProp[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + AnyTypeExceptNullProp[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + +AnyTypePropNullable: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "id": typing.Type[Id], + "username": typing.Type[Username], + "firstName": typing.Type[FirstName], + "lastName": typing.Type[LastName], + "email": typing.Type[Email], + "password": typing.Type[Password], + "phone": typing.Type[Phone], + "userStatus": typing.Type[UserStatus], + "objectWithNoDeclaredProps": typing.Type[ObjectWithNoDeclaredProps], + "objectWithNoDeclaredPropsNullable": typing.Type[ObjectWithNoDeclaredPropsNullable], + "anyTypeProp": typing.Type[AnyTypeProp], + "anyTypeExceptNullProp": typing.Type[AnyTypeExceptNullProp], + "anyTypePropNullable": typing.Type[AnyTypePropNullable], + } +) + class User( schemas.DictSchema[schemas.T] @@ -21,224 +155,46 @@ class User( """ - class Schema_: - types = {frozendict.frozendict} - - class Properties: - Id: typing_extensions.TypeAlias = schemas.Int64Schema[U] - Username: typing_extensions.TypeAlias = schemas.StrSchema[U] - FirstName: typing_extensions.TypeAlias = schemas.StrSchema[U] - LastName: typing_extensions.TypeAlias = schemas.StrSchema[U] - Email: typing_extensions.TypeAlias = schemas.StrSchema[U] - Password: typing_extensions.TypeAlias = schemas.StrSchema[U] - Phone: typing_extensions.TypeAlias = schemas.StrSchema[U] - UserStatus: typing_extensions.TypeAlias = schemas.Int32Schema[U] - ObjectWithNoDeclaredProps: typing_extensions.TypeAlias = schemas.DictSchema[U] - - - class ObjectWithNoDeclaredPropsNullable( - schemas.NoneBase, - schemas.DictBase, - schemas.Schema[schemas.T], - schemas.NoneFrozenDictMixin - ): - - - class Schema_: - types = { - schemas.NoneClass, - frozendict.frozendict, - } - - - def __new__( - cls, - *args_: typing.Union[ - None, - dict, - frozendict.frozendict - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> User.Schema_.Properties.ObjectWithNoDeclaredPropsNullable[ - typing.Union[ - schemas.NoneClass, - frozendict.frozendict - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - User.Schema_.Properties.ObjectWithNoDeclaredPropsNullable[ - typing.Union[ - schemas.NoneClass, - frozendict.frozendict - ] - ], - inst - ) - return inst - AnyTypeProp: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - - - class AnyTypeExceptNullProp( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - _Not: typing_extensions.TypeAlias = schemas.NoneSchema[U] - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> User.Schema_.Properties.AnyTypeExceptNullProp[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - User.Schema_.Properties.AnyTypeExceptNullProp[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - AnyTypePropNullable: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] - __annotations__ = { - "id": Id, - "username": Username, - "firstName": FirstName, - "lastName": LastName, - "email": Email, - "password": Password, - "phone": Phone, - "userStatus": UserStatus, - "objectWithNoDeclaredProps": ObjectWithNoDeclaredProps, - "objectWithNoDeclaredPropsNullable": ObjectWithNoDeclaredPropsNullable, - "anyTypeProp": AnyTypeProp, - "anyTypeExceptNullProp": AnyTypeExceptNullProp, - "anyTypePropNullable": AnyTypePropNullable, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["id"]) -> Schema_.Properties.Id[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["id"]) -> Id[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["username"]) -> Schema_.Properties.Username[str]: ... + def __getitem__(self, name: typing_extensions.Literal["username"]) -> Username[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["firstName"]) -> Schema_.Properties.FirstName[str]: ... + def __getitem__(self, name: typing_extensions.Literal["firstName"]) -> FirstName[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["lastName"]) -> Schema_.Properties.LastName[str]: ... + def __getitem__(self, name: typing_extensions.Literal["lastName"]) -> LastName[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["email"]) -> Schema_.Properties.Email[str]: ... + def __getitem__(self, name: typing_extensions.Literal["email"]) -> Email[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["password"]) -> Schema_.Properties.Password[str]: ... + def __getitem__(self, name: typing_extensions.Literal["password"]) -> Password[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["phone"]) -> Schema_.Properties.Phone[str]: ... + def __getitem__(self, name: typing_extensions.Literal["phone"]) -> Phone[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["userStatus"]) -> Schema_.Properties.UserStatus[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["userStatus"]) -> UserStatus[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["objectWithNoDeclaredProps"]) -> Schema_.Properties.ObjectWithNoDeclaredProps[frozendict.frozendict]: ... + def __getitem__(self, name: typing_extensions.Literal["objectWithNoDeclaredProps"]) -> ObjectWithNoDeclaredProps[frozendict.frozendict]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["objectWithNoDeclaredPropsNullable"]) -> Schema_.Properties.ObjectWithNoDeclaredPropsNullable[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["objectWithNoDeclaredPropsNullable"]) -> ObjectWithNoDeclaredPropsNullable[typing.Union[ schemas.NoneClass, frozendict.frozendict ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["anyTypeProp"]) -> Schema_.Properties.AnyTypeProp[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["anyTypeProp"]) -> AnyTypeProp[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -250,7 +206,7 @@ def __getitem__(self, name: typing_extensions.Literal["anyTypeProp"]) -> Schema_ ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["anyTypeExceptNullProp"]) -> Schema_.Properties.AnyTypeExceptNullProp[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["anyTypeExceptNullProp"]) -> AnyTypeExceptNullProp[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -262,7 +218,7 @@ def __getitem__(self, name: typing_extensions.Literal["anyTypeExceptNullProp"]) ]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["anyTypePropNullable"]) -> Schema_.Properties.AnyTypePropNullable[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["anyTypePropNullable"]) -> AnyTypePropNullable[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -311,55 +267,55 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], id: typing.Union[ - Schema_.Properties.Id[decimal.Decimal], + Id[decimal.Decimal], schemas.Unset, decimal.Decimal, int ] = schemas.unset, username: typing.Union[ - Schema_.Properties.Username[str], + Username[str], schemas.Unset, str ] = schemas.unset, firstName: typing.Union[ - Schema_.Properties.FirstName[str], + FirstName[str], schemas.Unset, str ] = schemas.unset, lastName: typing.Union[ - Schema_.Properties.LastName[str], + LastName[str], schemas.Unset, str ] = schemas.unset, email: typing.Union[ - Schema_.Properties.Email[str], + Email[str], schemas.Unset, str ] = schemas.unset, password: typing.Union[ - Schema_.Properties.Password[str], + Password[str], schemas.Unset, str ] = schemas.unset, phone: typing.Union[ - Schema_.Properties.Phone[str], + Phone[str], schemas.Unset, str ] = schemas.unset, userStatus: typing.Union[ - Schema_.Properties.UserStatus[decimal.Decimal], + UserStatus[decimal.Decimal], schemas.Unset, decimal.Decimal, int ] = schemas.unset, objectWithNoDeclaredProps: typing.Union[ - Schema_.Properties.ObjectWithNoDeclaredProps[frozendict.frozendict], + ObjectWithNoDeclaredProps[frozendict.frozendict], schemas.Unset, dict, frozendict.frozendict ] = schemas.unset, objectWithNoDeclaredPropsNullable: typing.Union[ - Schema_.Properties.ObjectWithNoDeclaredPropsNullable[typing.Union[ + ObjectWithNoDeclaredPropsNullable[typing.Union[ schemas.NoneClass, frozendict.frozendict ]], @@ -369,16 +325,9 @@ def __new__( frozendict.frozendict ] = schemas.unset, anyTypeProp: typing.Union[ - Schema_.Properties.AnyTypeProp[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + AnyTypeProp[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -398,16 +347,9 @@ def __new__( io.BufferedReader ] = schemas.unset, anyTypeExceptNullProp: typing.Union[ - Schema_.Properties.AnyTypeExceptNullProp[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + AnyTypeExceptNullProp[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -427,16 +369,9 @@ def __new__( io.BufferedReader ] = schemas.unset, anyTypePropNullable: typing.Union[ - Schema_.Properties.AnyTypePropNullable[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + AnyTypePropNullable[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -456,25 +391,7 @@ def __new__( io.BufferedReader ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> User[frozendict.frozendict]: inst = super().__new__( cls, @@ -500,3 +417,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/uuid_string.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/uuid_string.py index 34aa23ea49e..e73573753c9 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/uuid_string.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/uuid_string.py @@ -11,6 +11,7 @@ from petstore_api.shared_imports.schema_imports import * + class UUIDString( schemas.UUIDSchema[schemas.T] ): @@ -21,9 +22,10 @@ class UUIDString( """ - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ str, - } - format = 'uuid' - min_length = 1 + }) + format: str = 'uuid' + min_length: int = 1 diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/whale.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/whale.py index c9eae619c4e..842454e632d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/whale.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/whale.py @@ -10,6 +10,38 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +HasBaleen: typing_extensions.TypeAlias = schemas.BoolSchema[U] +HasTeeth: typing_extensions.TypeAlias = schemas.BoolSchema[U] + + +class ClassName( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "whale": "WHALE", + } + ) + + @schemas.classproperty + def WHALE(cls) -> ClassName[str]: + return cls("whale") # type: ignore +Properties = typing_extensions.TypedDict( + 'Properties', + { + "hasBaleen": typing.Type[HasBaleen], + "hasTeeth": typing.Type[HasTeeth], + "className": typing.Type[ClassName], + } +) + class Whale( schemas.DictSchema[schemas.T] @@ -21,51 +53,26 @@ class Whale( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "className", - } - - class Properties: - HasBaleen: typing_extensions.TypeAlias = schemas.BoolSchema[U] - HasTeeth: typing_extensions.TypeAlias = schemas.BoolSchema[U] - - - class ClassName( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - enum_value_to_name = { - "whale": "WHALE", - } - - @schemas.classproperty - def WHALE(cls): - return cls("whale") # type: ignore - __annotations__ = { - "hasBaleen": HasBaleen, - "hasTeeth": HasTeeth, - "className": ClassName, - } + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @property - def className(self) -> Schema_.Properties.ClassName[str]: + def className(self) -> ClassName[str]: return self.__getitem__("className") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["className"]) -> Schema_.Properties.ClassName[str]: ... + def __getitem__(self, name: typing_extensions.Literal["className"]) -> ClassName[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["hasBaleen"]) -> Schema_.Properties.HasBaleen[schemas.BoolClass]: ... + def __getitem__(self, name: typing_extensions.Literal["hasBaleen"]) -> HasBaleen[schemas.BoolClass]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["hasTeeth"]) -> Schema_.Properties.HasTeeth[schemas.BoolClass]: ... + def __getitem__(self, name: typing_extensions.Literal["hasTeeth"]) -> HasTeeth[schemas.BoolClass]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -95,39 +102,21 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], className: typing.Union[ - Schema_.Properties.ClassName[str], + ClassName[str], str ], hasBaleen: typing.Union[ - Schema_.Properties.HasBaleen[schemas.BoolClass], + HasBaleen[schemas.BoolClass], schemas.Unset, bool ] = schemas.unset, hasTeeth: typing.Union[ - Schema_.Properties.HasTeeth[schemas.BoolClass], + HasTeeth[schemas.BoolClass], schemas.Unset, bool ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Whale[frozendict.frozendict]: inst = super().__new__( cls, @@ -143,3 +132,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/zebra.py b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/zebra.py index 3418b48e525..f1292e9be9c 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/zebra.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/components/schema/zebra.py @@ -10,6 +10,67 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +AdditionalProperties: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] + + +class Type( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "plains": "PLAINS", + "mountain": "MOUNTAIN", + "grevys": "GREVYS", + } + ) + + @schemas.classproperty + def PLAINS(cls) -> Type[str]: + return cls("plains") # type: ignore + + @schemas.classproperty + def MOUNTAIN(cls) -> Type[str]: + return cls("mountain") # type: ignore + + @schemas.classproperty + def GREVYS(cls) -> Type[str]: + return cls("grevys") # type: ignore + + +class ClassName( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "zebra": "ZEBRA", + } + ) + + @schemas.classproperty + def ZEBRA(cls) -> ClassName[str]: + return cls("zebra") # type: ignore +Properties = typing_extensions.TypedDict( + 'Properties', + { + "type": typing.Type[Type], + "className": typing.Type[ClassName], + } +) + class Zebra( schemas.DictSchema[schemas.T] @@ -21,77 +82,27 @@ class Zebra( """ - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "className", - } - - class Properties: - - - class Type( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - enum_value_to_name = { - "plains": "PLAINS", - "mountain": "MOUNTAIN", - "grevys": "GREVYS", - } - - @schemas.classproperty - def PLAINS(cls): - return cls("plains") # type: ignore - - @schemas.classproperty - def MOUNTAIN(cls): - return cls("mountain") # type: ignore - - @schemas.classproperty - def GREVYS(cls): - return cls("grevys") # type: ignore - - - class ClassName( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - enum_value_to_name = { - "zebra": "ZEBRA", - } - - @schemas.classproperty - def ZEBRA(cls): - return cls("zebra") # type: ignore - __annotations__ = { - "type": Type, - "className": ClassName, - } - AdditionalProperties: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore @property - def className(self) -> Schema_.Properties.ClassName[str]: + def className(self) -> ClassName[str]: return self.__getitem__("className") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["className"]) -> Schema_.Properties.ClassName[str]: ... + def __getitem__(self, name: typing_extensions.Literal["className"]) -> ClassName[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["type"]) -> Schema_.Properties.Type[str]: ... + def __getitem__(self, name: typing_extensions.Literal["type"]) -> Type[str]: ... @typing.overload - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[typing.Union[ + def __getitem__(self, name: str) -> AdditionalProperties[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -117,26 +128,19 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], className: typing.Union[ - Schema_.Properties.ClassName[str], + ClassName[str], str ], type: typing.Union[ - Schema_.Properties.Type[str], + Type[str], schemas.Unset, str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, **kwargs: typing.Union[ - Schema_.AdditionalProperties[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + AdditionalProperties[ + schemas.INPUT_BASE_TYPES + ], dict, frozendict.frozendict, str, @@ -168,3 +172,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/configurations/schema_configuration.py b/samples/openapi3/client/petstore/python/src/petstore_api/configurations/schema_configuration.py index 773588a3248..575a1e9754f 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/configurations/schema_configuration.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/configurations/schema_configuration.py @@ -13,34 +13,32 @@ PYTHON_KEYWORD_TO_JSON_SCHEMA_KEYWORD = { - 'types': 'type', + 'additional_properties': 'additionalProperties', + 'all_of': 'allOf', + 'any_of': 'anyOf', + 'discriminator': 'discriminator', + # default omitted because it has no validation impact 'enum_value_to_name': 'enum', - 'unique_items': 'uniqueItems', - 'min_items': 'minItems', + 'exclusive_maximum': 'exclusiveMaximum', + 'exclusive_minimum': 'exclusiveMinimum', + 'format': 'format', + 'inclusive_maximum': 'maximum', + 'inclusive_minimum': 'minimum', + 'items': 'items', 'max_items': 'maxItems', - 'min_properties': 'minProperties', + 'max_length': 'maxLength', 'max_properties': 'maxProperties', + 'min_items': 'minItems', 'min_length': 'minLength', - 'max_length': 'maxLength', - 'inclusive_minimum': 'minimum', - 'exclusive_minimum': 'exclusiveMinimum', - 'inclusive_maximum': 'maximum', - 'exclusive_maximum': 'exclusiveMaximum', + 'min_properties': 'minProperties', 'multiple_of': 'multipleOf', - 'regex': 'pattern', - 'format': 'format', + 'not_': 'not', + 'one_of': 'oneOf', + 'pattern': 'pattern', + 'properties': 'properties', 'required': 'required', - 'items': 'items', - 'Items': 'items', - 'Properties': 'properties', - 'additional_properties': 'additionalProperties', - 'additionalProperties': 'additionalProperties', - 'OneOf': 'oneOf', - 'AnyOf': 'anyOf', - 'AllOf': 'allOf', - '_not': 'not', - '_Not': 'not', - 'discriminator': 'discriminator' + 'types': 'type', + 'unique_items': 'uniqueItems' } class SchemaConfiguration: diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/delete/parameters/parameter_0/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/delete/parameters/parameter_0/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/delete/parameters/parameter_0/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/delete/parameters/parameter_0/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/delete/parameters/parameter_1/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/delete/parameters/parameter_1/schema.py index af34848077f..beefb32f1d0 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/delete/parameters/parameter_1/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/delete/parameters/parameter_1/schema.py @@ -11,24 +11,28 @@ from petstore_api.shared_imports.schema_imports import * + class Schema( schemas.StrSchema[schemas.T] ): - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ str, - } - enum_value_to_name = { - "true": "TRUE", - "false": "FALSE", - } + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "true": "TRUE", + "false": "FALSE", + } + ) @schemas.classproperty - def TRUE(cls): + def TRUE(cls) -> Schema[str]: return cls("true") # type: ignore @schemas.classproperty - def FALSE(cls): + def FALSE(cls) -> Schema[str]: return cls("false") # type: ignore diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/delete/parameters/parameter_2/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/delete/parameters/parameter_2/schema.py index cc2fd90961c..db592ea3e5b 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/delete/parameters/parameter_2/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/delete/parameters/parameter_2/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.Int64Schema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/delete/parameters/parameter_3/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/delete/parameters/parameter_3/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/delete/parameters/parameter_3/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/delete/parameters/parameter_3/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/delete/parameters/parameter_4/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/delete/parameters/parameter_4/schema.py index af34848077f..beefb32f1d0 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/delete/parameters/parameter_4/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/delete/parameters/parameter_4/schema.py @@ -11,24 +11,28 @@ from petstore_api.shared_imports.schema_imports import * + class Schema( schemas.StrSchema[schemas.T] ): - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ str, - } - enum_value_to_name = { - "true": "TRUE", - "false": "FALSE", - } + }) + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "true": "TRUE", + "false": "FALSE", + } + ) @schemas.classproperty - def TRUE(cls): + def TRUE(cls) -> Schema[str]: return cls("true") # type: ignore @schemas.classproperty - def FALSE(cls): + def FALSE(cls) -> Schema[str]: return cls("false") # type: ignore diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/delete/parameters/parameter_5/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/delete/parameters/parameter_5/schema.py index cc2fd90961c..db592ea3e5b 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/delete/parameters/parameter_5/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/delete/parameters/parameter_5/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.Int64Schema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/parameters/parameter_0/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/parameters/parameter_0/schema.py index 9b7c4fcf5b0..0eba2856e64 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/parameters/parameter_0/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/parameters/parameter_0/schema.py @@ -11,43 +11,49 @@ from petstore_api.shared_imports.schema_imports import * + +class Items( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + default: str = "$" + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + ">": "GREATER_THAN_SIGN", + "$": "DOLLAR_SIGN", + } + ) + + @schemas.classproperty + def GREATER_THAN_SIGN(cls) -> Items[str]: + return cls(">") # type: ignore + + @schemas.classproperty + def DOLLAR_SIGN(cls) -> Items[str]: + return cls("$") # type: ignore + + class Schema( schemas.ListSchema[schemas.T] ): - class Schema_: - types = {tuple} - - - class Items( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - default = "$" - enum_value_to_name = { - ">": "GREATER_THAN_SIGN", - "$": "DOLLAR_SIGN", - } - - @schemas.classproperty - def GREATER_THAN_SIGN(cls): - return cls(">") # type: ignore - - @schemas.classproperty - def DOLLAR_SIGN(cls): - return cls("$") # type: ignore + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore def __new__( cls, arg_: typing.Sequence[ typing.Union[ - Schema_.Items[str], + Items[str], str ] ], @@ -64,5 +70,6 @@ def __new__( ) return inst - def __getitem__(self, name: int) -> Schema_.Items[str]: + def __getitem__(self, name: int) -> Items[str]: return super().__getitem__(name) + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/parameters/parameter_1/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/parameters/parameter_1/schema.py index d1695293c61..7a71abacd02 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/parameters/parameter_1/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/parameters/parameter_1/schema.py @@ -11,30 +11,34 @@ from petstore_api.shared_imports.schema_imports import * + class Schema( schemas.StrSchema[schemas.T] ): - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ str, - } - default = "-efg" - enum_value_to_name = { - "_abc": "_ABC", - "-efg": "HYPHEN_MINUS_EFG", - "(xyz)": "LEFT_PARENTHESIS_XYZ_RIGHT_PARENTHESIS", - } + }) + default: str = "-efg" + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "_abc": "_ABC", + "-efg": "HYPHEN_MINUS_EFG", + "(xyz)": "LEFT_PARENTHESIS_XYZ_RIGHT_PARENTHESIS", + } + ) @schemas.classproperty - def _ABC(cls): + def _ABC(cls) -> Schema[str]: return cls("_abc") # type: ignore @schemas.classproperty - def HYPHEN_MINUS_EFG(cls): + def HYPHEN_MINUS_EFG(cls) -> Schema[str]: return cls("-efg") # type: ignore @schemas.classproperty - def LEFT_PARENTHESIS_XYZ_RIGHT_PARENTHESIS(cls): + def LEFT_PARENTHESIS_XYZ_RIGHT_PARENTHESIS(cls) -> Schema[str]: return cls("(xyz)") # type: ignore diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/parameters/parameter_2/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/parameters/parameter_2/schema.py index 9b7c4fcf5b0..0eba2856e64 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/parameters/parameter_2/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/parameters/parameter_2/schema.py @@ -11,43 +11,49 @@ from petstore_api.shared_imports.schema_imports import * + +class Items( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + default: str = "$" + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + ">": "GREATER_THAN_SIGN", + "$": "DOLLAR_SIGN", + } + ) + + @schemas.classproperty + def GREATER_THAN_SIGN(cls) -> Items[str]: + return cls(">") # type: ignore + + @schemas.classproperty + def DOLLAR_SIGN(cls) -> Items[str]: + return cls("$") # type: ignore + + class Schema( schemas.ListSchema[schemas.T] ): - class Schema_: - types = {tuple} - - - class Items( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - default = "$" - enum_value_to_name = { - ">": "GREATER_THAN_SIGN", - "$": "DOLLAR_SIGN", - } - - @schemas.classproperty - def GREATER_THAN_SIGN(cls): - return cls(">") # type: ignore - - @schemas.classproperty - def DOLLAR_SIGN(cls): - return cls("$") # type: ignore + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore def __new__( cls, arg_: typing.Sequence[ typing.Union[ - Schema_.Items[str], + Items[str], str ] ], @@ -64,5 +70,6 @@ def __new__( ) return inst - def __getitem__(self, name: int) -> Schema_.Items[str]: + def __getitem__(self, name: int) -> Items[str]: return super().__getitem__(name) + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/parameters/parameter_3/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/parameters/parameter_3/schema.py index d1695293c61..7a71abacd02 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/parameters/parameter_3/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/parameters/parameter_3/schema.py @@ -11,30 +11,34 @@ from petstore_api.shared_imports.schema_imports import * + class Schema( schemas.StrSchema[schemas.T] ): - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ str, - } - default = "-efg" - enum_value_to_name = { - "_abc": "_ABC", - "-efg": "HYPHEN_MINUS_EFG", - "(xyz)": "LEFT_PARENTHESIS_XYZ_RIGHT_PARENTHESIS", - } + }) + default: str = "-efg" + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "_abc": "_ABC", + "-efg": "HYPHEN_MINUS_EFG", + "(xyz)": "LEFT_PARENTHESIS_XYZ_RIGHT_PARENTHESIS", + } + ) @schemas.classproperty - def _ABC(cls): + def _ABC(cls) -> Schema[str]: return cls("_abc") # type: ignore @schemas.classproperty - def HYPHEN_MINUS_EFG(cls): + def HYPHEN_MINUS_EFG(cls) -> Schema[str]: return cls("-efg") # type: ignore @schemas.classproperty - def LEFT_PARENTHESIS_XYZ_RIGHT_PARENTHESIS(cls): + def LEFT_PARENTHESIS_XYZ_RIGHT_PARENTHESIS(cls) -> Schema[str]: return cls("(xyz)") # type: ignore diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/parameters/parameter_4/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/parameters/parameter_4/schema.py index b15e843337e..9a0a26920d0 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/parameters/parameter_4/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/parameters/parameter_4/schema.py @@ -11,25 +11,29 @@ from petstore_api.shared_imports.schema_imports import * + class Schema( schemas.Int32Schema[schemas.T] ): - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ decimal.Decimal, - } - format = 'int32' - enum_value_to_name = { - 1: "POSITIVE_1", - -2: "NEGATIVE_2", - } + }) + format: str = 'int32' + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + 1: "POSITIVE_1", + -2: "NEGATIVE_2", + } + ) @schemas.classproperty - def POSITIVE_1(cls): + def POSITIVE_1(cls) -> Schema[decimal.Decimal]: return cls(1) # type: ignore @schemas.classproperty - def NEGATIVE_2(cls): + def NEGATIVE_2(cls) -> Schema[decimal.Decimal]: return cls(-2) # type: ignore diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/parameters/parameter_5/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/parameters/parameter_5/schema.py index 59fe5d41bf8..c4ee010af0c 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/parameters/parameter_5/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/parameters/parameter_5/schema.py @@ -11,25 +11,29 @@ from petstore_api.shared_imports.schema_imports import * + class Schema( schemas.Float64Schema[schemas.T] ): - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ decimal.Decimal, - } - format = 'double' - enum_value_to_name = { - 1.1: "POSITIVE_1_PT_1", - -1.2: "NEGATIVE_1_PT_2", - } + }) + format: str = 'double' + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + 1.1: "POSITIVE_1_PT_1", + -1.2: "NEGATIVE_1_PT_2", + } + ) @schemas.classproperty - def POSITIVE_1_PT_1(cls): + def POSITIVE_1_PT_1(cls) -> Schema[decimal.Decimal]: return cls(1.1) # type: ignore @schemas.classproperty - def NEGATIVE_1_PT_2(cls): + def NEGATIVE_1_PT_2(cls) -> Schema[decimal.Decimal]: return cls(-1.2) # type: ignore diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/request_body/content/application_x_www_form_urlencoded/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/request_body/content/application_x_www_form_urlencoded/schema.py index 17f6ad25d7c..bb476bb4f00 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/request_body/content/application_x_www_form_urlencoded/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/request_body/content/application_x_www_form_urlencoded/schema.py @@ -11,111 +11,124 @@ from petstore_api.shared_imports.schema_imports import * + +class Items( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + default: str = "$" + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + ">": "GREATER_THAN_SIGN", + "$": "DOLLAR_SIGN", + } + ) + + @schemas.classproperty + def GREATER_THAN_SIGN(cls) -> Items[str]: + return cls(">") # type: ignore + + @schemas.classproperty + def DOLLAR_SIGN(cls) -> Items[str]: + return cls("$") # type: ignore + + +class EnumFormStringArray( + schemas.ListSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore + + def __new__( + cls, + arg_: typing.Sequence[ + typing.Union[ + Items[str], + str + ] + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> EnumFormStringArray[tuple]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + EnumFormStringArray[tuple], + inst + ) + return inst + + def __getitem__(self, name: int) -> Items[str]: + return super().__getitem__(name) + + + +class EnumFormString( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + default: str = "-efg" + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "_abc": "_ABC", + "-efg": "HYPHEN_MINUS_EFG", + "(xyz)": "LEFT_PARENTHESIS_XYZ_RIGHT_PARENTHESIS", + } + ) + + @schemas.classproperty + def _ABC(cls) -> EnumFormString[str]: + return cls("_abc") # type: ignore + + @schemas.classproperty + def HYPHEN_MINUS_EFG(cls) -> EnumFormString[str]: + return cls("-efg") # type: ignore + + @schemas.classproperty + def LEFT_PARENTHESIS_XYZ_RIGHT_PARENTHESIS(cls) -> EnumFormString[str]: + return cls("(xyz)") # type: ignore +Properties = typing_extensions.TypedDict( + 'Properties', + { + "enum_form_string_array": typing.Type[EnumFormStringArray], + "enum_form_string": typing.Type[EnumFormString], + } +) + + class Schema( schemas.DictSchema[schemas.T] ): - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - - class EnumFormStringArray( - schemas.ListSchema[schemas.T] - ): - - - class Schema_: - types = {tuple} - - - class Items( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - default = "$" - enum_value_to_name = { - ">": "GREATER_THAN_SIGN", - "$": "DOLLAR_SIGN", - } - - @schemas.classproperty - def GREATER_THAN_SIGN(cls): - return cls(">") # type: ignore - - @schemas.classproperty - def DOLLAR_SIGN(cls): - return cls("$") # type: ignore - - def __new__( - cls, - arg_: typing.Sequence[ - typing.Union[ - Schema_.Items[str], - str - ] - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> Schema.Schema_.Properties.EnumFormStringArray[tuple]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - Schema.Schema_.Properties.EnumFormStringArray[tuple], - inst - ) - return inst - - def __getitem__(self, name: int) -> Schema_.Items[str]: - return super().__getitem__(name) - - - class EnumFormString( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - default = "-efg" - enum_value_to_name = { - "_abc": "_ABC", - "-efg": "HYPHEN_MINUS_EFG", - "(xyz)": "LEFT_PARENTHESIS_XYZ_RIGHT_PARENTHESIS", - } - - @schemas.classproperty - def _ABC(cls): - return cls("_abc") # type: ignore - - @schemas.classproperty - def HYPHEN_MINUS_EFG(cls): - return cls("-efg") # type: ignore - - @schemas.classproperty - def LEFT_PARENTHESIS_XYZ_RIGHT_PARENTHESIS(cls): - return cls("(xyz)") # type: ignore - __annotations__ = { - "enum_form_string_array": EnumFormStringArray, - "enum_form_string": EnumFormString, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["enum_form_string_array"]) -> Schema_.Properties.EnumFormStringArray[tuple]: ... + def __getitem__(self, name: typing_extensions.Literal["enum_form_string_array"]) -> EnumFormStringArray[tuple]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["enum_form_string"]) -> Schema_.Properties.EnumFormString[str]: ... + def __getitem__(self, name: typing_extensions.Literal["enum_form_string"]) -> EnumFormString[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -144,36 +157,18 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], enum_form_string_array: typing.Union[ - Schema_.Properties.EnumFormStringArray[tuple], + EnumFormStringArray[tuple], schemas.Unset, list, tuple ] = schemas.unset, enum_form_string: typing.Union[ - Schema_.Properties.EnumFormString[str], + EnumFormString[str], schemas.Unset, str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Schema[frozendict.frozendict]: inst = super().__new__( cls, @@ -188,3 +183,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/responses/response_404/content/application_json/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/responses/response_404/content/application_json/schema.py index 218cec972de..b8bcb2051e9 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/responses/response_404/content/application_json/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/get/responses/response_404/content/application_json/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.DictSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/post/request_body/content/application_x_www_form_urlencoded/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/post/request_body/content/application_x_www_form_urlencoded/schema.py index e20d6064bba..8b9bda5cf17 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/post/request_body/content/application_x_www_form_urlencoded/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake/post/request_body/content/application_x_www_form_urlencoded/schema.py @@ -11,223 +11,236 @@ from petstore_api.shared_imports.schema_imports import * + +class Integer( + schemas.IntSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + decimal.Decimal, + }) + format: str = 'int' + inclusive_maximum: typing.Union[int, float] = 100 + inclusive_minimum: typing.Union[int, float] = 10 + + +class Int32( + schemas.Int32Schema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + decimal.Decimal, + }) + format: str = 'int32' + inclusive_maximum: typing.Union[int, float] = 200 + inclusive_minimum: typing.Union[int, float] = 20 +Int64: typing_extensions.TypeAlias = schemas.Int64Schema[U] + + +class Number( + schemas.NumberSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + decimal.Decimal, + }) + inclusive_maximum: typing.Union[int, float] = 543.2 + inclusive_minimum: typing.Union[int, float] = 32.1 + + +class _Float( + schemas.Float32Schema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + decimal.Decimal, + }) + format: str = 'float' + inclusive_maximum: typing.Union[int, float] = 987.6 + + +class Double( + schemas.Float64Schema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + decimal.Decimal, + }) + format: str = 'double' + inclusive_maximum: typing.Union[int, float] = 123.4 + inclusive_minimum: typing.Union[int, float] = 67.8 + + +class String( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + pattern: schemas.PatternInfo = schemas.PatternInfo( + pattern=r'[a-z]', # noqa: E501 + flags=re.I, + ) + + +class PatternWithoutDelimiter( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + pattern: schemas.PatternInfo = schemas.PatternInfo( + pattern=r'^[A-Z].*' # noqa: E501 + ) +Byte: typing_extensions.TypeAlias = schemas.StrSchema[U] +Binary: typing_extensions.TypeAlias = schemas.BinarySchema[U] +Date: typing_extensions.TypeAlias = schemas.DateSchema[U] + + +class DateTime( + schemas.DateTimeSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + format: str = 'date-time' + + +class Password( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + format: str = 'password' + max_length: int = 64 + min_length: int = 10 +Callback: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "integer": typing.Type[Integer], + "int32": typing.Type[Int32], + "int64": typing.Type[Int64], + "number": typing.Type[Number], + "float": typing.Type[_Float], + "double": typing.Type[Double], + "string": typing.Type[String], + "pattern_without_delimiter": typing.Type[PatternWithoutDelimiter], + "byte": typing.Type[Byte], + "binary": typing.Type[Binary], + "date": typing.Type[Date], + "dateTime": typing.Type[DateTime], + "password": typing.Type[Password], + "callback": typing.Type[Callback], + } +) + + class Schema( schemas.DictSchema[schemas.T] ): - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "byte", "double", "number", "pattern_without_delimiter", - } - - class Properties: - - - class Integer( - schemas.IntSchema[schemas.T] - ): - - - class Schema_: - types = { - decimal.Decimal, - } - format = 'int' - inclusive_maximum = 100 - inclusive_minimum = 10 - - - class Int32( - schemas.Int32Schema[schemas.T] - ): - - - class Schema_: - types = { - decimal.Decimal, - } - format = 'int32' - inclusive_maximum = 200 - inclusive_minimum = 20 - Int64: typing_extensions.TypeAlias = schemas.Int64Schema[U] - - - class Number( - schemas.NumberSchema[schemas.T] - ): - - - class Schema_: - types = { - decimal.Decimal, - } - inclusive_maximum = 543.2 - inclusive_minimum = 32.1 - - - class _Float( - schemas.Float32Schema[schemas.T] - ): - - - class Schema_: - types = { - decimal.Decimal, - } - format = 'float' - inclusive_maximum = 987.6 - - - class Double( - schemas.Float64Schema[schemas.T] - ): - - - class Schema_: - types = { - decimal.Decimal, - } - format = 'double' - inclusive_maximum = 123.4 - inclusive_minimum = 67.8 - - - class String( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - regex={ - 'pattern': r'[a-z]', # noqa: E501 - 'flags': re.I, - } - - - class PatternWithoutDelimiter( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - regex={ - 'pattern': r'^[A-Z].*', # noqa: E501 - } - Byte: typing_extensions.TypeAlias = schemas.StrSchema[U] - Binary: typing_extensions.TypeAlias = schemas.BinarySchema[U] - Date: typing_extensions.TypeAlias = schemas.DateSchema[U] - - - class DateTime( - schemas.DateTimeSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - format = 'date-time' - - - class Password( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - format = 'password' - max_length = 64 - min_length = 10 - Callback: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "integer": Integer, - "int32": Int32, - "int64": Int64, - "number": Number, - "float": _Float, - "double": Double, - "string": String, - "pattern_without_delimiter": PatternWithoutDelimiter, - "byte": Byte, - "binary": Binary, - "date": Date, - "dateTime": DateTime, - "password": Password, - "callback": Callback, - } + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @property - def byte(self) -> Schema_.Properties.Byte[str]: + def byte(self) -> Byte[str]: return self.__getitem__("byte") @property - def double(self) -> Schema_.Properties.Double[decimal.Decimal]: + def double(self) -> Double[decimal.Decimal]: return self.__getitem__("double") @property - def number(self) -> Schema_.Properties.Number[decimal.Decimal]: + def number(self) -> Number[decimal.Decimal]: return self.__getitem__("number") @property - def pattern_without_delimiter(self) -> Schema_.Properties.PatternWithoutDelimiter[str]: + def pattern_without_delimiter(self) -> PatternWithoutDelimiter[str]: return self.__getitem__("pattern_without_delimiter") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["byte"]) -> Schema_.Properties.Byte[str]: ... + def __getitem__(self, name: typing_extensions.Literal["byte"]) -> Byte[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["double"]) -> Schema_.Properties.Double[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["double"]) -> Double[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["number"]) -> Schema_.Properties.Number[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["number"]) -> Number[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["pattern_without_delimiter"]) -> Schema_.Properties.PatternWithoutDelimiter[str]: ... + def __getitem__(self, name: typing_extensions.Literal["pattern_without_delimiter"]) -> PatternWithoutDelimiter[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["integer"]) -> Schema_.Properties.Integer[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["integer"]) -> Integer[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["int32"]) -> Schema_.Properties.Int32[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["int32"]) -> Int32[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["int64"]) -> Schema_.Properties.Int64[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["int64"]) -> Int64[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["float"]) -> Schema_.Properties._Float[decimal.Decimal]: ... + def __getitem__(self, name: typing_extensions.Literal["float"]) -> _Float[decimal.Decimal]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["string"]) -> Schema_.Properties.String[str]: ... + def __getitem__(self, name: typing_extensions.Literal["string"]) -> String[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["binary"]) -> Schema_.Properties.Binary[typing.Union[bytes, schemas.FileIO]]: ... + def __getitem__(self, name: typing_extensions.Literal["binary"]) -> Binary[typing.Union[bytes, schemas.FileIO]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["date"]) -> Schema_.Properties.Date[str]: ... + def __getitem__(self, name: typing_extensions.Literal["date"]) -> Date[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["dateTime"]) -> Schema_.Properties.DateTime[str]: ... + def __getitem__(self, name: typing_extensions.Literal["dateTime"]) -> DateTime[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["password"]) -> Schema_.Properties.Password[str]: ... + def __getitem__(self, name: typing_extensions.Literal["password"]) -> Password[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["callback"]) -> Schema_.Properties.Callback[str]: ... + def __getitem__(self, name: typing_extensions.Literal["callback"]) -> Callback[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -268,97 +281,79 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], byte: typing.Union[ - Schema_.Properties.Byte[str], + Byte[str], str ], double: typing.Union[ - Schema_.Properties.Double[decimal.Decimal], + Double[decimal.Decimal], decimal.Decimal, int, float ], number: typing.Union[ - Schema_.Properties.Number[decimal.Decimal], + Number[decimal.Decimal], decimal.Decimal, int, float ], pattern_without_delimiter: typing.Union[ - Schema_.Properties.PatternWithoutDelimiter[str], + PatternWithoutDelimiter[str], str ], integer: typing.Union[ - Schema_.Properties.Integer[decimal.Decimal], + Integer[decimal.Decimal], schemas.Unset, decimal.Decimal, int ] = schemas.unset, int32: typing.Union[ - Schema_.Properties.Int32[decimal.Decimal], + Int32[decimal.Decimal], schemas.Unset, decimal.Decimal, int ] = schemas.unset, int64: typing.Union[ - Schema_.Properties.Int64[decimal.Decimal], + Int64[decimal.Decimal], schemas.Unset, decimal.Decimal, int ] = schemas.unset, string: typing.Union[ - Schema_.Properties.String[str], + String[str], schemas.Unset, str ] = schemas.unset, binary: typing.Union[ - Schema_.Properties.Binary[typing.Union[bytes, schemas.FileIO]], + Binary[typing.Union[bytes, schemas.FileIO]], schemas.Unset, bytes, io.FileIO, io.BufferedReader ] = schemas.unset, date: typing.Union[ - Schema_.Properties.Date[str], + Date[str], schemas.Unset, str, datetime.date ] = schemas.unset, dateTime: typing.Union[ - Schema_.Properties.DateTime[str], + DateTime[str], schemas.Unset, str, datetime.datetime ] = schemas.unset, password: typing.Union[ - Schema_.Properties.Password[str], + Password[str], schemas.Unset, str ] = schemas.unset, callback: typing.Union[ - Schema_.Properties.Callback[str], + Callback[str], schemas.Unset, str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Schema[frozendict.frozendict]: inst = super().__new__( cls, @@ -384,3 +379,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_body_with_query_params/put/parameters/parameter_0/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_body_with_query_params/put/parameters/parameter_0/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_body_with_query_params/put/parameters/parameter_0/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_body_with_query_params/put/parameters/parameter_0/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_case_sensitive_params/put/parameters/parameter_0/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_case_sensitive_params/put/parameters/parameter_0/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_case_sensitive_params/put/parameters/parameter_0/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_case_sensitive_params/put/parameters/parameter_0/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_case_sensitive_params/put/parameters/parameter_1/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_case_sensitive_params/put/parameters/parameter_1/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_case_sensitive_params/put/parameters/parameter_1/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_case_sensitive_params/put/parameters/parameter_1/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_case_sensitive_params/put/parameters/parameter_2/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_case_sensitive_params/put/parameters/parameter_2/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_case_sensitive_params/put/parameters/parameter_2/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_case_sensitive_params/put/parameters/parameter_2/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_delete_coffee_id/delete/parameters/parameter_0/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_delete_coffee_id/delete/parameters/parameter_0/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_delete_coffee_id/delete/parameters/parameter_0/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_delete_coffee_id/delete/parameters/parameter_0/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_additional_properties/post/request_body/content/application_json/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_additional_properties/post/request_body/content/application_json/schema.py index 40dd94f5e63..98e182c11f8 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_additional_properties/post/request_body/content/application_json/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_additional_properties/post/request_body/content/application_json/schema.py @@ -10,17 +10,20 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +AdditionalProperties: typing_extensions.TypeAlias = schemas.StrSchema[U] + class Schema( schemas.DictSchema[schemas.T] ): - class Schema_: - types = {frozendict.frozendict} - AdditionalProperties: typing_extensions.TypeAlias = schemas.StrSchema[U] + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore - def __getitem__(self, name: str) -> Schema_.AdditionalProperties[str]: + def __getitem__(self, name: str) -> AdditionalProperties[str]: # dict_instance[name] accessor return super().__getitem__(name) @@ -29,7 +32,7 @@ def __new__( *args_: typing.Union[dict, frozendict.frozendict], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, **kwargs: typing.Union[ - Schema_.AdditionalProperties[str], + AdditionalProperties[str], str ], ) -> Schema[frozendict.frozendict]: @@ -44,3 +47,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_composition/post/parameters/parameter_0/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_composition/post/parameters/parameter_0/schema.py index c7de2034f62..04e7339aa92 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_composition/post/parameters/parameter_0/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_composition/post/parameters/parameter_0/schema.py @@ -11,72 +11,39 @@ from petstore_api.shared_imports.schema_imports import * + +class _0( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + min_length: int = 1 +AllOf = typing.Tuple[ + typing.Type[_0[schemas.U]], +] + + class Schema( schemas.AnyTypeSchema[schemas.T], ): - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AllOf: - - - class _0( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - min_length = 1 - classes = [ - _0, - ] + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Schema[ typing.Union[ frozendict.frozendict, @@ -111,3 +78,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_composition/post/parameters/parameter_1/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_composition/post/parameters/parameter_1/schema.py index f11e82c626e..ecbf400e34f 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_composition/post/parameters/parameter_1/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_composition/post/parameters/parameter_1/schema.py @@ -11,123 +11,94 @@ from petstore_api.shared_imports.schema_imports import * + +class _0( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + min_length: int = 1 +AllOf = typing.Tuple[ + typing.Type[_0[schemas.U]], +] + + +class SomeProp( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> SomeProp[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + SomeProp[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + +Properties = typing_extensions.TypedDict( + 'Properties', + { + "someProp": typing.Type[SomeProp], + } +) + + class Schema( schemas.DictSchema[schemas.T] ): - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - - class SomeProp( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - - class AllOf: - - - class _0( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - min_length = 1 - classes = [ - _0, - ] - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> Schema.Schema_.Properties.SomeProp[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - Schema.Schema_.Properties.SomeProp[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - __annotations__ = { - "someProp": SomeProp, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["someProp"]) -> Schema_.Properties.SomeProp[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["someProp"]) -> SomeProp[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -164,16 +135,9 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], someProp: typing.Union[ - Schema_.Properties.SomeProp[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + SomeProp[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -193,25 +157,7 @@ def __new__( io.BufferedReader ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Schema[frozendict.frozendict]: inst = super().__new__( cls, @@ -225,3 +171,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_composition/post/request_body/content/application_json/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_composition/post/request_body/content/application_json/schema.py index c7de2034f62..04e7339aa92 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_composition/post/request_body/content/application_json/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_composition/post/request_body/content/application_json/schema.py @@ -11,72 +11,39 @@ from petstore_api.shared_imports.schema_imports import * + +class _0( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + min_length: int = 1 +AllOf = typing.Tuple[ + typing.Type[_0[schemas.U]], +] + + class Schema( schemas.AnyTypeSchema[schemas.T], ): - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AllOf: - - - class _0( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - min_length = 1 - classes = [ - _0, - ] + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Schema[ typing.Union[ frozendict.frozendict, @@ -111,3 +78,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_composition/post/request_body/content/multipart_form_data/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_composition/post/request_body/content/multipart_form_data/schema.py index f11e82c626e..ecbf400e34f 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_composition/post/request_body/content/multipart_form_data/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_composition/post/request_body/content/multipart_form_data/schema.py @@ -11,123 +11,94 @@ from petstore_api.shared_imports.schema_imports import * + +class _0( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + min_length: int = 1 +AllOf = typing.Tuple[ + typing.Type[_0[schemas.U]], +] + + +class SomeProp( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> SomeProp[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + SomeProp[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + +Properties = typing_extensions.TypedDict( + 'Properties', + { + "someProp": typing.Type[SomeProp], + } +) + + class Schema( schemas.DictSchema[schemas.T] ): - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - - class SomeProp( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - - class AllOf: - - - class _0( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - min_length = 1 - classes = [ - _0, - ] - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> Schema.Schema_.Properties.SomeProp[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - Schema.Schema_.Properties.SomeProp[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - __annotations__ = { - "someProp": SomeProp, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["someProp"]) -> Schema_.Properties.SomeProp[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["someProp"]) -> SomeProp[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -164,16 +135,9 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], someProp: typing.Union[ - Schema_.Properties.SomeProp[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + SomeProp[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -193,25 +157,7 @@ def __new__( io.BufferedReader ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Schema[frozendict.frozendict]: inst = super().__new__( cls, @@ -225,3 +171,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_composition/post/responses/response_200/content/application_json/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_composition/post/responses/response_200/content/application_json/schema.py index c7de2034f62..04e7339aa92 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_composition/post/responses/response_200/content/application_json/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_composition/post/responses/response_200/content/application_json/schema.py @@ -11,72 +11,39 @@ from petstore_api.shared_imports.schema_imports import * + +class _0( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + min_length: int = 1 +AllOf = typing.Tuple[ + typing.Type[_0[schemas.U]], +] + + class Schema( schemas.AnyTypeSchema[schemas.T], ): - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): # any type - - class AllOf: - - - class _0( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - min_length = 1 - classes = [ - _0, - ] + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore def __new__( cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Schema[ typing.Union[ frozendict.frozendict, @@ -111,3 +78,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_composition/post/responses/response_200/content/multipart_form_data/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_composition/post/responses/response_200/content/multipart_form_data/schema.py index f11e82c626e..ecbf400e34f 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_composition/post/responses/response_200/content/multipart_form_data/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_inline_composition/post/responses/response_200/content/multipart_form_data/schema.py @@ -11,123 +11,94 @@ from petstore_api.shared_imports.schema_imports import * + +class _0( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + min_length: int = 1 +AllOf = typing.Tuple[ + typing.Type[_0[schemas.U]], +] + + +class SomeProp( + schemas.AnyTypeSchema[schemas.T], +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + # any type + all_of: AllOf = dataclasses.field(default_factory=lambda: schemas.tuple_to_instance(AllOf)) # type: ignore + + + def __new__( + cls, + *args_: schemas.INPUT_TYPES_ALL_INCL_SCHEMA, + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA + ) -> SomeProp[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ]: + inst = super().__new__( + cls, + *args_, + configuration_=configuration_, + **kwargs, + ) + inst = typing.cast( + SomeProp[ + typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + schemas.BoolClass, + schemas.NoneClass, + tuple, + bytes, + schemas.FileIO + ] + ], + inst + ) + return inst + +Properties = typing_extensions.TypedDict( + 'Properties', + { + "someProp": typing.Type[SomeProp], + } +) + + class Schema( schemas.DictSchema[schemas.T] ): - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - - class SomeProp( - schemas.AnyTypeSchema[schemas.T], - ): - - - class Schema_: - # any type - - class AllOf: - - - class _0( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - min_length = 1 - classes = [ - _0, - ] - - - def __new__( - cls, - *args_: typing.Union[ - dict, - frozendict.frozendict, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - int, - float, - decimal.Decimal, - bool, - None, - list, - tuple, - bytes, - io.FileIO, - io.BufferedReader - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], - ) -> Schema.Schema_.Properties.SomeProp[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ]: - inst = super().__new__( - cls, - *args_, - configuration_=configuration_, - **kwargs, - ) - inst = typing.cast( - Schema.Schema_.Properties.SomeProp[ - typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ] - ], - inst - ) - return inst - __annotations__ = { - "someProp": SomeProp, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["someProp"]) -> Schema_.Properties.SomeProp[typing.Union[ + def __getitem__(self, name: typing_extensions.Literal["someProp"]) -> SomeProp[typing.Union[ frozendict.frozendict, str, decimal.Decimal, @@ -164,16 +135,9 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], someProp: typing.Union[ - Schema_.Properties.SomeProp[typing.Union[ - frozendict.frozendict, - str, - decimal.Decimal, - schemas.BoolClass, - schemas.NoneClass, - tuple, - bytes, - schemas.FileIO - ]], + SomeProp[ + schemas.INPUT_BASE_TYPES + ], schemas.Unset, dict, frozendict.frozendict, @@ -193,25 +157,7 @@ def __new__( io.BufferedReader ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Schema[frozendict.frozendict]: inst = super().__new__( cls, @@ -225,3 +171,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_json_form_data/get/request_body/content/application_x_www_form_urlencoded/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_json_form_data/get/request_body/content/application_x_www_form_urlencoded/schema.py index 34421180f3d..545e1f9972a 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_json_form_data/get/request_body/content/application_x_www_form_urlencoded/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_json_form_data/get/request_body/content/application_x_www_form_urlencoded/schema.py @@ -10,40 +10,44 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Param: typing_extensions.TypeAlias = schemas.StrSchema[U] +Param2: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "param": typing.Type[Param], + "param2": typing.Type[Param2], + } +) + class Schema( schemas.DictSchema[schemas.T] ): - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "param", "param2", - } - - class Properties: - Param: typing_extensions.TypeAlias = schemas.StrSchema[U] - Param2: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "param": Param, - "param2": Param2, - } + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @property - def param(self) -> Schema_.Properties.Param[str]: + def param(self) -> Param[str]: return self.__getitem__("param") @property - def param2(self) -> Schema_.Properties.Param2[str]: + def param2(self) -> Param2[str]: return self.__getitem__("param2") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["param"]) -> Schema_.Properties.Param[str]: ... + def __getitem__(self, name: typing_extensions.Literal["param"]) -> Param[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["param2"]) -> Schema_.Properties.Param2[str]: ... + def __getitem__(self, name: typing_extensions.Literal["param2"]) -> Param2[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -72,33 +76,15 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], param: typing.Union[ - Schema_.Properties.Param[str], + Param[str], str ], param2: typing.Union[ - Schema_.Properties.Param2[str], + Param2[str], str ], configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Schema[frozendict.frozendict]: inst = super().__new__( cls, @@ -113,3 +99,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_json_with_charset/post/request_body/content/application_json_charsetutf8/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_json_with_charset/post/request_body/content/application_json_charsetutf8/schema.py index 83bd5a9325f..072e994d56d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_json_with_charset/post/request_body/content/application_json_charsetutf8/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_json_with_charset/post/request_body/content/application_json_charsetutf8/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_json_with_charset/post/responses/response_200/content/application_json_charsetutf8/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_json_with_charset/post/responses/response_200/content/application_json_charsetutf8/schema.py index 83bd5a9325f..072e994d56d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_json_with_charset/post/responses/response_200/content/application_json_charsetutf8/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_json_with_charset/post/responses/response_200/content/application_json_charsetutf8/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_multiple_response_bodies/get/responses/response_200/content/application_json/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_multiple_response_bodies/get/responses/response_200/content/application_json/schema.py index 83bd5a9325f..072e994d56d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_multiple_response_bodies/get/responses/response_200/content/application_json/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_multiple_response_bodies/get/responses/response_200/content/application_json/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_multiple_response_bodies/get/responses/response_202/content/application_json/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_multiple_response_bodies/get/responses/response_202/content/application_json/schema.py index 83bd5a9325f..072e994d56d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_multiple_response_bodies/get/responses/response_202/content/application_json/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_multiple_response_bodies/get/responses/response_202/content/application_json/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_multiple_securities/get/responses/response_200/content/application_json/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_multiple_securities/get/responses/response_200/content/application_json/schema.py index 83bd5a9325f..072e994d56d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_multiple_securities/get/responses/response_200/content/application_json/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_multiple_securities/get/responses/response_200/content/application_json/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_obj_in_query/get/parameters/parameter_0/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_obj_in_query/get/parameters/parameter_0/schema.py index 87202840d8b..79c6229df62 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_obj_in_query/get/parameters/parameter_0/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_obj_in_query/get/parameters/parameter_0/schema.py @@ -10,23 +10,27 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Keyword: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "keyword": typing.Type[Keyword], + } +) + class Schema( schemas.DictSchema[schemas.T] ): - class Schema_: - types = {frozendict.frozendict} - - class Properties: - Keyword: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "keyword": Keyword, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["keyword"]) -> Schema_.Properties.Keyword[str]: ... + def __getitem__(self, name: typing_extensions.Literal["keyword"]) -> Keyword[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -54,30 +58,12 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], keyword: typing.Union[ - Schema_.Properties.Keyword[str], + Keyword[str], schemas.Unset, str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Schema[frozendict.frozendict]: inst = super().__new__( cls, @@ -91,3 +77,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_0/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_0/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_0/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_0/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_1/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_1/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_1/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_1/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_10/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_10/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_10/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_10/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_11/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_11/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_11/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_11/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_12/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_12/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_12/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_12/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_13/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_13/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_13/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_13/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_14/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_14/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_14/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_14/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_15/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_15/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_15/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_15/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_16/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_16/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_16/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_16/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_17/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_17/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_17/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_17/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_18/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_18/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_18/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_18/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_2/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_2/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_2/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_2/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_3/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_3/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_3/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_3/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_4/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_4/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_4/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_4/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_5/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_5/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_5/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_5/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_6/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_6/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_6/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_6/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_7/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_7/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_7/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_7/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_8/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_8/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_8/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_8/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_9/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_9/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_9/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/parameters/parameter_9/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/request_body/content/application_json/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/request_body/content/application_json/schema.py index 83bd5a9325f..072e994d56d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/request_body/content/application_json/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/request_body/content/application_json/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/responses/response_200/content/application_json/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/responses/response_200/content/application_json/schema.py index 83bd5a9325f..072e994d56d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/responses/response_200/content/application_json/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_parameter_collisions1_abab_self_ab/post/responses/response_200/content/application_json/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_pet_id_upload_image_with_required_file/post/parameters/parameter_0/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_pet_id_upload_image_with_required_file/post/parameters/parameter_0/schema.py index cc2fd90961c..db592ea3e5b 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_pet_id_upload_image_with_required_file/post/parameters/parameter_0/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_pet_id_upload_image_with_required_file/post/parameters/parameter_0/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.Int64Schema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_pet_id_upload_image_with_required_file/post/request_body/content/multipart_form_data/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_pet_id_upload_image_with_required_file/post/request_body/content/multipart_form_data/schema.py index 1875a8012a6..c589a9cef9a 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_pet_id_upload_image_with_required_file/post/request_body/content/multipart_form_data/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_pet_id_upload_image_with_required_file/post/request_body/content/multipart_form_data/schema.py @@ -10,35 +10,39 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +AdditionalMetadata: typing_extensions.TypeAlias = schemas.StrSchema[U] +RequiredFile: typing_extensions.TypeAlias = schemas.BinarySchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "additionalMetadata": typing.Type[AdditionalMetadata], + "requiredFile": typing.Type[RequiredFile], + } +) + class Schema( schemas.DictSchema[schemas.T] ): - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "requiredFile", - } - - class Properties: - AdditionalMetadata: typing_extensions.TypeAlias = schemas.StrSchema[U] - RequiredFile: typing_extensions.TypeAlias = schemas.BinarySchema[U] - __annotations__ = { - "additionalMetadata": AdditionalMetadata, - "requiredFile": RequiredFile, - } + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @property - def requiredFile(self) -> Schema_.Properties.RequiredFile[typing.Union[bytes, schemas.FileIO]]: + def requiredFile(self) -> RequiredFile[typing.Union[bytes, schemas.FileIO]]: return self.__getitem__("requiredFile") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["requiredFile"]) -> Schema_.Properties.RequiredFile[typing.Union[bytes, schemas.FileIO]]: ... + def __getitem__(self, name: typing_extensions.Literal["requiredFile"]) -> RequiredFile[typing.Union[bytes, schemas.FileIO]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["additionalMetadata"]) -> Schema_.Properties.AdditionalMetadata[str]: ... + def __getitem__(self, name: typing_extensions.Literal["additionalMetadata"]) -> AdditionalMetadata[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -67,36 +71,18 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], requiredFile: typing.Union[ - Schema_.Properties.RequiredFile[typing.Union[bytes, schemas.FileIO]], + RequiredFile[typing.Union[bytes, schemas.FileIO]], bytes, io.FileIO, io.BufferedReader ], additionalMetadata: typing.Union[ - Schema_.Properties.AdditionalMetadata[str], + AdditionalMetadata[str], schemas.Unset, str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Schema[frozendict.frozendict]: inst = super().__new__( cls, @@ -111,3 +97,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_query_param_with_json_content_type/get/parameters/parameter_0/content/application_json/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_query_param_with_json_content_type/get/parameters/parameter_0/content/application_json/schema.py index 83bd5a9325f..072e994d56d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_query_param_with_json_content_type/get/parameters/parameter_0/content/application_json/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_query_param_with_json_content_type/get/parameters/parameter_0/content/application_json/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_query_param_with_json_content_type/get/responses/response_200/content/application_json/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_query_param_with_json_content_type/get/responses/response_200/content/application_json/schema.py index 83bd5a9325f..072e994d56d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_query_param_with_json_content_type/get/responses/response_200/content/application_json/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_query_param_with_json_content_type/get/responses/response_200/content/application_json/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_test_query_paramters/put/parameters/parameter_0/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_test_query_paramters/put/parameters/parameter_0/schema.py index da15d120e4a..de25475a43d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_test_query_paramters/put/parameters/parameter_0/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_test_query_paramters/put/parameters/parameter_0/schema.py @@ -10,21 +10,24 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Items: typing_extensions.TypeAlias = schemas.StrSchema[U] + class Schema( schemas.ListSchema[schemas.T] ): - class Schema_: - types = {tuple} - Items: typing_extensions.TypeAlias = schemas.StrSchema[U] + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore def __new__( cls, arg_: typing.Sequence[ typing.Union[ - Schema_.Items[str], + Items[str], str ] ], @@ -41,5 +44,6 @@ def __new__( ) return inst - def __getitem__(self, name: int) -> Schema_.Items[str]: + def __getitem__(self, name: int) -> Items[str]: return super().__getitem__(name) + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_test_query_paramters/put/parameters/parameter_1/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_test_query_paramters/put/parameters/parameter_1/schema.py index da15d120e4a..de25475a43d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_test_query_paramters/put/parameters/parameter_1/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_test_query_paramters/put/parameters/parameter_1/schema.py @@ -10,21 +10,24 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Items: typing_extensions.TypeAlias = schemas.StrSchema[U] + class Schema( schemas.ListSchema[schemas.T] ): - class Schema_: - types = {tuple} - Items: typing_extensions.TypeAlias = schemas.StrSchema[U] + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore def __new__( cls, arg_: typing.Sequence[ typing.Union[ - Schema_.Items[str], + Items[str], str ] ], @@ -41,5 +44,6 @@ def __new__( ) return inst - def __getitem__(self, name: int) -> Schema_.Items[str]: + def __getitem__(self, name: int) -> Items[str]: return super().__getitem__(name) + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_test_query_paramters/put/parameters/parameter_2/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_test_query_paramters/put/parameters/parameter_2/schema.py index da15d120e4a..de25475a43d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_test_query_paramters/put/parameters/parameter_2/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_test_query_paramters/put/parameters/parameter_2/schema.py @@ -10,21 +10,24 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Items: typing_extensions.TypeAlias = schemas.StrSchema[U] + class Schema( schemas.ListSchema[schemas.T] ): - class Schema_: - types = {tuple} - Items: typing_extensions.TypeAlias = schemas.StrSchema[U] + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore def __new__( cls, arg_: typing.Sequence[ typing.Union[ - Schema_.Items[str], + Items[str], str ] ], @@ -41,5 +44,6 @@ def __new__( ) return inst - def __getitem__(self, name: int) -> Schema_.Items[str]: + def __getitem__(self, name: int) -> Items[str]: return super().__getitem__(name) + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_test_query_paramters/put/parameters/parameter_3/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_test_query_paramters/put/parameters/parameter_3/schema.py index da15d120e4a..de25475a43d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_test_query_paramters/put/parameters/parameter_3/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_test_query_paramters/put/parameters/parameter_3/schema.py @@ -10,21 +10,24 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Items: typing_extensions.TypeAlias = schemas.StrSchema[U] + class Schema( schemas.ListSchema[schemas.T] ): - class Schema_: - types = {tuple} - Items: typing_extensions.TypeAlias = schemas.StrSchema[U] + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore def __new__( cls, arg_: typing.Sequence[ typing.Union[ - Schema_.Items[str], + Items[str], str ] ], @@ -41,5 +44,6 @@ def __new__( ) return inst - def __getitem__(self, name: int) -> Schema_.Items[str]: + def __getitem__(self, name: int) -> Items[str]: return super().__getitem__(name) + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_test_query_paramters/put/parameters/parameter_4/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_test_query_paramters/put/parameters/parameter_4/schema.py index da15d120e4a..de25475a43d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_test_query_paramters/put/parameters/parameter_4/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_test_query_paramters/put/parameters/parameter_4/schema.py @@ -10,21 +10,24 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Items: typing_extensions.TypeAlias = schemas.StrSchema[U] + class Schema( schemas.ListSchema[schemas.T] ): - class Schema_: - types = {tuple} - Items: typing_extensions.TypeAlias = schemas.StrSchema[U] + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore def __new__( cls, arg_: typing.Sequence[ typing.Union[ - Schema_.Items[str], + Items[str], str ] ], @@ -41,5 +44,6 @@ def __new__( ) return inst - def __getitem__(self, name: int) -> Schema_.Items[str]: + def __getitem__(self, name: int) -> Items[str]: return super().__getitem__(name) + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_upload_download_file/post/request_body/content/application_octet_stream/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_upload_download_file/post/request_body/content/application_octet_stream/schema.py index ec7153b02a5..2d4bbce1d22 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_upload_download_file/post/request_body/content/application_octet_stream/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_upload_download_file/post/request_body/content/application_octet_stream/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.BinarySchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_upload_download_file/post/responses/response_200/content/application_octet_stream/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_upload_download_file/post/responses/response_200/content/application_octet_stream/schema.py index ec7153b02a5..2d4bbce1d22 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_upload_download_file/post/responses/response_200/content/application_octet_stream/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_upload_download_file/post/responses/response_200/content/application_octet_stream/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.BinarySchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_upload_file/post/request_body/content/multipart_form_data/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_upload_file/post/request_body/content/multipart_form_data/schema.py index 9f28a0fca8d..8e2d921ec18 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_upload_file/post/request_body/content/multipart_form_data/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_upload_file/post/request_body/content/multipart_form_data/schema.py @@ -10,35 +10,39 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +AdditionalMetadata: typing_extensions.TypeAlias = schemas.StrSchema[U] +File: typing_extensions.TypeAlias = schemas.BinarySchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "additionalMetadata": typing.Type[AdditionalMetadata], + "file": typing.Type[File], + } +) + class Schema( schemas.DictSchema[schemas.T] ): - class Schema_: - types = {frozendict.frozendict} - required = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ "file", - } - - class Properties: - AdditionalMetadata: typing_extensions.TypeAlias = schemas.StrSchema[U] - File: typing_extensions.TypeAlias = schemas.BinarySchema[U] - __annotations__ = { - "additionalMetadata": AdditionalMetadata, - "file": File, - } + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @property - def file(self) -> Schema_.Properties.File[typing.Union[bytes, schemas.FileIO]]: + def file(self) -> File[typing.Union[bytes, schemas.FileIO]]: return self.__getitem__("file") @typing.overload - def __getitem__(self, name: typing_extensions.Literal["file"]) -> Schema_.Properties.File[typing.Union[bytes, schemas.FileIO]]: ... + def __getitem__(self, name: typing_extensions.Literal["file"]) -> File[typing.Union[bytes, schemas.FileIO]]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["additionalMetadata"]) -> Schema_.Properties.AdditionalMetadata[str]: ... + def __getitem__(self, name: typing_extensions.Literal["additionalMetadata"]) -> AdditionalMetadata[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -67,36 +71,18 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], file: typing.Union[ - Schema_.Properties.File[typing.Union[bytes, schemas.FileIO]], + File[typing.Union[bytes, schemas.FileIO]], bytes, io.FileIO, io.BufferedReader ], additionalMetadata: typing.Union[ - Schema_.Properties.AdditionalMetadata[str], + AdditionalMetadata[str], schemas.Unset, str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Schema[frozendict.frozendict]: inst = super().__new__( cls, @@ -111,3 +97,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_upload_files/post/request_body/content/multipart_form_data/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_upload_files/post/request_body/content/multipart_form_data/schema.py index cbc589a3c57..6a5ad3aa12b 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_upload_files/post/request_body/content/multipart_form_data/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_upload_files/post/request_body/content/multipart_form_data/schema.py @@ -10,58 +10,65 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Items: typing_extensions.TypeAlias = schemas.BinarySchema[U] + + +class Files( + schemas.ListSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore + + def __new__( + cls, + arg_: typing.Sequence[ + typing.Union[ + Items[typing.Union[bytes, schemas.FileIO]], + bytes, + io.FileIO, + io.BufferedReader + ] + ], + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> Files[tuple]: + inst = super().__new__( + cls, + arg_, + configuration_=configuration_, + ) + inst = typing.cast( + Files[tuple], + inst + ) + return inst + + def __getitem__(self, name: int) -> Items[typing.Union[bytes, schemas.FileIO]]: + return super().__getitem__(name) + +Properties = typing_extensions.TypedDict( + 'Properties', + { + "files": typing.Type[Files], + } +) + class Schema( schemas.DictSchema[schemas.T] ): - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - - class Files( - schemas.ListSchema[schemas.T] - ): - - - class Schema_: - types = {tuple} - Items: typing_extensions.TypeAlias = schemas.BinarySchema[U] - - def __new__( - cls, - arg_: typing.Sequence[ - typing.Union[ - Schema_.Items[typing.Union[bytes, schemas.FileIO]], - bytes, - io.FileIO, - io.BufferedReader - ] - ], - configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - ) -> Schema.Schema_.Properties.Files[tuple]: - inst = super().__new__( - cls, - arg_, - configuration_=configuration_, - ) - inst = typing.cast( - Schema.Schema_.Properties.Files[tuple], - inst - ) - return inst - - def __getitem__(self, name: int) -> Schema_.Items[typing.Union[bytes, schemas.FileIO]]: - return super().__getitem__(name) - __annotations__ = { - "files": Files, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["files"]) -> Schema_.Properties.Files[tuple]: ... + def __getitem__(self, name: typing_extensions.Literal["files"]) -> Files[tuple]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -89,31 +96,13 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], files: typing.Union[ - Schema_.Properties.Files[tuple], + Files[tuple], schemas.Unset, list, tuple ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Schema[frozendict.frozendict]: inst = super().__new__( cls, @@ -127,3 +116,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_wild_card_responses/get/responses/response_1xx/content/application_json/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_wild_card_responses/get/responses/response_1xx/content/application_json/schema.py index 83bd5a9325f..072e994d56d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_wild_card_responses/get/responses/response_1xx/content/application_json/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_wild_card_responses/get/responses/response_1xx/content/application_json/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_wild_card_responses/get/responses/response_200/content/application_json/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_wild_card_responses/get/responses/response_200/content/application_json/schema.py index 83bd5a9325f..072e994d56d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_wild_card_responses/get/responses/response_200/content/application_json/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_wild_card_responses/get/responses/response_200/content/application_json/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_wild_card_responses/get/responses/response_2xx/content/application_json/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_wild_card_responses/get/responses/response_2xx/content/application_json/schema.py index 83bd5a9325f..072e994d56d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_wild_card_responses/get/responses/response_2xx/content/application_json/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_wild_card_responses/get/responses/response_2xx/content/application_json/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_wild_card_responses/get/responses/response_3xx/content/application_json/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_wild_card_responses/get/responses/response_3xx/content/application_json/schema.py index 83bd5a9325f..072e994d56d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_wild_card_responses/get/responses/response_3xx/content/application_json/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_wild_card_responses/get/responses/response_3xx/content/application_json/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_wild_card_responses/get/responses/response_4xx/content/application_json/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_wild_card_responses/get/responses/response_4xx/content/application_json/schema.py index 83bd5a9325f..072e994d56d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_wild_card_responses/get/responses/response_4xx/content/application_json/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_wild_card_responses/get/responses/response_4xx/content/application_json/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_wild_card_responses/get/responses/response_5xx/content/application_json/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_wild_card_responses/get/responses/response_5xx/content/application_json/schema.py index 83bd5a9325f..072e994d56d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_wild_card_responses/get/responses/response_5xx/content/application_json/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/fake_wild_card_responses/get/responses/response_5xx/content/application_json/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.AnyTypeSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/foo/get/responses/response_default/content/application_json/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/foo/get/responses/response_default/content/application_json/schema.py index eacd76cfd2f..88e4d2e8edc 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/foo/get/responses/response_default/content/application_json/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/foo/get/responses/response_default/content/application_json/schema.py @@ -11,22 +11,16 @@ from petstore_api.shared_imports.schema_imports import * + class Schema( schemas.DictSchema[schemas.T] ): - class Schema_: - types = {frozendict.frozendict} - - class Properties: - - @staticmethod - def string() -> typing.Type[foo.Foo]: - return foo.Foo - __annotations__ = { - "string": string, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload def __getitem__(self, name: typing_extensions.Literal["string"]) -> foo.Foo[frozendict.frozendict]: ... @@ -63,25 +57,7 @@ def __new__( frozendict.frozendict ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Schema[frozendict.frozendict]: inst = super().__new__( cls, @@ -96,4 +72,11 @@ def __new__( ) return inst + from petstore_api.components.schema import foo +Properties = typing_extensions.TypedDict( + 'Properties', + { + "string": typing.Type[foo.Foo], + } +) diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/foo/get/servers/server_0.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/foo/get/servers/server_0.py index c608567dec1..dba4b67ecb2 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/foo/get/servers/server_0.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/foo/get/servers/server_0.py @@ -7,5 +7,5 @@ @dataclasses.dataclass -class Server0(server.Server): - _url: str = "https://path-server-test.petstore.local/v2" +class Server0(server.ServerWithoutVariables): + url: str = "https://path-server-test.petstore.local/v2" diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/foo/get/servers/server_1.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/foo/get/servers/server_1.py index c547659a28d..d72b6fd42af 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/foo/get/servers/server_1.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/foo/get/servers/server_1.py @@ -3,62 +3,102 @@ Generated by: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator """ +from __future__ import annotations +from petstore_api.shared_imports.schema_imports import * from petstore_api.shared_imports.server_imports import * +AdditionalProperties: typing_extensions.TypeAlias = schemas.NotAnyTypeSchema[U] -class _Variables: - - - class Version( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - default = "v1" - enum_value_to_name = { +class Version( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + default: str = "v1" + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { "v1": "V1", "v2": "V2", } - - @schemas.classproperty - def V1(cls): - return cls("v1") # type: ignore - - @schemas.classproperty - def V2(cls): - return cls("v2") # type: ignore - -_VariablesSchemas = typing_extensions.TypedDict( - '_VariablesSchemas', + ) + + @schemas.classproperty + def V1(cls) -> Version[str]: + return cls("v1") # type: ignore + + @schemas.classproperty + def V2(cls) -> Version[str]: + return cls("v2") # type: ignore +Properties = typing_extensions.TypedDict( + 'Properties', { - "version": typing.Type[_Variables.Version], - }, - total=False + "version": typing.Type[Version], + } ) -Variables = typing_extensions.TypedDict( - 'Variables', - { - "version": typing_extensions.Literal[ - "v1", - "v2", + +class Variables( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ + "version", + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore + + @property + def version(self) -> Version[str]: + return self.__getitem__("version") + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["version"]) -> Version[str]: ... + + def __getitem__( + self, + name: typing.Union[ + typing_extensions.Literal["version"], + ] + ): + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + version: typing.Union[ + Version[str], + str ], - }, - total=False -) + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> Variables[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + version=version, + configuration_=configuration_, + ) + inst = typing.cast( + Variables[frozendict.frozendict], + inst + ) + return inst -def _default_variable_schemas() -> _VariablesSchemas: - return { - "version": _Variables.Version, - } @dataclasses.dataclass -class Server1(server.Server): - variables: typing.Optional[Variables] = None - variable_schemas: _VariablesSchemas = dataclasses.field(default_factory=_default_variable_schemas) +class Server1(server.ServerWithVariables): + variables: Variables[frozendict.frozendict] = Variables.from_openapi_data_({ + "version": Version.Schema_.default, + }) + variables_cls: typing.Type[Variables] = Variables _url: str = "https://petstore.swagger.io/{version}" diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_find_by_status/get/parameters/parameter_0/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_find_by_status/get/parameters/parameter_0/schema.py index f5d206ef46c..6c9f7ff2be4 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_find_by_status/get/parameters/parameter_0/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_find_by_status/get/parameters/parameter_0/schema.py @@ -11,48 +11,54 @@ from petstore_api.shared_imports.schema_imports import * + +class Items( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + default: str = "available" + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { + "available": "AVAILABLE", + "pending": "PENDING", + "sold": "SOLD", + } + ) + + @schemas.classproperty + def AVAILABLE(cls) -> Items[str]: + return cls("available") # type: ignore + + @schemas.classproperty + def PENDING(cls) -> Items[str]: + return cls("pending") # type: ignore + + @schemas.classproperty + def SOLD(cls) -> Items[str]: + return cls("sold") # type: ignore + + class Schema( schemas.ListSchema[schemas.T] ): - class Schema_: - types = {tuple} - - - class Items( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - default = "available" - enum_value_to_name = { - "available": "AVAILABLE", - "pending": "PENDING", - "sold": "SOLD", - } - - @schemas.classproperty - def AVAILABLE(cls): - return cls("available") # type: ignore - - @schemas.classproperty - def PENDING(cls): - return cls("pending") # type: ignore - - @schemas.classproperty - def SOLD(cls): - return cls("sold") # type: ignore + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore def __new__( cls, arg_: typing.Sequence[ typing.Union[ - Schema_.Items[str], + Items[str], str ] ], @@ -69,5 +75,6 @@ def __new__( ) return inst - def __getitem__(self, name: int) -> Schema_.Items[str]: + def __getitem__(self, name: int) -> Items[str]: return super().__getitem__(name) + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_find_by_status/servers/server_0.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_find_by_status/servers/server_0.py index c608567dec1..dba4b67ecb2 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_find_by_status/servers/server_0.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_find_by_status/servers/server_0.py @@ -7,5 +7,5 @@ @dataclasses.dataclass -class Server0(server.Server): - _url: str = "https://path-server-test.petstore.local/v2" +class Server0(server.ServerWithoutVariables): + url: str = "https://path-server-test.petstore.local/v2" diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_find_by_status/servers/server_1.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_find_by_status/servers/server_1.py index c547659a28d..d72b6fd42af 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_find_by_status/servers/server_1.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_find_by_status/servers/server_1.py @@ -3,62 +3,102 @@ Generated by: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator """ +from __future__ import annotations +from petstore_api.shared_imports.schema_imports import * from petstore_api.shared_imports.server_imports import * +AdditionalProperties: typing_extensions.TypeAlias = schemas.NotAnyTypeSchema[U] -class _Variables: - - - class Version( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - default = "v1" - enum_value_to_name = { +class Version( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + default: str = "v1" + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { "v1": "V1", "v2": "V2", } - - @schemas.classproperty - def V1(cls): - return cls("v1") # type: ignore - - @schemas.classproperty - def V2(cls): - return cls("v2") # type: ignore - -_VariablesSchemas = typing_extensions.TypedDict( - '_VariablesSchemas', + ) + + @schemas.classproperty + def V1(cls) -> Version[str]: + return cls("v1") # type: ignore + + @schemas.classproperty + def V2(cls) -> Version[str]: + return cls("v2") # type: ignore +Properties = typing_extensions.TypedDict( + 'Properties', { - "version": typing.Type[_Variables.Version], - }, - total=False + "version": typing.Type[Version], + } ) -Variables = typing_extensions.TypedDict( - 'Variables', - { - "version": typing_extensions.Literal[ - "v1", - "v2", + +class Variables( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ + "version", + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore + + @property + def version(self) -> Version[str]: + return self.__getitem__("version") + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["version"]) -> Version[str]: ... + + def __getitem__( + self, + name: typing.Union[ + typing_extensions.Literal["version"], + ] + ): + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + version: typing.Union[ + Version[str], + str ], - }, - total=False -) + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> Variables[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + version=version, + configuration_=configuration_, + ) + inst = typing.cast( + Variables[frozendict.frozendict], + inst + ) + return inst -def _default_variable_schemas() -> _VariablesSchemas: - return { - "version": _Variables.Version, - } @dataclasses.dataclass -class Server1(server.Server): - variables: typing.Optional[Variables] = None - variable_schemas: _VariablesSchemas = dataclasses.field(default_factory=_default_variable_schemas) +class Server1(server.ServerWithVariables): + variables: Variables[frozendict.frozendict] = Variables.from_openapi_data_({ + "version": Version.Schema_.default, + }) + variables_cls: typing.Type[Variables] = Variables _url: str = "https://petstore.swagger.io/{version}" diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_find_by_tags/get/parameters/parameter_0/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_find_by_tags/get/parameters/parameter_0/schema.py index da15d120e4a..de25475a43d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_find_by_tags/get/parameters/parameter_0/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_find_by_tags/get/parameters/parameter_0/schema.py @@ -10,21 +10,24 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Items: typing_extensions.TypeAlias = schemas.StrSchema[U] + class Schema( schemas.ListSchema[schemas.T] ): - class Schema_: - types = {tuple} - Items: typing_extensions.TypeAlias = schemas.StrSchema[U] + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) + items: typing.Type[Items] = dataclasses.field(default_factory=lambda: Items) # type: ignore def __new__( cls, arg_: typing.Sequence[ typing.Union[ - Schema_.Items[str], + Items[str], str ] ], @@ -41,5 +44,6 @@ def __new__( ) return inst - def __getitem__(self, name: int) -> Schema_.Items[str]: + def __getitem__(self, name: int) -> Items[str]: return super().__getitem__(name) + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id/delete/parameters/parameter_0/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id/delete/parameters/parameter_0/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id/delete/parameters/parameter_0/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id/delete/parameters/parameter_0/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id/delete/parameters/parameter_1/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id/delete/parameters/parameter_1/schema.py index cc2fd90961c..db592ea3e5b 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id/delete/parameters/parameter_1/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id/delete/parameters/parameter_1/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.Int64Schema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id/get/parameters/parameter_0/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id/get/parameters/parameter_0/schema.py index cc2fd90961c..db592ea3e5b 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id/get/parameters/parameter_0/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id/get/parameters/parameter_0/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.Int64Schema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id/post/parameters/parameter_0/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id/post/parameters/parameter_0/schema.py index cc2fd90961c..db592ea3e5b 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id/post/parameters/parameter_0/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id/post/parameters/parameter_0/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.Int64Schema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id/post/request_body/content/application_x_www_form_urlencoded/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id/post/request_body/content/application_x_www_form_urlencoded/schema.py index 48f30d5e620..f4340ec25c9 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id/post/request_body/content/application_x_www_form_urlencoded/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id/post/request_body/content/application_x_www_form_urlencoded/schema.py @@ -10,28 +10,32 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +Name: typing_extensions.TypeAlias = schemas.StrSchema[U] +Status: typing_extensions.TypeAlias = schemas.StrSchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "name": typing.Type[Name], + "status": typing.Type[Status], + } +) + class Schema( schemas.DictSchema[schemas.T] ): - class Schema_: - types = {frozendict.frozendict} - - class Properties: - Name: typing_extensions.TypeAlias = schemas.StrSchema[U] - Status: typing_extensions.TypeAlias = schemas.StrSchema[U] - __annotations__ = { - "name": Name, - "status": Status, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["name"]) -> Schema_.Properties.Name[str]: ... + def __getitem__(self, name: typing_extensions.Literal["name"]) -> Name[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["status"]) -> Schema_.Properties.Status[str]: ... + def __getitem__(self, name: typing_extensions.Literal["status"]) -> Status[str]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -60,35 +64,17 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], name: typing.Union[ - Schema_.Properties.Name[str], + Name[str], schemas.Unset, str ] = schemas.unset, status: typing.Union[ - Schema_.Properties.Status[str], + Status[str], schemas.Unset, str ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Schema[frozendict.frozendict]: inst = super().__new__( cls, @@ -103,3 +89,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id_upload_image/post/parameters/parameter_0/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id_upload_image/post/parameters/parameter_0/schema.py index cc2fd90961c..db592ea3e5b 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id_upload_image/post/parameters/parameter_0/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id_upload_image/post/parameters/parameter_0/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.Int64Schema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id_upload_image/post/request_body/content/multipart_form_data/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id_upload_image/post/request_body/content/multipart_form_data/schema.py index 16f492dd51a..e9b5356eebe 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id_upload_image/post/request_body/content/multipart_form_data/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/pet_pet_id_upload_image/post/request_body/content/multipart_form_data/schema.py @@ -10,28 +10,32 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * +AdditionalMetadata: typing_extensions.TypeAlias = schemas.StrSchema[U] +File: typing_extensions.TypeAlias = schemas.BinarySchema[U] +Properties = typing_extensions.TypedDict( + 'Properties', + { + "additionalMetadata": typing.Type[AdditionalMetadata], + "file": typing.Type[File], + } +) + class Schema( schemas.DictSchema[schemas.T] ): - class Schema_: - types = {frozendict.frozendict} - - class Properties: - AdditionalMetadata: typing_extensions.TypeAlias = schemas.StrSchema[U] - File: typing_extensions.TypeAlias = schemas.BinarySchema[U] - __annotations__ = { - "additionalMetadata": AdditionalMetadata, - "file": File, - } + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore @typing.overload - def __getitem__(self, name: typing_extensions.Literal["additionalMetadata"]) -> Schema_.Properties.AdditionalMetadata[str]: ... + def __getitem__(self, name: typing_extensions.Literal["additionalMetadata"]) -> AdditionalMetadata[str]: ... @typing.overload - def __getitem__(self, name: typing_extensions.Literal["file"]) -> Schema_.Properties.File[typing.Union[bytes, schemas.FileIO]]: ... + def __getitem__(self, name: typing_extensions.Literal["file"]) -> File[typing.Union[bytes, schemas.FileIO]]: ... @typing.overload def __getitem__(self, name: str) -> schemas.AnyTypeSchema[typing.Union[ @@ -60,37 +64,19 @@ def __new__( cls, *args_: typing.Union[dict, frozendict.frozendict], additionalMetadata: typing.Union[ - Schema_.Properties.AdditionalMetadata[str], + AdditionalMetadata[str], schemas.Unset, str ] = schemas.unset, file: typing.Union[ - Schema_.Properties.File[typing.Union[bytes, schemas.FileIO]], + File[typing.Union[bytes, schemas.FileIO]], schemas.Unset, bytes, io.FileIO, io.BufferedReader ] = schemas.unset, configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, - **kwargs: typing.Union[ - dict, - frozendict.frozendict, - list, - tuple, - decimal.Decimal, - float, - int, - str, - datetime.date, - datetime.datetime, - uuid.UUID, - bool, - None, - bytes, - io.FileIO, - io.BufferedReader, - schemas.Schema - ], + **kwargs: schemas.INPUT_TYPES_ALL_INCL_SCHEMA ) -> Schema[frozendict.frozendict]: inst = super().__new__( cls, @@ -105,3 +91,4 @@ def __new__( inst ) return inst + diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/store_order_order_id/delete/parameters/parameter_0/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/store_order_order_id/delete/parameters/parameter_0/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/store_order_order_id/delete/parameters/parameter_0/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/store_order_order_id/delete/parameters/parameter_0/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/store_order_order_id/get/parameters/parameter_0/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/store_order_order_id/get/parameters/parameter_0/schema.py index 96d158c3674..5bf2461e229 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/store_order_order_id/get/parameters/parameter_0/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/store_order_order_id/get/parameters/parameter_0/schema.py @@ -11,15 +11,17 @@ from petstore_api.shared_imports.schema_imports import * + class Schema( schemas.Int64Schema[schemas.T] ): - class Schema_: - types = { + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ decimal.Decimal, - } - format = 'int64' - inclusive_maximum = 5 - inclusive_minimum = 1 + }) + format: str = 'int64' + inclusive_maximum: typing.Union[int, float] = 5 + inclusive_minimum: typing.Union[int, float] = 1 diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/user_login/get/parameters/parameter_0/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/user_login/get/parameters/parameter_0/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/user_login/get/parameters/parameter_0/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/user_login/get/parameters/parameter_0/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/user_login/get/parameters/parameter_1/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/user_login/get/parameters/parameter_1/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/user_login/get/parameters/parameter_1/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/user_login/get/parameters/parameter_1/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/user_login/get/responses/response_200/content/application_json/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/user_login/get/responses/response_200/content/application_json/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/user_login/get/responses/response_200/content/application_json/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/user_login/get/responses/response_200/content/application_json/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/user_login/get/responses/response_200/content/application_xml/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/user_login/get/responses/response_200/content/application_xml/schema.py index 905311bf8ad..1f544f8f747 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/user_login/get/responses/response_200/content/application_xml/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/user_login/get/responses/response_200/content/application_xml/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.StrSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/user_login/get/responses/response_200/headers/header_x_expires_after/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/user_login/get/responses/response_200/headers/header_x_expires_after/schema.py index 12bceb3098d..6354f6d5744 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/user_login/get/responses/response_200/headers/header_x_expires_after/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/user_login/get/responses/response_200/headers/header_x_expires_after/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.DateTimeSchema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/paths/user_login/get/responses/response_200/headers/header_x_rate_limit/content/application_json/schema.py b/samples/openapi3/client/petstore/python/src/petstore_api/paths/user_login/get/responses/response_200/headers/header_x_rate_limit/content/application_json/schema.py index af8e03d6a9c..5af8b8a8ede 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/paths/user_login/get/responses/response_200/headers/header_x_rate_limit/content/application_json/schema.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/paths/user_login/get/responses/response_200/headers/header_x_rate_limit/content/application_json/schema.py @@ -9,4 +9,5 @@ from __future__ import annotations from petstore_api.shared_imports.schema_imports import * + Schema: typing_extensions.TypeAlias = schemas.Int32Schema[U] diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/schemas.py b/samples/openapi3/client/petstore/python/src/petstore_api/schemas.py index fba4ffeff18..b16bbe4431c 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/schemas.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/schemas.py @@ -13,6 +13,7 @@ import dataclasses import functools import decimal +import inspect import io import re import types @@ -111,6 +112,20 @@ def add_deeper_validated_schemas(validation_metadata: ValidationMetadata, path_t update(path_to_schemas, other_path_to_schemas) +class SingletonMeta(type): + """ + A singleton class for schemas + Schemas are frozen classes that are never instantiated with init args + All args come from defaults + """ + _instances = {} + + def __call__(cls, *args, **kwargs): + if cls not in cls._instances: + cls._instances[cls] = super().__call__(*args, **kwargs) + return cls._instances[cls] + + class Singleton: """ Enums and singletons are the same @@ -147,14 +162,18 @@ def __repr__(self): return f'<{self.__class__.__name__}: False>' return f'<{self.__class__.__name__}: {super().__repr__()}>' +T = typing.TypeVar('T') -class classproperty: - def __init__(self, fget): - self.fget = fget +class classproperty(typing.Generic[T]): + def __init__(self, method: typing.Callable[..., T]): + self.__method = method + functools.update_wrapper(self, method) # type: ignore - def __get__(self, owner_self, owner_cls): - return self.fget(owner_cls) + def __get__(self, obj, cls=None) -> T: + if cls is None: + cls = type(obj) + return self.__method(cls) class NoneClass(Singleton): @@ -183,32 +202,40 @@ def __bool__(self) -> bool: raise ValueError('Unable to find the boolean value of this instance') +@dataclasses.dataclass(frozen=True) +class PatternInfo: + pattern: str + flags: typing.Optional[re.RegexFlag] = None + + class SchemaTyped: - types: typing.Optional[typing.Set[typing.Type]] + additional_properties: typing.Type[Schema] + all_of: typing.Tuple[typing.Type[Schema], ...] + any_of: typing.Tuple[typing.Type[Schema], ...] + discriminator: typing.Mapping[str, typing.Mapping[str, typing.Type[Schema]]] + default: typing.Union[str, int, float, BoolClass, NoneClass] + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, BoolClass, NoneClass], str] exclusive_maximum: typing.Union[int, float] - inclusive_maximum: typing.Union[int, float] exclusive_minimum: typing.Union[int, float] + format: str + inclusive_maximum: typing.Union[int, float] inclusive_minimum: typing.Union[int, float] + items: typing.Type[Schema] max_items: int - min_items: int - discriminator: typing.Dict[str, typing.Dict[str, typing.Type['Schema']]] - default: typing.Union[str, int, BoolClass] - - - class Properties: - # to hold object properties - pass - - additionalProperties: typing.Optional[typing.Type['Schema']] - max_properties: int - min_properties: int - AllOf: typing.List[typing.Type['Schema']] - OneOf: typing.List[typing.Type['Schema']] - AnyOf: typing.List[typing.Type['Schema']] - _not: typing.Type['Schema'] max_length: int + max_properties: int + min_items: int min_length: int - items: typing.Type['Schema'] + min_properties: int + multiple_of: typing.Union[int, float] + not_: typing.Type[Schema] + one_of: typing.Tuple[typing.Type[Schema], ...] + pattern: PatternInfo + properties: typing.Mapping[str, typing.Type[Schema]] + required: typing.FrozenSet[str] + types: typing.FrozenSet[typing.Type] + unique_items: bool + PathToSchemasType = typing.Dict[ typing.Tuple[typing.Union[str, int], ...], @@ -530,30 +557,30 @@ def validate_multiple_of( return None -def validate_regex( +def validate_pattern( arg: typing.Any, - regex_dict: typing.Dict, + pattern_info: PatternInfo, cls: typing.Type, validation_metadata: ValidationMetadata, ) -> None: if not isinstance(arg, str): return None - flags = regex_dict.get('flags', 0) - if not re.search(regex_dict['pattern'], arg, flags=flags): + flags = pattern_info.flags if pattern_info.flags is not None else 0 + if not re.search(pattern_info.pattern, arg, flags=flags): if flags != 0: # Don't print the regex flags if the flags are not # specified in the OAS document. _raise_validation_error_message( value=arg, constraint_msg="must match regular expression", - constraint_value=regex_dict['pattern'], + constraint_value=pattern_info.pattern, path_to_item=validation_metadata.path_to_item, additional_txt=" with flags=`{}`".format(flags) ) _raise_validation_error_message( value=arg, constraint_msg="must match regular expression", - constraint_value=regex_dict['pattern'], + constraint_value=pattern_info.pattern, path_to_item=validation_metadata.path_to_item ) return None @@ -649,8 +676,8 @@ def __parse_isodate(self, dt_str: str) -> typing.Tuple[typing.Tuple[int, int, in def __parse_isotime(self, dt_str: str) -> typing.Tuple[int, int, int, int, typing.Optional[typing.Union[tz.tzutc, tz.tzoffset]]]: dt_str_ascii = self.__get_ascii_bytes(dt_str) values = self._parse_isotime(dt_str_ascii) # type: ignore - components: typing.Tuple[int, int, int, int, typing.Optional[typing.Union[tz.tzutc, tz.tzoffset]]] = tuple(values) - return tuple(components) + components: typing.Tuple[int, int, int, int, typing.Optional[typing.Union[tz.tzutc, tz.tzoffset]]] = tuple(values) # type: ignore + return components def parse_isodatetime(self, dt_str: str) -> datetime.datetime: components, pos = self.__parse_isodate(dt_str) @@ -786,17 +813,20 @@ def _get_class(item_cls: typing.Union[types.FunctionType, staticmethod, typing.T elif isinstance(item_cls, staticmethod): # referenced schema return item_cls.__func__() - return item_cls + elif isinstance(item_cls, type): + return item_cls + raise ValueError('invalid class value passed in') def validate_items( arg: typing.Any, - item_cls: typing.Type, + item_cls: typing.Type[Schema], cls: typing.Type, validation_metadata: ValidationMetadata, ) -> typing.Optional[PathToSchemasType]: if not isinstance(arg, tuple): return None + schema = _get_class(additional_properties_cls) item_cls = _get_class(item_cls) path_to_schemas = {} for i, value in enumerate(arg): @@ -816,17 +846,17 @@ def validate_items( def validate_properties( arg: typing.Any, - properties: typing.Type, + properties: typing.Mapping[str, typing.Type[Schema]], cls: typing.Type, validation_metadata: ValidationMetadata, ) -> typing.Optional[PathToSchemasType]: if not isinstance(arg, frozendict.frozendict): return None path_to_schemas = {} - present_properties = {k: v for k, v, in arg.items() if k in properties.__annotations__} + present_properties = {k: v for k, v, in arg.items() if k in properties} for property_name, value in present_properties.items(): path_to_item = validation_metadata.path_to_item + (property_name,) - schema = properties.__annotations__[property_name] + schema = properties[property_name] schema = _get_class(schema) arg_validation_metadata = ValidationMetadata( path_to_item=path_to_item, @@ -843,16 +873,17 @@ def validate_properties( def validate_additional_properties( arg: typing.Any, - additional_properties_schema: typing.Type, + additional_properties_cls: typing.Type[Schema], cls: typing.Type, validation_metadata: ValidationMetadata, ) -> typing.Optional[PathToSchemasType]: if not isinstance(arg, frozendict.frozendict): return None - schema = _get_class(additional_properties_schema) + schema = _get_class(additional_properties_cls) path_to_schemas = {} - properties_annotations = cls.Schema_.Properties.__annotations__ if hasattr(cls.Schema_, 'Properties') else {} - present_additional_properties = {k: v for k, v, in arg.items() if k not in properties_annotations} + cls_schema = cls.Schema_() + properties = cls_schema.properties if hasattr(cls_schema, 'properties') else {} + present_additional_properties = {k: v for k, v, in arg.items() if k not in properties} for property_name, value in present_additional_properties.items(): path_to_item = validation_metadata.path_to_item + (property_name,) arg_validation_metadata = ValidationMetadata( @@ -870,14 +901,14 @@ def validate_additional_properties( def validate_one_of( arg: typing.Any, - one_of_container_cls: typing.Type, + classes: typing.Tuple[typing.Type[Schema], ...], cls: 'Schema', validation_metadata: ValidationMetadata, ) -> PathToSchemasType: oneof_classes = [] path_to_schemas = collections.defaultdict(set) - for one_of_cls in one_of_container_cls.classes: - schema = _get_class(one_of_cls) + for schema in classes: + schema = _get_class(schema) if schema in path_to_schemas[validation_metadata.path_to_item]: oneof_classes.append(schema) continue @@ -914,14 +945,14 @@ def validate_one_of( def validate_any_of( arg: typing.Any, - any_of_container_cls: typing.Type, + classes: typing.Tuple[typing.Type[Schema], ...], cls: 'Schema', validation_metadata: ValidationMetadata, ) -> PathToSchemasType: anyof_classes = [] path_to_schemas = collections.defaultdict(set) - for any_of_cls in any_of_container_cls.classes: - schema = _get_class(any_of_cls) + for schema in classes: + schema = _get_class(schema) if schema is cls: """ optimistically assume that cls schema will pass validation @@ -951,13 +982,13 @@ def validate_any_of( def validate_all_of( arg: typing.Any, - all_of_cls: typing.Type, + classes: typing.Tuple[typing.Type[Schema], ...], cls: typing.Type, validation_metadata: ValidationMetadata, ) -> PathToSchemasType: path_to_schemas = collections.defaultdict(set) - for allof_cls in all_of_cls.classes: - schema = _get_class(allof_cls) + for schema in classes: + schema = _get_class(schema) if schema is cls: """ optimistically assume that cls schema will pass validation @@ -974,7 +1005,7 @@ def validate_all_of( def validate_not( arg: typing.Any, - not_cls: typing.Type, + not_cls: typing.Type[Schema], cls: typing.Type, validation_metadata: ValidationMetadata, ) -> None: @@ -1016,38 +1047,36 @@ def __get_discriminated_class(cls, disc_property_name: str, disc_payload_value: """ Used in schemas with discriminators """ - if not hasattr(cls.Schema_, 'discriminator'): + cls_schema = cls.Schema_() + if not hasattr(cls_schema, 'discriminator'): return None - disc = cls.Schema_.discriminator() + disc = cls_schema.discriminator if disc_property_name not in disc: return None discriminated_cls = disc[disc_property_name].get(disc_payload_value) if discriminated_cls is not None: return discriminated_cls if not ( - hasattr(cls.Schema_, 'AllOf') or - hasattr(cls.Schema_, 'OneOf') or - hasattr(cls.Schema_, 'AnyOf') + hasattr(cls_schema, 'all_of') or + hasattr(cls_schema, 'one_of') or + hasattr(cls_schema, 'any_of') ): return None # TODO stop traveling if a cycle is hit - if hasattr(cls.Schema_, 'AllOf'): - for allof_cls in cls.Schema_.AllOf.classes: - allof_cls = _get_class(allof_cls) + if hasattr(cls_schema, 'all_of'): + for allof_cls in cls_schema.all_of: discriminated_cls = __get_discriminated_class( allof_cls, disc_property_name=disc_property_name, disc_payload_value=disc_payload_value) if discriminated_cls is not None: return discriminated_cls - if hasattr(cls.Schema_, 'OneOf'): - for oneof_cls in cls.Schema_.OneOf.classes: - oneof_cls = _get_class(oneof_cls) + if hasattr(cls_schema, 'one_of'): + for oneof_cls in cls_schema.one_of: discriminated_cls = __get_discriminated_class( oneof_cls, disc_property_name=disc_property_name, disc_payload_value=disc_payload_value) if discriminated_cls is not None: return discriminated_cls - if hasattr(cls.Schema_, 'AnyOf'): - for anyof_cls in cls.Schema_.AnyOf.classes: - anyof_cls = _get_class(anyof_cls) + if hasattr(cls_schema, 'any_of'): + for anyof_cls in cls_schema.any_of: discriminated_cls = __get_discriminated_class( anyof_cls, disc_property_name=disc_property_name, disc_payload_value=disc_payload_value) if discriminated_cls is not None: @@ -1057,13 +1086,12 @@ def __get_discriminated_class(cls, disc_property_name: str, disc_payload_value: def validate_discriminator( arg: typing.Any, - discriminator_fn: typing.Type, + discriminator: typing.Mapping[str, typing.Mapping[str, typing.Type[Schema]]], cls: typing.Type, validation_metadata: ValidationMetadata, ) -> typing.Optional[PathToSchemasType]: if not isinstance(arg, frozendict.frozendict): return None - discriminator = discriminator_fn.__func__() disc_prop_name = list(discriminator.keys())[0] __ensure_discriminator_value_present(disc_prop_name, validation_metadata, arg) discriminated_cls = __get_discriminated_class( @@ -1112,24 +1140,19 @@ def validate_discriminator( 'inclusive_maximum': validate_inclusive_maximum, 'exclusive_maximum': validate_exclusive_maximum, 'multiple_of': validate_multiple_of, - 'regex': validate_regex, + 'pattern': validate_pattern, 'format': validate_format, 'required': validate_required, 'items': validate_items, - 'Items': validate_items, - 'Properties': validate_properties, - 'AdditionalProperties': validate_additional_properties, + 'properties': validate_properties, 'additional_properties': validate_additional_properties, - 'OneOf': validate_one_of, - 'AnyOf': validate_any_of, - 'AllOf': validate_all_of, - '_not': validate_not, - '_Not': validate_not, - 'ModelNot': validate_not, + 'one_of': validate_one_of, + 'any_of': validate_any_of, + 'all_of': validate_all_of, + 'not_': validate_not, 'discriminator': validate_discriminator } -T = typing.TypeVar('T') U = typing.TypeVar('U') class Schema(typing.Generic[T]): @@ -1158,9 +1181,10 @@ def _validate( All keyword validation except for type checking was done in calling stack frames If those validations passed, the validated classes are collected in path_to_schemas """ + cls_schema = cls.Schema_() json_schema_data = { k: v - for k, v in vars(cls.Schema_).items() + for k, v in vars(cls_schema).items() if k not in cls.__excluded_cls_properties and k not in validation_metadata.configuration.disabled_json_schema_python_keywords @@ -1276,7 +1300,7 @@ def __get_new_cls( """ cls._process_schema_classes(schema_classes) enum_schema = any( - issubclass(this_cls, Schema) and hasattr(this_cls.Schema_, "enum_value_to_name") + issubclass(this_cls, Schema) and hasattr(this_cls.Schema_(), "enum_value_to_name") for this_cls in schema_classes ) inheritable_primitive_type = schema_classes.intersection(cls.__inheritable_primitive_types_set) @@ -1396,9 +1420,11 @@ def __new__( bytes, io.FileIO, io.BufferedReader, - 'Schema', ], + 'Schema', + ], configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None, **kwargs: typing.Union[ + Unset, dict, frozendict.frozendict, list, @@ -1415,7 +1441,7 @@ def __new__( bytes, io.FileIO, io.BufferedReader, - 'Schema', Unset + 'Schema', ] ): """ @@ -1971,7 +1997,8 @@ def cast_to_allowed_types( bytes, io.FileIO, io.BufferedReader, - 'Schema', ], + '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.frozendict, tuple]]], path_to_item: typing.Tuple[typing.Union[str, int], ...], @@ -2100,8 +2127,9 @@ class ListSchema( Schema[T], TupleMixin ): - class Schema_: - types = {tuple} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({tuple}) @classmethod def from_openapi_data_(cls, arg: typing.Sequence[typing.Any], configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2116,8 +2144,9 @@ class NoneSchema( Schema[T], NoneMixin ): - class Schema_: - types = {NoneClass} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({NoneClass}) @classmethod def from_openapi_data_(cls, arg: None, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2136,8 +2165,9 @@ class NumberSchema( This is used for type: number with no format Both integers AND floats are accepted """ - class Schema_: - types = {decimal.Decimal} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) @classmethod def from_openapi_data_(cls, arg: typing.Union[int, float], configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2160,9 +2190,10 @@ def as_int_(self) -> int: class IntSchema(IntBase, NumberSchema[T]): - class Schema_: - types = {decimal.Decimal} - format = 'int' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) + format: str = 'int' @classmethod def from_openapi_data_(cls, arg: int, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2176,9 +2207,10 @@ def __new__(cls, arg_: typing.Union[decimal.Decimal, int], **kwargs: schema_conf class Int32Schema( IntSchema[T] ): - class Schema_: - types = {decimal.Decimal} - format = 'int32' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) + format: str = 'int32' def __new__(cls, arg_: typing.Union[decimal.Decimal, int], **kwargs: schema_configuration.SchemaConfiguration) -> Int32Schema[decimal.Decimal]: inst = super().__new__(cls, arg_, **kwargs) @@ -2188,9 +2220,10 @@ def __new__(cls, arg_: typing.Union[decimal.Decimal, int], **kwargs: schema_conf class Int64Schema( IntSchema[T] ): - class Schema_: - types = {decimal.Decimal} - format = 'int64' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) + format: str = 'int64' def __new__(cls, arg_: typing.Union[decimal.Decimal, int], **kwargs: schema_configuration.SchemaConfiguration) -> Int64Schema[decimal.Decimal]: inst = super().__new__(cls, arg_, **kwargs) @@ -2200,9 +2233,10 @@ def __new__(cls, arg_: typing.Union[decimal.Decimal, int], **kwargs: schema_conf class Float32Schema( NumberSchema[T] ): - class Schema_: - types = {decimal.Decimal} - format = 'float' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) + format: str = 'float' @classmethod def from_openapi_data_(cls, arg: float, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2216,9 +2250,10 @@ def __new__(cls, arg_: typing.Union[decimal.Decimal, int, float], **kwargs: sche class Float64Schema( NumberSchema[T] ): - class Schema_: - types = {decimal.Decimal} - format = 'double' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({decimal.Decimal}) + format: str = 'double' @classmethod def from_openapi_data_(cls, arg: float, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2240,8 +2275,9 @@ class StrSchema( - type: string (format unset) - type: string, format: date """ - class Schema_: - types = {str} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({str}) @classmethod def from_openapi_data_(cls, arg: str, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None) -> StrSchema[str]: @@ -2252,9 +2288,10 @@ def __new__(cls, arg_: typing.Union[str, datetime.date, datetime.datetime, uuid. class UUIDSchema(UUIDBase, StrSchema[T]): - class Schema_: - types = {str} - format = 'uuid' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({str}) + format: str = 'uuid' def __new__(cls, arg_: typing.Union[str, uuid.UUID], **kwargs: schema_configuration.SchemaConfiguration) -> UUIDSchema[str]: inst = super().__new__(cls, arg_, **kwargs) @@ -2262,9 +2299,10 @@ def __new__(cls, arg_: typing.Union[str, uuid.UUID], **kwargs: schema_configurat class DateSchema(DateBase, StrSchema[T]): - class Schema_: - types = {str} - format = 'date' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({str}) + format: str = 'date' def __new__(cls, arg_: typing.Union[str, datetime.date], **kwargs: schema_configuration.SchemaConfiguration) -> DateSchema[str]: inst = super().__new__(cls, arg_, **kwargs) @@ -2272,9 +2310,10 @@ def __new__(cls, arg_: typing.Union[str, datetime.date], **kwargs: schema_config class DateTimeSchema(DateTimeBase, StrSchema[T]): - class Schema_: - types = {str} - format = 'date-time' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({str}) + format: str = 'date-time' def __new__(cls, arg_: typing.Union[str, datetime.datetime], **kwargs: schema_configuration.SchemaConfiguration) -> DateTimeSchema[str]: inst = super().__new__(cls, arg_, **kwargs) @@ -2282,9 +2321,10 @@ def __new__(cls, arg_: typing.Union[str, datetime.datetime], **kwargs: schema_co class DecimalSchema(DecimalBase, StrSchema[T]): - class Schema_: - types = {str} - format = 'number' + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({str}) + format: str = 'number' def __new__(cls, arg_: str, **kwargs: schema_configuration.SchemaConfiguration) -> DecimalSchema[str]: """ @@ -2306,8 +2346,9 @@ class BytesSchema( """ this class will subclass bytes and is immutable """ - class Schema_: - types = {bytes} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({bytes}) def __new__(cls, arg_: bytes, **kwargs: schema_configuration.SchemaConfiguration) -> BytesSchema[bytes]: super_cls: typing.Type = super(Schema, cls) @@ -2334,8 +2375,9 @@ class FileSchema( - to allow file reading and writing to disk - to be able to preserve file name info """ - class Schema_: - types = {FileIO} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({FileIO}) def __new__(cls, arg_: typing.Union[io.FileIO, io.BufferedReader], **kwargs: schema_configuration.SchemaConfiguration) -> FileSchema[FileIO]: super_cls: typing.Type = super(Schema, cls) @@ -2346,15 +2388,15 @@ class BinarySchema( Schema[T], BinaryMixin ): - class Schema_: - types = {FileIO, bytes} - format = 'binary' - - class OneOf: - classes = [ - BytesSchema, - FileSchema, - ] + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({FileIO, bytes}) + format: str = 'binary' + + one_of: typing.Tuple[typing.Type[Schema], ...] = ( + BytesSchema, + FileSchema, + ) def __new__(cls, arg_: typing.Union[io.FileIO, io.BufferedReader, bytes], **kwargs: schema_configuration.SchemaConfiguration) -> BinarySchema[typing.Union[FileIO, bytes]]: return super().__new__(cls, arg_) @@ -2365,8 +2407,9 @@ class BoolSchema( Schema[T], BoolMixin ): - class Schema_: - types = {BoolClass} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({BoolClass}) @classmethod def from_openapi_data_(cls, arg: bool, configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2387,7 +2430,8 @@ class AnyTypeSchema( NoneFrozenDictTupleStrDecimalBoolFileBytesMixin ): # Python representation of a schema defined as true or {} - class Schema_: + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): pass def __new__( @@ -2427,7 +2471,8 @@ def __new__( Schema, bytes, io.FileIO, - io.BufferedReader + io.BufferedReader, + Unset ] ) -> AnyTypeSchema[typing.Union[ NoneClass, @@ -2497,9 +2542,9 @@ class NotAnyTypeSchema(AnyTypeSchema[T]): Does not allow inputs in of AnyType Note: validations on this class are never run because the code knows that no inputs will ever validate """ - - class Schema_: - _not = AnyTypeSchema[U] + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + not_: typing.Type[Schema] = AnyTypeSchema def __new__( cls, @@ -2515,8 +2560,9 @@ class DictSchema( Schema[T], FrozenDictMixin ): - class Schema_: - types = {frozendict.frozendict} + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) @classmethod def from_openapi_data_(cls, arg: typing.Dict[str, typing.Any], configuration_: typing.Optional[schema_configuration.SchemaConfiguration] = None): @@ -2552,3 +2598,57 @@ def get_new_class( def log_cache_usage(cache_fn): if LOG_CACHE_USAGE: print(cache_fn.__name__, cache_fn.cache_info()) + + +W = typing.TypeVar('W', bound=typing_extensions.TypedDict) + +def typed_dict_to_instance(t_dict: typing.Type[W]) -> W: + res = {} + for key, val in t_dict.__annotations__.items(): + if isinstance(val, typing._GenericAlias): # type: ignore + # typing.Type[W] -> W + val_cls = typing_extensions.get_args(val)[0] + res[key] = val_cls + return res # type: ignore + +X = typing.TypeVar('X', bound=typing.Tuple) + +def tuple_to_instance(tup: typing.Type[X]) -> X: + res = [] + for arg in typing_extensions.get_args(tup): + if isinstance(arg, typing._GenericAlias): # type: ignore + # typing.Type[Schema] -> Schema + arg_cls = typing_extensions.get_args(arg)[0] + res.append(arg_cls) + return tuple(res) # type: ignore + +INPUT_TYPES_ALL_INCL_SCHEMA = typing.Union[ + dict, + frozendict.frozendict, + list, + tuple, + decimal.Decimal, + float, + int, + str, + datetime.date, + datetime.datetime, + uuid.UUID, + bool, + None, + bytes, + io.FileIO, + io.BufferedReader, + Schema +] + +INPUT_BASE_TYPES = typing.Union[ + frozendict.frozendict, + str, + decimal.Decimal, + BoolClass, + NoneClass, + tuple, + bytes, + FileIO +] \ No newline at end of file diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/server.py b/samples/openapi3/client/petstore/python/src/petstore_api/server.py index eaacfd90e79..25e04db25c6 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/server.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/server.py @@ -6,30 +6,29 @@ Generated by: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator """ +from __future__ import annotations import abc import dataclasses import typing @dataclasses.dataclass -class Server(abc.ABC): +class ServerWithoutVariables(abc.ABC): + url: str + + +@dataclasses.dataclass +class ServerWithVariables(abc.ABC): _url: str - variables: typing.Optional[typing.Dict[str, str]] = None - variable_schemas: typing.Optional[typing.Dict[str, typing.Type['schemas.Schema']]] = None + variables: schemas.DictSchema + variables_cls: typing.Type[schemas.DictSchema] url: str = dataclasses.field(init=False) def __post_init__(self): - if not self.variable_schemas: - self.url = self._url - return url = self._url - for (key, schema) in self.variable_schemas.items(): - if self.variables and key in self.variables: - value = self.variables[key] - cast_value = schema(value) - else: - cast_value = schema.Schema_.default - cast_value = typing.cast(str, cast_value) + assert isinstance (self.variables, self.variables_cls) + for (key, value) in self.variables.items(): + cast_value = typing.cast(str, value) url = url.replace("{" + key + "}", cast_value) self.url = url diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/servers/server_0.py b/samples/openapi3/client/petstore/python/src/petstore_api/servers/server_0.py index ae530125587..a2e2a01424c 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/servers/server_0.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/servers/server_0.py @@ -3,101 +3,153 @@ Generated by: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator """ +from __future__ import annotations +from petstore_api.shared_imports.schema_imports import * from petstore_api.shared_imports.server_imports import * +AdditionalProperties: typing_extensions.TypeAlias = schemas.NotAnyTypeSchema[U] -class _Variables: - - - class Server( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - default = "petstore" - enum_value_to_name = { +class Server( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + default: str = "petstore" + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { "petstore": "PETSTORE", "qa-petstore": "QA_HYPHEN_MINUS_PETSTORE", "dev-petstore": "DEV_HYPHEN_MINUS_PETSTORE", } - - @schemas.classproperty - def PETSTORE(cls): - return cls("petstore") # type: ignore - - @schemas.classproperty - def QA_HYPHEN_MINUS_PETSTORE(cls): - return cls("qa-petstore") # type: ignore - - @schemas.classproperty - def DEV_HYPHEN_MINUS_PETSTORE(cls): - return cls("dev-petstore") # type: ignore + ) + @schemas.classproperty + def PETSTORE(cls) -> Server[str]: + return cls("petstore") # type: ignore - class Port( - schemas.StrSchema[schemas.T] - ): - + @schemas.classproperty + def QA_HYPHEN_MINUS_PETSTORE(cls) -> Server[str]: + return cls("qa-petstore") # type: ignore - class Schema_: - types = { - str, - } - default = "80" - enum_value_to_name = { + @schemas.classproperty + def DEV_HYPHEN_MINUS_PETSTORE(cls) -> Server[str]: + return cls("dev-petstore") # type: ignore + + +class Port( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + default: str = "80" + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { "80": "POSITIVE_80", "8080": "POSITIVE_8080", } - - @schemas.classproperty - def POSITIVE_80(cls): - return cls("80") # type: ignore - - @schemas.classproperty - def POSITIVE_8080(cls): - return cls("8080") # type: ignore - -_VariablesSchemas = typing_extensions.TypedDict( - '_VariablesSchemas', + ) + + @schemas.classproperty + def POSITIVE_80(cls) -> Port[str]: + return cls("80") # type: ignore + + @schemas.classproperty + def POSITIVE_8080(cls) -> Port[str]: + return cls("8080") # type: ignore +Properties = typing_extensions.TypedDict( + 'Properties', { - "server": typing.Type[_Variables.Server], - "port": typing.Type[_Variables.Port], - }, - total=False + "server": typing.Type[Server], + "port": typing.Type[Port], + } ) -Variables = typing_extensions.TypedDict( - 'Variables', - { - "server": typing_extensions.Literal[ - "petstore", - "qa-petstore", - "dev-petstore", + +class Variables( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ + "port", + "server", + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore + + @property + def port(self) -> Port[str]: + return self.__getitem__("port") + + @property + def server(self) -> Server[str]: + return self.__getitem__("server") + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["port"]) -> Port[str]: ... + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["server"]) -> Server[str]: ... + + def __getitem__( + self, + name: typing.Union[ + typing_extensions.Literal["port"], + typing_extensions.Literal["server"], + ] + ): + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + port: typing.Union[ + Port[str], + str ], - "port": typing_extensions.Literal[ - "80", - "8080", + server: typing.Union[ + Server[str], + str ], - }, - total=False -) + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> Variables[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + port=port, + server=server, + configuration_=configuration_, + ) + inst = typing.cast( + Variables[frozendict.frozendict], + inst + ) + return inst -def _default_variable_schemas() -> _VariablesSchemas: - return { - "server": _Variables.Server, - "port": _Variables.Port, - } @dataclasses.dataclass -class Server0(server.Server): +class Server0(server.ServerWithVariables): ''' petstore server ''' - variables: typing.Optional[Variables] = None - variable_schemas: _VariablesSchemas = dataclasses.field(default_factory=_default_variable_schemas) + variables: Variables[frozendict.frozendict] = Variables.from_openapi_data_({ + "server": Server.Schema_.default, + "port": Port.Schema_.default, + }) + variables_cls: typing.Type[Variables] = Variables _url: str = "http://{server}.swagger.io:{port}/v2" diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/servers/server_1.py b/samples/openapi3/client/petstore/python/src/petstore_api/servers/server_1.py index 1e80e2229bb..cbf5b71e965 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/servers/server_1.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/servers/server_1.py @@ -3,65 +3,105 @@ Generated by: https://github.com/openapi-json-schema-tools/openapi-json-schema-generator """ +from __future__ import annotations +from petstore_api.shared_imports.schema_imports import * from petstore_api.shared_imports.server_imports import * +AdditionalProperties: typing_extensions.TypeAlias = schemas.NotAnyTypeSchema[U] -class _Variables: - - - class Version( - schemas.StrSchema[schemas.T] - ): - - - class Schema_: - types = { - str, - } - default = "v2" - enum_value_to_name = { +class Version( + schemas.StrSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({ + str, + }) + default: str = "v2" + enum_value_to_name: typing.Mapping[typing.Union[int, float, str, schemas.BoolClass, schemas.NoneClass], str] = dataclasses.field( + default_factory=lambda: { "v1": "V1", "v2": "V2", } - - @schemas.classproperty - def V1(cls): - return cls("v1") # type: ignore - - @schemas.classproperty - def V2(cls): - return cls("v2") # type: ignore - -_VariablesSchemas = typing_extensions.TypedDict( - '_VariablesSchemas', + ) + + @schemas.classproperty + def V1(cls) -> Version[str]: + return cls("v1") # type: ignore + + @schemas.classproperty + def V2(cls) -> Version[str]: + return cls("v2") # type: ignore +Properties = typing_extensions.TypedDict( + 'Properties', { - "version": typing.Type[_Variables.Version], - }, - total=False + "version": typing.Type[Version], + } ) -Variables = typing_extensions.TypedDict( - 'Variables', - { - "version": typing_extensions.Literal[ - "v1", - "v2", + +class Variables( + schemas.DictSchema[schemas.T] +): + + + @dataclasses.dataclass(frozen=True) + class Schema_(metaclass=schemas.SingletonMeta): + types: typing.FrozenSet[typing.Type] = frozenset({frozendict.frozendict}) + required: typing.FrozenSet[str] = frozenset({ + "version", + }) + properties: Properties = dataclasses.field(default_factory=lambda: schemas.typed_dict_to_instance(Properties)) # type: ignore + additional_properties: typing.Type[AdditionalProperties] = dataclasses.field(default_factory=lambda: AdditionalProperties) # type: ignore + + @property + def version(self) -> Version[str]: + return self.__getitem__("version") + + @typing.overload + def __getitem__(self, name: typing_extensions.Literal["version"]) -> Version[str]: ... + + def __getitem__( + self, + name: typing.Union[ + typing_extensions.Literal["version"], + ] + ): + # dict_instance[name] accessor + return super().__getitem__(name) + + def __new__( + cls, + *args_: typing.Union[dict, frozendict.frozendict], + version: typing.Union[ + Version[str], + str ], - }, - total=False -) + configuration_: typing.Optional[schemas.schema_configuration.SchemaConfiguration] = None, + ) -> Variables[frozendict.frozendict]: + inst = super().__new__( + cls, + *args_, + version=version, + configuration_=configuration_, + ) + inst = typing.cast( + Variables[frozendict.frozendict], + inst + ) + return inst -def _default_variable_schemas() -> _VariablesSchemas: - return { - "version": _Variables.Version, - } @dataclasses.dataclass -class Server1(server.Server): +class Server1(server.ServerWithVariables): ''' The local server ''' - variables: typing.Optional[Variables] = None - variable_schemas: _VariablesSchemas = dataclasses.field(default_factory=_default_variable_schemas) + variables: Variables[frozendict.frozendict] = Variables.from_openapi_data_({ + "version": Version.Schema_.default, + }) + variables_cls: typing.Type[Variables] = Variables _url: str = "https://localhost:8080/{version}" diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/servers/server_2.py b/samples/openapi3/client/petstore/python/src/petstore_api/servers/server_2.py index dbc48052d9f..4ceeb3ffc26 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/servers/server_2.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/servers/server_2.py @@ -7,8 +7,8 @@ @dataclasses.dataclass -class Server2(server.Server): +class Server2(server.ServerWithoutVariables): ''' staging server with no variables ''' - _url: str = "https://localhost:8080" + url: str = "https://localhost:8080" diff --git a/samples/openapi3/client/petstore/python/src/petstore_api/shared_imports/schema_imports.py b/samples/openapi3/client/petstore/python/src/petstore_api/shared_imports/schema_imports.py index a617a45974c..91fe007058d 100644 --- a/samples/openapi3/client/petstore/python/src/petstore_api/shared_imports/schema_imports.py +++ b/samples/openapi3/client/petstore/python/src/petstore_api/shared_imports/schema_imports.py @@ -1,3 +1,4 @@ +import dataclasses import datetime import decimal import io diff --git a/samples/openapi3/client/petstore/python/tests_manual/test_additional_properties_validator.py b/samples/openapi3/client/petstore/python/tests_manual/test_additional_properties_validator.py index cd5e601dea4..13d4462545b 100644 --- a/samples/openapi3/client/petstore/python/tests_manual/test_additional_properties_validator.py +++ b/samples/openapi3/client/petstore/python/tests_manual/test_additional_properties_validator.py @@ -30,8 +30,8 @@ def test_additional_properties_validator(self): assert add_prop == 'abc' assert isinstance(add_prop, str) assert isinstance(add_prop, schemas.AnyTypeSchema) - assert isinstance(add_prop, AdditionalPropertiesValidator.Schema_.AllOf.classes[1].Schema_.AdditionalProperties) - assert isinstance(add_prop, AdditionalPropertiesValidator.Schema_.AllOf.classes[2].Schema_.AdditionalProperties) + assert isinstance(add_prop, AdditionalPropertiesValidator.Schema_().all_of[1].Schema_().additional_properties) + assert isinstance(add_prop, AdditionalPropertiesValidator.Schema_().all_of[2].Schema_().additional_properties) assert not isinstance(add_prop, schemas.UnsetAnyTypeSchema) diff --git a/samples/openapi3/client/petstore/python/tests_manual/test_animal.py b/samples/openapi3/client/petstore/python/tests_manual/test_animal.py index fcbd99af52d..3972a5f2d6c 100644 --- a/samples/openapi3/client/petstore/python/tests_manual/test_animal.py +++ b/samples/openapi3/client/petstore/python/tests_manual/test_animal.py @@ -15,8 +15,8 @@ import frozendict import petstore_api -from petstore_api.components.schema.cat import Cat -from petstore_api.components.schema.dog import Dog +from petstore_api.components.schema import cat +from petstore_api.components.schema import dog from petstore_api.components.schema.animal import Animal from petstore_api.schemas import StrSchema, BoolSchema @@ -42,8 +42,8 @@ def testAnimal(self): animal = Animal(className='Cat', color='black') assert isinstance(animal, frozendict.frozendict) - assert isinstance(animal, Cat) - assert isinstance(animal, Cat.Schema_.AllOf.classes[1]) + assert isinstance(animal, cat.Cat) + assert isinstance(animal, cat._1) assert isinstance(animal, Animal) assert set(animal.keys()) == {'className', 'color'} assert animal.className == 'Cat' @@ -55,8 +55,8 @@ def testAnimal(self): animal = Animal(className='Cat', color='black', declawed=True) assert isinstance(animal, Animal) assert isinstance(animal, frozendict.frozendict) - assert isinstance(animal, Cat) - assert isinstance(animal, Cat.Schema_.AllOf.classes[1]) + assert isinstance(animal, cat.Cat) + assert isinstance(animal, cat._1) assert set(animal.keys()) == {'className', 'color', 'declawed'} assert animal.className == 'Cat' assert animal["color"] == 'black' @@ -69,8 +69,8 @@ def testAnimal(self): animal = Animal(className='Dog', color='black') assert isinstance(animal, Animal) assert isinstance(animal, frozendict.frozendict) - assert isinstance(animal, Dog) - assert isinstance(animal, Dog.Schema_.AllOf.classes[1]) + assert isinstance(animal, dog.Dog) + assert isinstance(animal, dog._1) assert set(animal.keys()) == {'className', 'color'} assert animal.className == 'Dog' assert animal["color"] == 'black' @@ -81,8 +81,8 @@ def testAnimal(self): animal = Animal(className='Dog', color='black', breed='Labrador') assert isinstance(animal, Animal) assert isinstance(animal, frozendict.frozendict) - assert isinstance(animal, Dog) - assert isinstance(animal, Dog.Schema_.AllOf.classes[1]) + assert isinstance(animal, dog.Dog) + assert isinstance(animal, dog._1) assert set(animal.keys()) == {'className', 'color', 'breed'} assert animal.className == 'Dog' assert animal["color"] == 'black' diff --git a/samples/openapi3/client/petstore/python/tests_manual/test_any_type_schema.py b/samples/openapi3/client/petstore/python/tests_manual/test_any_type_schema.py index 69539c3bdab..16fd7a3e043 100644 --- a/samples/openapi3/client/petstore/python/tests_manual/test_any_type_schema.py +++ b/samples/openapi3/client/petstore/python/tests_manual/test_any_type_schema.py @@ -1,4 +1,3 @@ -# coding: utf-8 """ OpenAPI Petstore @@ -10,12 +9,15 @@ """ -import unittest +import dataclasses from decimal import Decimal +import typing +import unittest import frozendict import petstore_api +from petstore_api import schemas from petstore_api.schemas import ( AnyTypeSchema, DictSchema, @@ -37,13 +39,13 @@ class TestAnyTypeSchema(unittest.TestCase): def testDictSchema(self): class Model(AnyTypeSchema): + @dataclasses.dataclass(frozen=True) class Schema_: - class AllOf: - classes = [ - AnyTypeSchema, - DictSchema, - ] + all_of: typing.Tuple[typing.Type[schemas.Schema], ...] = ( + AnyTypeSchema, + DictSchema, + ) m = Model(a=1, b='hi') assert isinstance(m, Model) @@ -54,13 +56,13 @@ class AllOf: def testListSchema(self): class Model(AnyTypeSchema): + @dataclasses.dataclass(frozen=True) class Schema_: - class AllOf: - classes = [ - AnyTypeSchema, - ListSchema, - ] + all_of: typing.Tuple[typing.Type[schemas.Schema], ...] = ( + AnyTypeSchema, + ListSchema, + ) m = Model([1, 'hi']) assert isinstance(m, Model) @@ -71,13 +73,13 @@ class AllOf: def testStrSchema(self): class Model(AnyTypeSchema): + @dataclasses.dataclass(frozen=True) class Schema_: - class AllOf: - classes = [ - AnyTypeSchema, - StrSchema, - ] + all_of: typing.Tuple[typing.Type[schemas.Schema], ...] = ( + AnyTypeSchema, + StrSchema, + ) m = Model('hi') assert isinstance(m, Model) @@ -88,13 +90,13 @@ class AllOf: def testNumberSchema(self): class Model(AnyTypeSchema): + @dataclasses.dataclass(frozen=True) class Schema_: - class AllOf: - classes = [ - AnyTypeSchema, - NumberSchema, - ] + all_of: typing.Tuple[typing.Type[schemas.Schema], ...] = ( + AnyTypeSchema, + NumberSchema, + ) m = Model(1) assert isinstance(m, Model) @@ -112,13 +114,13 @@ class AllOf: def testIntSchema(self): class Model(AnyTypeSchema): + @dataclasses.dataclass(frozen=True) class Schema_: - class AllOf: - classes = [ - AnyTypeSchema, - IntSchema, - ] + all_of: typing.Tuple[typing.Type[schemas.Schema], ...] = ( + AnyTypeSchema, + IntSchema, + ) m = Model(1) assert isinstance(m, Model) @@ -127,19 +129,19 @@ class AllOf: assert isinstance(m, Decimal) assert m == Decimal(1) - with self.assertRaises(petstore_api.exceptions.ApiValueError): + with self.assertRaises(petstore_api.ApiValueError): # can't pass in float into Int Model(3.14) def testBoolSchema(self): class Model(AnyTypeSchema): + @dataclasses.dataclass(frozen=True) class Schema_: - class AllOf: - classes = [ - AnyTypeSchema, - BoolSchema, - ] + all_of: typing.Tuple[typing.Type[schemas.Schema], ...] = ( + AnyTypeSchema, + BoolSchema, + ) m = Model(True) assert isinstance(m, Model) @@ -157,13 +159,13 @@ class AllOf: def testNoneSchema(self): class Model(AnyTypeSchema): + @dataclasses.dataclass(frozen=True) class Schema_: - class AllOf: - classes = [ - AnyTypeSchema, - NoneSchema, - ] + all_of: typing.Tuple[typing.Type[schemas.Schema], ...] = ( + AnyTypeSchema, + NoneSchema, + ) m = Model(None) self.assertTrue(m.is_none_()) @@ -174,13 +176,13 @@ class AllOf: def testDateSchema(self): class Model(AnyTypeSchema): + @dataclasses.dataclass(frozen=True) class Schema_: - class AllOf: - classes = [ - AnyTypeSchema, - DateSchema, - ] + all_of: typing.Tuple[typing.Type[schemas.Schema], ...] = ( + AnyTypeSchema, + DateSchema, + ) m = Model('1970-01-01') assert isinstance(m, Model) @@ -191,13 +193,13 @@ class AllOf: def testDateTimeSchema(self): class Model(AnyTypeSchema): + @dataclasses.dataclass(frozen=True) class Schema_: - class AllOf: - classes = [ - AnyTypeSchema, - DateTimeSchema, - ] + all_of: typing.Tuple[typing.Type[schemas.Schema], ...] = ( + AnyTypeSchema, + DateTimeSchema, + ) m = Model('2020-01-01T00:00:00') assert isinstance(m, Model) @@ -208,13 +210,13 @@ class AllOf: def testDecimalSchema(self): class Model(AnyTypeSchema): + @dataclasses.dataclass(frozen=True) class Schema_: - class AllOf: - classes = [ - AnyTypeSchema, - DecimalSchema, - ] + all_of: typing.Tuple[typing.Type[schemas.Schema], ...] = ( + AnyTypeSchema, + DecimalSchema, + ) m = Model('12.34') assert m == '12.34' diff --git a/samples/openapi3/client/petstore/python/tests_manual/test_configuration.py b/samples/openapi3/client/petstore/python/tests_manual/test_configuration.py index 338d2fd8d60..ae8c6b34bc6 100644 --- a/samples/openapi3/client/petstore/python/tests_manual/test_configuration.py +++ b/samples/openapi3/client/petstore/python/tests_manual/test_configuration.py @@ -32,7 +32,9 @@ def test_spec_root_servers(self): api_key=api_configuration.security_scheme_api_key.ApiKey(api_key='abcdefg') ) server_info: api_configuration.ServerInfo = { - 'servers/1': api_configuration.server_1.Server1(variables={'version': 'v2'}) + 'servers/1': api_configuration.server_1.Server1( + variables=api_configuration.server_1.Variables(version='v2') + ) } server_index_info: api_configuration.ServerIndexInfo = { 'servers': 1 @@ -81,7 +83,7 @@ def test_path_servers(self): ) server_info: api_configuration.ServerInfo = { "paths//pet/findByStatus/servers/1": api_configuration.pet_find_by_status_server_1.Server1( - variables={'version': 'v2'} + variables=api_configuration.pet_find_by_status_server_1.Variables(version='v2') ) } configuration = api_configuration.ApiConfiguration(security_scheme_info=security_scheme_info, server_info=server_info) @@ -120,7 +122,7 @@ def test_path_servers(self): def test_operation_servers(self): server_info: api_configuration.ServerInfo = { "paths//foo/get/servers/1": api_configuration.foo_get_server_1.Server1( - variables={'version': 'v2'} + variables=api_configuration.foo_get_server_1.Variables(version='v2') ) } config = api_configuration.ApiConfiguration(server_info=server_info) diff --git a/samples/openapi3/client/petstore/python/tests_manual/test_mammal.py b/samples/openapi3/client/petstore/python/tests_manual/test_mammal.py index 63fca5e4d50..334b890c63a 100644 --- a/samples/openapi3/client/petstore/python/tests_manual/test_mammal.py +++ b/samples/openapi3/client/petstore/python/tests_manual/test_mammal.py @@ -43,7 +43,7 @@ def testMammal(self): assert isinstance(m, whale.Whale) # can use the enum value - m = Mammal(className=whale.Whale.Schema_.Properties.ClassName.WHALE) + m = Mammal(className=whale.ClassName.WHALE) assert isinstance(m, whale.Whale) from petstore_api.components.schema import zebra diff --git a/samples/openapi3/client/petstore/python/tests_manual/test_obj_with_required_props.py b/samples/openapi3/client/petstore/python/tests_manual/test_obj_with_required_props.py index f9639468b10..53b735f16ff 100644 --- a/samples/openapi3/client/petstore/python/tests_manual/test_obj_with_required_props.py +++ b/samples/openapi3/client/petstore/python/tests_manual/test_obj_with_required_props.py @@ -13,22 +13,22 @@ import typing_extensions -from petstore_api.components.schema.obj_with_required_props import ObjWithRequiredProps -from petstore_api.components.schema.obj_with_required_props_base import ObjWithRequiredPropsBase +from petstore_api.components.schema import obj_with_required_props +from petstore_api.components.schema import obj_with_required_props_base from petstore_api.configurations import schema_configuration class TestObjWithRequiredProps(unittest.TestCase): """ObjWithRequiredProps unit test stubs""" configuration_ = schema_configuration.SchemaConfiguration() - obj = ObjWithRequiredProps(a='a', b='b') - assert isinstance(obj, ObjWithRequiredProps) and isinstance(obj, ObjWithRequiredPropsBase) + obj = obj_with_required_props.ObjWithRequiredProps(a='a', b='b') + assert isinstance(obj, obj_with_required_props.ObjWithRequiredProps) and isinstance(obj, obj_with_required_props_base.ObjWithRequiredPropsBase) a = obj.a - orgin_cls = typing_extensions.get_origin(ObjWithRequiredProps.Schema_.Properties.A) + orgin_cls = typing_extensions.get_origin(obj_with_required_props.A) assert orgin_cls is not None assert isinstance(a, orgin_cls) b = obj.b - orgin_cls = typing_extensions.get_origin(ObjWithRequiredPropsBase.Schema_.Properties.B) + orgin_cls = typing_extensions.get_origin(obj_with_required_props_base.B) assert orgin_cls is not None assert isinstance(a, orgin_cls) diff --git a/samples/openapi3/client/petstore/python/tests_manual/test_object_model_with_arg_and_args_properties.py b/samples/openapi3/client/petstore/python/tests_manual/test_object_model_with_arg_and_args_properties.py index 988c4c45013..d904ab633c6 100644 --- a/samples/openapi3/client/petstore/python/tests_manual/test_object_model_with_arg_and_args_properties.py +++ b/samples/openapi3/client/petstore/python/tests_manual/test_object_model_with_arg_and_args_properties.py @@ -14,7 +14,7 @@ import typing_extensions from petstore_api import schemas, exceptions -from petstore_api.components.schema.object_model_with_arg_and_args_properties import ObjectModelWithArgAndArgsProperties +from petstore_api.components.schema import object_model_with_arg_and_args_properties class TestObjectModelWithArgAndArgsProperties(unittest.TestCase): @@ -22,8 +22,9 @@ class TestObjectModelWithArgAndArgsProperties(unittest.TestCase): def test_ObjectModelWithArgAndArgsProperties(self): """Test ObjectModelWithArgAndArgsProperties""" - model = ObjectModelWithArgAndArgsProperties(arg='a', args='as') - origin_cls = typing_extensions.get_origin(ObjectModelWithArgAndArgsProperties.Schema_.Properties.Arg) + model = object_model_with_arg_and_args_properties.ObjectModelWithArgAndArgsProperties( + arg='a', args='as') + origin_cls = typing_extensions.get_origin(object_model_with_arg_and_args_properties.Arg) assert origin_cls is not None self.assertTrue( isinstance( @@ -31,7 +32,7 @@ def test_ObjectModelWithArgAndArgsProperties(self): origin_cls ) ) - origin_cls = typing_extensions.get_origin(ObjectModelWithArgAndArgsProperties.Schema_.Properties.Args) + origin_cls = typing_extensions.get_origin(object_model_with_arg_and_args_properties.Args) assert origin_cls is not None self.assertTrue( isinstance( diff --git a/samples/openapi3/client/petstore/python/tests_manual/test_object_model_with_ref_props.py b/samples/openapi3/client/petstore/python/tests_manual/test_object_model_with_ref_props.py index 0c2139fac3b..70aec76cce4 100644 --- a/samples/openapi3/client/petstore/python/tests_manual/test_object_model_with_ref_props.py +++ b/samples/openapi3/client/petstore/python/tests_manual/test_object_model_with_ref_props.py @@ -15,7 +15,7 @@ import typing_extensions from petstore_api.schemas import BoolClass -from petstore_api.components.schema.object_model_with_ref_props import ObjectModelWithRefProps +from petstore_api.components.schema import object_model_with_ref_props from petstore_api.components.schema.number_with_validations import NumberWithValidations @@ -30,18 +30,18 @@ def tearDown(self): def testObjectModelWithRefProps(self): """Test ObjectModelWithRefProps""" - inst = ObjectModelWithRefProps(myNumber=15.0, myString="a", myBoolean=True) - assert isinstance(inst, ObjectModelWithRefProps) + inst = object_model_with_ref_props.ObjectModelWithRefProps(myNumber=15.0, myString="a", myBoolean=True) + assert isinstance(inst, object_model_with_ref_props.ObjectModelWithRefProps) assert isinstance(inst, frozendict.frozendict) assert set(inst.keys()) == {"myNumber", "myString", "myBoolean"} assert inst["myNumber"] == 15.0 assert isinstance(inst["myNumber"], NumberWithValidations) assert inst["myString"] == 'a' - origin_cls = typing_extensions.get_origin(ObjectModelWithRefProps.Schema_.Properties.my_string()) + origin_cls = typing_extensions.get_origin(object_model_with_ref_props.string.String) assert origin_cls is not None assert isinstance(inst["myString"], origin_cls) assert bool(inst["myBoolean"]) is True - origin_cls = typing_extensions.get_origin(ObjectModelWithRefProps.Schema_.Properties.my_boolean()) + origin_cls = typing_extensions.get_origin(object_model_with_ref_props.boolean.Boolean) assert origin_cls is not None assert isinstance(inst["myBoolean"], origin_cls) assert isinstance(inst["myBoolean"], BoolClass) diff --git a/samples/openapi3/client/petstore/python/tests_manual/test_object_with_inline_composition_property.py b/samples/openapi3/client/petstore/python/tests_manual/test_object_with_inline_composition_property.py index dfafdf42f19..f33add17d91 100644 --- a/samples/openapi3/client/petstore/python/tests_manual/test_object_with_inline_composition_property.py +++ b/samples/openapi3/client/petstore/python/tests_manual/test_object_with_inline_composition_property.py @@ -12,7 +12,7 @@ import unittest from petstore_api import schemas, exceptions -from petstore_api.components.schema.object_with_inline_composition_property import ObjectWithInlineCompositionProperty +from petstore_api.components.schema import object_with_inline_composition_property class TestObjectWithInlineCompositionProperty(unittest.TestCase): @@ -20,18 +20,18 @@ class TestObjectWithInlineCompositionProperty(unittest.TestCase): def test_ObjectWithInlineCompositionProperty(self): """Test ObjectWithInlineCompositionProperty""" - model = ObjectWithInlineCompositionProperty(someProp='a') + model = object_with_inline_composition_property.ObjectWithInlineCompositionProperty(someProp='a') self.assertTrue( isinstance( model["someProp"], - ObjectWithInlineCompositionProperty.Schema_.Properties.SomeProp + object_with_inline_composition_property.SomeProp ) ) self.assertTrue(isinstance(model["someProp"], schemas.StrSchema)) # error thrown on length < 1 with self.assertRaises(exceptions.ApiValueError): - ObjectWithInlineCompositionProperty(someProp='') + object_with_inline_composition_property.ObjectWithInlineCompositionProperty(someProp='') if __name__ == '__main__': diff --git a/samples/openapi3/client/petstore/python/tests_manual/test_validate.py b/samples/openapi3/client/petstore/python/tests_manual/test_validate.py index 263752aa38b..a4893386098 100644 --- a/samples/openapi3/client/petstore/python/tests_manual/test_validate.py +++ b/samples/openapi3/client/petstore/python/tests_manual/test_validate.py @@ -6,22 +6,21 @@ import frozendict -from petstore_api.components.schema.string_with_validation import StringWithValidation -from petstore_api.components.schema.string_enum import StringEnum -from petstore_api.components.schema.number_with_validations import NumberWithValidations -from petstore_api.components.schema.array_holding_any_type import ArrayHoldingAnyType -from petstore_api.components.schema.array_with_validations_in_items import ( - ArrayWithValidationsInItems, -) +from petstore_api.components.schema import string_with_validation +from petstore_api.components.schema import string_enum +from petstore_api.components.schema import number_with_validations +from petstore_api.components.schema import array_holding_any_type +from petstore_api.components.schema import array_with_validations_in_items + from petstore_api.components.schema.foo import Foo from petstore_api.components.schema.bar import Bar -from petstore_api.components.schema.animal import Animal -from petstore_api.components.schema.dog import Dog +from petstore_api.components.schema import animal +from petstore_api.components.schema import dog from petstore_api.components.schema.boolean_enum import BooleanEnum from petstore_api.components.schema.pig import Pig -from petstore_api.components.schema.danish_pig import DanishPig +from petstore_api.components.schema import danish_pig from petstore_api.components.schema.gm_fruit import GmFruit -from petstore_api.components.schema.apple import Apple +from petstore_api.components.schema import apple from petstore_api.components.schema.banana import Banana from petstore_api import schemas from petstore_api.configurations import schema_configuration @@ -40,40 +39,40 @@ class TestValidateResults(unittest.TestCase): def test_str_validate(self): vm = ValidationMetadata(path_to_item=("args[0]",), configuration=schema_configuration.SchemaConfiguration()) - path_to_schemas = StringWithValidation._validate( + path_to_schemas = string_with_validation.StringWithValidation._validate( "abcdefg", validation_metadata=vm ) - assert path_to_schemas == {("args[0]",): {StringWithValidation, str}} + assert path_to_schemas == {("args[0]",): {string_with_validation.StringWithValidation, str}} def test_number_validate(self): vm = ValidationMetadata(path_to_item=("args[0]",), configuration=schema_configuration.SchemaConfiguration()) - path_to_schemas = NumberWithValidations._validate( + path_to_schemas = number_with_validations.NumberWithValidations._validate( Decimal(11), validation_metadata=vm ) - assert path_to_schemas == {("args[0]",): {NumberWithValidations, Decimal}} + assert path_to_schemas == {("args[0]",): {number_with_validations.NumberWithValidations, Decimal}} def test_str_enum_validate(self): vm = ValidationMetadata(path_to_item=("args[0]",), configuration=schema_configuration.SchemaConfiguration()) - path_to_schemas = StringEnum._validate("placed", validation_metadata=vm) - assert path_to_schemas == {("args[0]",): {str, StringEnum}} + path_to_schemas = string_enum.StringEnum._validate("placed", validation_metadata=vm) + assert path_to_schemas == {("args[0]",): {str, string_enum.StringEnum}} def test_nullable_enum_validate(self): vm = ValidationMetadata(path_to_item=("args[0]",), configuration=schema_configuration.SchemaConfiguration()) - path_to_schemas = StringEnum._validate(NoneClass.NONE, validation_metadata=vm) - assert path_to_schemas == {("args[0]",): {NoneClass, StringEnum}} + path_to_schemas = string_enum.StringEnum._validate(NoneClass.NONE, validation_metadata=vm) + assert path_to_schemas == {("args[0]",): {NoneClass, string_enum.StringEnum}} def test_empty_list_validate(self): vm = ValidationMetadata(path_to_item=("args[0]",), configuration=schema_configuration.SchemaConfiguration()) - path_to_schemas = ArrayHoldingAnyType._validate((), validation_metadata=vm) - assert path_to_schemas == {("args[0]",): {ArrayHoldingAnyType, tuple}} + path_to_schemas = array_holding_any_type.ArrayHoldingAnyType._validate((), validation_metadata=vm) + assert path_to_schemas == {("args[0]",): {array_holding_any_type.ArrayHoldingAnyType, tuple}} def test_list_validate(self): vm = ValidationMetadata(path_to_item=("args[0]",), configuration=schema_configuration.SchemaConfiguration()) - path_to_schemas = ArrayHoldingAnyType._validate( + path_to_schemas = array_holding_any_type.ArrayHoldingAnyType._validate( (Decimal(1), "a"), validation_metadata=vm ) assert path_to_schemas == { - ("args[0]",): {ArrayHoldingAnyType, tuple}, + ("args[0]",): {array_holding_any_type.ArrayHoldingAnyType, tuple}, ("args[0]", 0): {AnyTypeSchema, Decimal}, ("args[0]", 1): {AnyTypeSchema, str}, } @@ -96,15 +95,15 @@ def test_dict_validate(self): def test_discriminated_dict_validate(self): vm = ValidationMetadata(path_to_item=("args[0]",), configuration=schema_configuration.SchemaConfiguration()) - path_to_schemas = Animal._validate( + path_to_schemas = animal.Animal._validate( frozendict.frozendict(className="Dog", color="black"), validation_metadata=vm ) for schema_classes in path_to_schemas.values(): - Animal._process_schema_classes(schema_classes) + animal.Animal._process_schema_classes(schema_classes) assert path_to_schemas == { - ("args[0]",): {Animal, Dog, Dog.Schema_.AllOf.classes[1], frozendict.frozendict}, + ("args[0]",): {animal.Animal, dog.Dog, dog._1, frozendict.frozendict}, ("args[0]", "className"): {StrSchema, str}, - ("args[0]", "color"): {Animal.Schema_.Properties.Color, str}, + ("args[0]", "color"): {animal.Color, str}, } def test_bool_enum_validate(self): @@ -120,8 +119,8 @@ def test_oneof_composition_pig_validate(self): for schema_classes in path_to_schemas.values(): Pig._process_schema_classes(schema_classes) assert path_to_schemas == { - ("args[0]",): {Pig, DanishPig, frozendict.frozendict}, - ("args[0]", "className"): {DanishPig.Schema_.Properties.ClassName, str}, + ("args[0]",): {Pig, danish_pig.DanishPig, frozendict.frozendict}, + ("args[0]", "className"): {danish_pig.ClassName, str}, } def test_anyof_composition_gm_fruit_validate(self): @@ -133,25 +132,25 @@ def test_anyof_composition_gm_fruit_validate(self): for schema_classes in path_to_schemas.values(): GmFruit._process_schema_classes(schema_classes) assert path_to_schemas == { - ("args[0]",): {GmFruit, Apple, Banana, frozendict.frozendict}, - ("args[0]", "cultivar"): {Apple.Schema_.Properties.Cultivar, str}, + ("args[0]",): {GmFruit, apple.Apple, Banana, frozendict.frozendict}, + ("args[0]", "cultivar"): {apple.Cultivar, str}, ("args[0]", "lengthCm"): {NumberSchema, Decimal}, } class TestValidateCalls(unittest.TestCase): def test_empty_list_validate(self): - return_value = {("args[0]",): {ArrayHoldingAnyType, tuple}} + return_value = {("args[0]",): {array_holding_any_type.ArrayHoldingAnyType, tuple}} with patch.object( Schema, "_validate", return_value=return_value ) as mock_validate: - ArrayHoldingAnyType([]) + array_holding_any_type.ArrayHoldingAnyType([]) assert mock_validate.call_count == 1 with patch.object( Schema, "_validate", return_value=return_value ) as mock_validate: - ArrayHoldingAnyType.from_openapi_data_([]) + array_holding_any_type.ArrayHoldingAnyType.from_openapi_data_([]) assert mock_validate.call_count == 1 def test_empty_dict_validate(self): @@ -170,17 +169,17 @@ def test_empty_dict_validate(self): def test_list_validate_direct_instantiation(self): with patch.object( - ArrayWithValidationsInItems, + array_with_validations_in_items.ArrayWithValidationsInItems, "_validate", - side_effect=ArrayWithValidationsInItems._validate, + side_effect=array_with_validations_in_items.ArrayWithValidationsInItems._validate, ) as mock_outer_validate: with patch.object( - ArrayWithValidationsInItems.Schema_.Items, + array_with_validations_in_items.Items, "_validate", - side_effect=ArrayWithValidationsInItems.Schema_.Items._validate, + side_effect=array_with_validations_in_items.Items._validate, ) as mock_inner_validate: used_configuration = schema_configuration.SchemaConfiguration() - ArrayWithValidationsInItems([7], configuration_=used_configuration) + array_with_validations_in_items.ArrayWithValidationsInItems([7], configuration_=used_configuration) mock_outer_validate.assert_called_once_with( (Decimal("7"),), validation_metadata=ValidationMetadata(path_to_item=("args[0]",), configuration=used_configuration) @@ -192,42 +191,42 @@ def test_list_validate_direct_instantiation(self): def test_list_validate_direct_instantiation_cast_item(self): # item validation is skipped if items are of the correct type - item = ArrayWithValidationsInItems.Schema_.Items(7) + item = array_with_validations_in_items.Items(7) with patch.object( - ArrayWithValidationsInItems, + array_with_validations_in_items.ArrayWithValidationsInItems, "_validate", - side_effect=ArrayWithValidationsInItems._validate, + side_effect=array_with_validations_in_items.ArrayWithValidationsInItems._validate, ) as mock_outer_validate: with patch.object( - ArrayWithValidationsInItems.Schema_.Items, + array_with_validations_in_items.Items, "_validate", - side_effect=ArrayWithValidationsInItems.Schema_.Items._validate, + side_effect=array_with_validations_in_items.Items._validate, ) as mock_inner_validate: used_configuration = schema_configuration.SchemaConfiguration() - ArrayWithValidationsInItems([item], configuration_=used_configuration) + array_with_validations_in_items.ArrayWithValidationsInItems([item], configuration_=used_configuration) mock_outer_validate.assert_called_once_with( tuple([Decimal('7')]), validation_metadata=ValidationMetadata( path_to_item=("args[0]",), configuration=used_configuration, - validated_path_to_schemas={('args[0]', 0): {ArrayWithValidationsInItems.Schema_.Items, Decimal}} + validated_path_to_schemas={('args[0]', 0): {array_with_validations_in_items.Items, Decimal}} ) ) mock_inner_validate.assert_not_called def test_list_validate_from_openai_data_instantiation(self): with patch.object( - ArrayWithValidationsInItems, + array_with_validations_in_items.ArrayWithValidationsInItems, "_validate", - side_effect=ArrayWithValidationsInItems._validate, + side_effect=array_with_validations_in_items.ArrayWithValidationsInItems._validate, ) as mock_outer_validate: with patch.object( - ArrayWithValidationsInItems.Schema_.Items, + array_with_validations_in_items.Items, "_validate", - side_effect=ArrayWithValidationsInItems.Schema_.Items._validate, + side_effect=array_with_validations_in_items.Items._validate, ) as mock_inner_validate: used_configuration = schema_configuration.SchemaConfiguration() - ArrayWithValidationsInItems.from_openapi_data_([7], configuration_=used_configuration) + array_with_validations_in_items.ArrayWithValidationsInItems.from_openapi_data_([7], configuration_=used_configuration) mock_outer_validate.assert_called_once_with( (Decimal("7"),), validation_metadata=ValidationMetadata(path_to_item=("args[0]",), configuration=used_configuration)