Skip to content

Commit

Permalink
schema properties validation recursion fix
Browse files Browse the repository at this point in the history
  • Loading branch information
p1c2u committed Feb 2, 2023
1 parent ee153b2 commit 4b4f3d6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
9 changes: 8 additions & 1 deletion openapi_spec_validator/validation/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def __init__(
self.resolver_handlers = resolver_handlers

self.operation_ids_registry: Optional[List[str]] = None
self.schema_ids_registry: Optional[List[str]] = None
self.resolver = None

def validate(
Expand All @@ -82,6 +83,7 @@ def iter_errors(
self, instance: Mapping[Hashable, Any], spec_url: str = ""
) -> Iterator[ValidationError]:
self.operation_ids_registry = []
self.schema_ids_registry = []
self.resolver = self._get_resolver(spec_url, instance)

yield from self.schema_validator.iter_errors(instance)
Expand Down Expand Up @@ -248,7 +250,12 @@ def _iter_schema_errors(
if not hasattr(schema.content(), "__getitem__"):
return

schema_type = schema.getkey("type")
assert self.schema_ids_registry is not None
schema_id = id(schema.content())
if schema_id in self.schema_ids_registry:
return
self.schema_ids_registry.append(schema_id)

nested_properties = []
if "allOf" in schema:
all_of = schema / "allOf"
Expand Down
16 changes: 16 additions & 0 deletions tests/integration/data/v3.0/property-recursive.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
openapi: 3.0.0
info:
version: '1.0.0'
title: 'Some Schema'
paths: {}
components:
schemas:
SomeDataType:
type: object
properties:
id:
type: integer
prop1:
$ref: '#/components/schemas/SomeDataType'
prop2:
type: string
1 change: 1 addition & 0 deletions tests/integration/validation/test_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def local_test_suite_file_path(self, test_file):
"petstore.yaml",
"petstore-separate/spec/openapi.yaml",
"parent-reference/openapi.yaml",
"property-recursive.yaml",
],
)
def test_valid(self, factory, validator_v30, spec_file):
Expand Down

0 comments on commit 4b4f3d6

Please sign in to comment.