Skip to content

fix: Names of classes without titles will no longer include ref path (fixes #397) #405

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion end_to_end_tests/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,6 @@
"type": "object"
},
"ModelWithAdditionalPropertiesInlined": {
"title": "ModelWithAdditionalPropertiesInlined",
"type": "object",
"properties": {
"a_number": {
Expand Down
10 changes: 5 additions & 5 deletions openapi_python_client/parser/properties/model_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,18 @@ def build_model_property(
parent_name: The name of the property that this property is inside of (affects class naming)
config: Config data for this run of the generator, used to modifying names
"""
class_name = data.title or name
class_string = data.title or name
if parent_name:
class_name = f"{utils.pascal_case(parent_name)}{utils.pascal_case(class_name)}"
class_info = Class.from_string(string=class_name, config=config)
class_string = f"{utils.pascal_case(parent_name)}{utils.pascal_case(class_string)}"
class_info = Class.from_string(string=class_string, config=config)

property_data = _process_properties(data=data, schemas=schemas, class_name=class_name, config=config)
property_data = _process_properties(data=data, schemas=schemas, class_name=class_info.name, config=config)
if isinstance(property_data, PropertyError):
return property_data, schemas
schemas = property_data.schemas

additional_properties, schemas = _get_additional_properties(
schema_additional=data.additionalProperties, schemas=schemas, class_name=class_name, config=config
schema_additional=data.additionalProperties, schemas=schemas, class_name=class_info.name, config=config
)
if isinstance(additional_properties, Property):
property_data.relative_imports.update(additional_properties.get_imports(prefix=".."))
Expand Down
4 changes: 2 additions & 2 deletions tests/test_parser/test_properties/test_model_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def test_bad_props_return_error(self):
assert err == PropertyError(detail="unknown type not_real", data=oai.Schema(type="not_real"))

def test_bad_additional_props_return_error(self):
from openapi_python_client.parser.properties import Schemas, build_model_property
from openapi_python_client.parser.properties import Config, Schemas, build_model_property

additional_properties = oai.Schema(
type="object",
Expand All @@ -190,7 +190,7 @@ def test_bad_additional_props_return_error(self):
schemas = Schemas()

err, new_schemas = build_model_property(
data=data, name="prop", schemas=schemas, required=True, parent_name=None, config=MagicMock()
data=data, name="prop", schemas=schemas, required=True, parent_name=None, config=Config()
)

assert new_schemas == schemas
Expand Down