Skip to content

Commit b853de4

Browse files
author
evahala
committed
Recurse references in validation
JSON schema references can be nested complex schemas. Recurse in dereferencing logic until the returned item is no longer a reference. Also: Added a recursion to test data and fixed a typo in test_shortcuts.py.
1 parent 2adca8a commit b853de4

File tree

5 files changed

+15
-1
lines changed

5 files changed

+15
-1
lines changed

openapi_spec_validator/validators.py

+2
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ def dereference(self, item):
3434
ref = item['$ref']
3535
with self.resolver_manager.in_scope(item) as resolver:
3636
with resolver.resolving(ref) as target:
37+
if is_ref(target):
38+
target = self.dereference(target)
3739
return target
3840

3941

tests/integration/data/v3.0/parent-reference/openapi.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ paths:
1414
tags:
1515
- pets
1616
parameters:
17+
- $ref: "recursive.yaml#/parameters/RecursiveReference"
1718
- name: limit
1819
in: query
1920
description: How many items to return at one time (max 100)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
parameters:
2+
RecursiveReference:
3+
$ref : "recursive2.yaml#/parameters/RecursiveReference"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
parameters:
2+
RecursiveReference:
3+
name: sampleParameter
4+
in: query
5+
description: Tests recursion
6+
required: false
7+
schema:
8+
type: boolean

tests/integration/test_shortcuts.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def spec_url(self):
156156
)
157157

158158

159-
class TestApiWithExampe(BaseTestValidValidateV3SpecUrl):
159+
class TestApiWithExample(BaseTestValidValidateV3SpecUrl):
160160

161161
@pytest.fixture
162162
def spec_url(self):

0 commit comments

Comments
 (0)