From e1fba55192906f0c5e4abede7ee93dab41bf0fff Mon Sep 17 00:00:00 2001 From: Jaap Versteegh Date: Tue, 19 Jan 2021 22:12:48 +0100 Subject: [PATCH] Replace "class_name" schema dictionary entry with "name". Entry into schema dictionary should contain the received attribute name, not the class_name, since class_name can be modified by the model's "title" attribute, which will break reference resolution to this model. --- openapi_python_client/parser/properties/__init__.py | 4 ++-- tests/test_parser/test_properties/test_init.py | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/openapi_python_client/parser/properties/__init__.py b/openapi_python_client/parser/properties/__init__.py index 427276692..856be3b55 100644 --- a/openapi_python_client/parser/properties/__init__.py +++ b/openapi_python_client/parser/properties/__init__.py @@ -302,7 +302,7 @@ def build_model_property( name=name, additional_properties=additional_properties, ) - schemas = attr.evolve(schemas, models={**schemas.models, prop.reference.class_name: prop}) + schemas = attr.evolve(schemas, models={**schemas.models, prop.name: prop}) return prop, schemas @@ -374,7 +374,7 @@ def build_enum_property( values=values, value_type=value_type, ) - schemas = attr.evolve(schemas, enums={**schemas.enums, prop.reference.class_name: prop}) + schemas = attr.evolve(schemas, enums={**schemas.enums, prop.name: prop}) return prop, schemas diff --git a/tests/test_parser/test_properties/test_init.py b/tests/test_parser/test_properties/test_init.py index a7ea05881..4d6871978 100644 --- a/tests/test_parser/test_properties/test_init.py +++ b/tests/test_parser/test_properties/test_init.py @@ -510,7 +510,7 @@ def test_property_from_data_str_enum(self, mocker): assert schemas != new_schemas, "Provided Schemas was mutated" assert new_schemas.enums == { "AnEnum": schemas.enums["AnEnum"], - "ParentAnEnum": prop, + "my_enum": prop, } def test_property_from_data_int_enum(self, mocker): @@ -541,7 +541,7 @@ def test_property_from_data_int_enum(self, mocker): assert schemas != new_schemas, "Provided Schemas was mutated" assert new_schemas.enums == { "AnEnum": schemas.enums["AnEnum"], - "ParentAnEnum": prop, + "my_enum": prop, } def test_property_from_data_ref_enum(self): @@ -1083,7 +1083,7 @@ def test_build_model_property(additional_properties_schema, expected_additional_ assert new_schemas != schemas assert new_schemas.models == { "OtherModel": None, - "ParentMyModel": model, + "prop": model, } assert model == ModelProperty( name="prop",