Skip to content

Commit 2c157aa

Browse files
authored
feat: Improve error messages related to invalid arrays and circular or recursive references. (#519)
1 parent 8802e7e commit 2c157aa

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

openapi_python_client/parser/properties/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,8 @@ def build_list_property(
480480
name=f"{name}_item", required=True, data=data.items, schemas=schemas, parent_name=parent_name, config=config
481481
)
482482
if isinstance(inner_prop, PropertyError):
483-
return PropertyError(data=inner_prop.data, detail=f"invalid data in items of array {name}"), schemas
483+
inner_prop.header = f'invalid data in items of array named "{name}"'
484+
return inner_prop, schemas
484485
return (
485486
ListProperty(
486487
name=name,

openapi_python_client/parser/properties/schemas.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ def update_schemas_with_data(
9494
)
9595

9696
if isinstance(prop, PropertyError):
97+
prop.detail = f"{prop.header}: {prop.detail}"
98+
prop.header = f"Unable to parse schema {ref_path}"
99+
if isinstance(prop.data, oai.Reference) and prop.data.ref.endswith(ref_path): # pragma: nocover
100+
prop.detail += (
101+
"\n\nRecursive and circular references are not supported. "
102+
"See https://github.com/openapi-generators/openapi-python-client/issues/466"
103+
)
97104
return prop
98105

99106
schemas = attr.evolve(schemas, classes_by_reference={ref_path: prop, **schemas.classes_by_reference})

tests/test_parser/test_properties/test_init.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,9 @@ def test_build_list_property_invalid_items(self, mocker):
722722
name=name, required=required, data=data, schemas=schemas, parent_name="parent", config=config
723723
)
724724

725-
assert p == PropertyError(data="blah", detail=f"invalid data in items of array {name}")
725+
assert isinstance(p, PropertyError)
726+
assert p.data == "blah"
727+
assert p.header.startswith(f"invalid data in items of array {name}")
726728
assert new_schemas == second_schemas
727729
assert schemas != new_schemas, "Schema was mutated"
728730
property_from_data.assert_called_once_with(

0 commit comments

Comments
 (0)