Skip to content

feat: Improve error messages related to invalid arrays and circular or recursive references. #519

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 1 commit into from
Oct 17, 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
3 changes: 2 additions & 1 deletion openapi_python_client/parser/properties/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@ def build_list_property(
name=f"{name}_item", required=True, data=data.items, schemas=schemas, parent_name=parent_name, config=config
)
if isinstance(inner_prop, PropertyError):
return PropertyError(data=inner_prop.data, detail=f"invalid data in items of array {name}"), schemas
inner_prop.header = f'invalid data in items of array named "{name}"'
return inner_prop, schemas
return (
ListProperty(
name=name,
Expand Down
7 changes: 7 additions & 0 deletions openapi_python_client/parser/properties/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ def update_schemas_with_data(
)

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

schemas = attr.evolve(schemas, classes_by_reference={ref_path: prop, **schemas.classes_by_reference})
Expand Down
4 changes: 3 additions & 1 deletion tests/test_parser/test_properties/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,9 @@ def test_build_list_property_invalid_items(self, mocker):
name=name, required=required, data=data, schemas=schemas, parent_name="parent", config=config
)

assert p == PropertyError(data="blah", detail=f"invalid data in items of array {name}")
assert isinstance(p, PropertyError)
assert p.data == "blah"
assert p.header.startswith(f"invalid data in items of array {name}")
assert new_schemas == second_schemas
assert schemas != new_schemas, "Schema was mutated"
property_from_data.assert_called_once_with(
Expand Down