Skip to content

Commit f8f4891

Browse files
committed
Reference scopes stack fix
1 parent 662cd43 commit f8f4891

File tree

6 files changed

+85
-3
lines changed

6 files changed

+85
-3
lines changed

openapi_spec_validator/decorators.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ def __init__(self, instance_resolver):
1818
def __call__(self, func):
1919
def wrapped(validator, schema_element, instance, schema):
2020
if not isinstance(instance, dict) or '$ref' not in instance:
21-
return func(validator, schema_element, instance, schema)
21+
yield from func(validator, schema_element, instance, schema)
22+
return
2223

2324
ref = instance['$ref']
2425

@@ -29,7 +30,7 @@ def wrapped(validator, schema_element, instance, schema):
2930
self._attach_scope(instance)
3031
with self.visiting.visit(ref):
3132
with self.instance_resolver.resolving(ref) as target:
32-
return func(validator, schema_element, target, schema)
33+
yield from func(validator, schema_element, target, schema)
3334

3435
return wrapped
3536

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
schemas:
2+
Model:
3+
type: object
4+
required:
5+
- id
6+
properties:
7+
id:
8+
type: integer
9+
format: int32
10+
Error:
11+
type: object
12+
required:
13+
- code
14+
- message
15+
properties:
16+
code:
17+
type: integer
18+
format: int32
19+
message:
20+
type: string
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
openapi: "3.0.0"
2+
info:
3+
version: 1.0.0
4+
title: OpenAPI Petstore
5+
license:
6+
name: MIT
7+
servers:
8+
- url: http://petstore.swagger.io/v1
9+
paths:
10+
/pets:
11+
get:
12+
summary: List all pets
13+
operationId: listPets
14+
tags:
15+
- pets
16+
parameters:
17+
- name: limit
18+
in: query
19+
description: How many items to return at one time (max 100)
20+
required: false
21+
schema:
22+
type: integer
23+
format: int32
24+
responses:
25+
'200':
26+
description: Expected response to a valid request
27+
content:
28+
application/json:
29+
schema:
30+
$ref: "spec/components.yaml#/schemas/Pet"
31+
default:
32+
description: unexpected error
33+
content:
34+
application/json:
35+
schema:
36+
$ref: "common.yaml#/schemas/Error"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
schemas:
2+
Pet:
3+
type: object
4+
allOf:
5+
- $ref: "../common.yaml#/schemas/Model"
6+
required:
7+
- name
8+
properties:
9+
name:
10+
type: string
11+
tag:
12+
type: string
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
type: array
22
items:
3-
$ref: "schemas/Pet.yaml"
3+
$ref: "Pet.yaml"

tests/integration/test_validate.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,19 @@ def spec(self, factory):
5151
return factory.spec_from_file(self.spec_file)
5252

5353

54+
class TestLocalParentReferenceExample(BaseTestValidOpeAPIv3Validator):
55+
56+
spec_file = "data/v3.0/parent-reference/openapi.yaml"
57+
58+
@pytest.fixture
59+
def spec_url(self, factory):
60+
return factory.spec_url(self.spec_file)
61+
62+
@pytest.fixture
63+
def spec(self, factory):
64+
return factory.spec_from_file(self.spec_file)
65+
66+
5467
class TestPetstoreExample(BaseTestValidOpeAPIv3Validator):
5568

5669
@pytest.fixture

0 commit comments

Comments
 (0)