5
5
import pytest
6
6
7
7
8
+ def test__collision_resolver_get_schema_from_ref ():
9
+
10
+ from openapi_python_client .resolver .collision_resolver import CollisionResolver
11
+
12
+ root_schema = {"foo" : {"$ref" : "first_instance.yaml#/foo" }}
13
+
14
+ external_schemas = {"/home/user/first_instance.yaml" : {"food" : {"description" : "food_first_description" }}}
15
+
16
+ errors = []
17
+
18
+ CollisionResolver (root_schema , external_schemas , errors , "/home/user" ).resolve ()
19
+
20
+ assert len (errors ) == 1
21
+ assert errors == ["Did not find data corresponding to the reference first_instance.yaml#/foo" ]
22
+
23
+
24
+ def test__collision_resolver_duplicate_schema ():
25
+
26
+ from openapi_python_client .resolver .collision_resolver import CollisionResolver
27
+
28
+ root_schema = {
29
+ "foo" : {"$ref" : "first_instance.yaml#/foo" },
30
+ "bar" : {"$ref" : "second_instance.yaml#/bar/foo" },
31
+ }
32
+
33
+ external_schemas = {
34
+ "/home/user/first_instance.yaml" : {"foo" : {"description" : "foo_first_description" }},
35
+ "/home/user/second_instance.yaml" : {"bar" : {"foo" : {"description" : "foo_first_description" }}},
36
+ }
37
+
38
+ errors = []
39
+
40
+ CollisionResolver (root_schema , external_schemas , errors , "/home/user" ).resolve ()
41
+
42
+ assert len (errors ) == 1
43
+ assert errors == ["Found a duplicate schema in first_instance.yaml#/foo and second_instance.yaml#/bar/foo" ]
44
+
45
+
8
46
def test__collision_resolver ():
9
47
10
48
from openapi_python_client .resolver .collision_resolver import CollisionResolver
@@ -17,6 +55,7 @@ def test__collision_resolver():
17
55
"barfoobar" : {"$ref" : "first_instance.yaml#/bar/foo" },
18
56
"localref" : {"$ref" : "#/local_ref" },
19
57
"local_ref" : {"description" : "a local ref" },
58
+ "array" : ["array_item_one" , "array_item_two" ],
20
59
"last" : {"$ref" : "first_instance.yaml#/fourth_instance" },
21
60
"baz" : {"$ref" : "fifth_instance.yaml#/foo" },
22
61
}
@@ -27,7 +66,10 @@ def test__collision_resolver():
27
66
"bar" : {"foo" : {"description" : "nested foo" }},
28
67
"fourth_instance" : {"$ref" : "fourth_instance.yaml#/foo" },
29
68
},
30
- "/home/user/second_instance.yaml" : {"foo" : {"description" : "foo_second_description" }},
69
+ "/home/user/second_instance.yaml" : {
70
+ "foo" : {"description" : "foo_second_description" },
71
+ "another_local_ref" : {"$ref" : "#/foo" },
72
+ },
31
73
"/home/user/third_instance.yaml" : {"foo" : {"description" : "foo_third_description" }},
32
74
"/home/user/fourth_instance.yaml" : {"foo" : {"description" : "foo_fourth_description" }},
33
75
"/home/user/fifth_instance.yaml" : {"foo" : {"description" : "foo_second_description" }},
@@ -41,6 +83,7 @@ def test__collision_resolver():
41
83
"barfoobar" : {"$ref" : "first_instance.yaml#/bar/foo" },
42
84
"localref" : {"$ref" : "#/local_ref" },
43
85
"local_ref" : {"description" : "a local ref" },
86
+ "array" : ["array_item_one" , "array_item_two" ],
44
87
"last" : {"$ref" : "first_instance.yaml#/fourth_instance" },
45
88
"baz" : {"$ref" : "fifth_instance.yaml#/foo_2" },
46
89
}
@@ -51,7 +94,10 @@ def test__collision_resolver():
51
94
"bar" : {"foo" : {"description" : "nested foo" }},
52
95
"fourth_instance" : {"$ref" : "fourth_instance.yaml#/foo_4" },
53
96
},
54
- "/home/user/second_instance.yaml" : {"foo_2" : {"description" : "foo_second_description" }},
97
+ "/home/user/second_instance.yaml" : {
98
+ "foo_2" : {"description" : "foo_second_description" },
99
+ "another_local_ref" : {"$ref" : "#/foo_2" },
100
+ },
55
101
"/home/user/third_instance.yaml" : {"foo_3" : {"description" : "foo_third_description" }},
56
102
"/home/user/fourth_instance.yaml" : {"foo_4" : {"description" : "foo_fourth_description" }},
57
103
"/home/user/fifth_instance.yaml" : {"foo_2" : {"description" : "foo_second_description" }},
@@ -64,3 +110,54 @@ def test__collision_resolver():
64
110
assert len (errors ) == 0
65
111
assert root_schema == root_schema_result
66
112
assert external_schemas == external_schemas_result
113
+
114
+
115
+ def test__collision_resolver_deep_root_keys ():
116
+
117
+ from openapi_python_client .resolver .collision_resolver import CollisionResolver
118
+
119
+ root_schema = {
120
+ "foobar" : {"$ref" : "first_instance.yaml#/bar/foo" },
121
+ "barfoo" : {"$ref" : "second_instance.yaml#/bar/foo" },
122
+ "barfoobar" : {"$ref" : "second_instance.yaml#/barfoobar" },
123
+ }
124
+
125
+ external_schemas = {
126
+ "/home/user/first_instance.yaml" : {
127
+ "bar" : {"foo" : {"description" : "foo_first_description" }},
128
+ },
129
+ "/home/user/second_instance.yaml" : {
130
+ "bar" : {"foo" : {"description" : "foo_second_description" }},
131
+ "barfoobar" : {
132
+ "type" : "object" ,
133
+ "allOf" : [{"description" : "first_description" }, {"description" : "second_description" }],
134
+ },
135
+ },
136
+ }
137
+
138
+ root_schema_result = {
139
+ "foobar" : {"$ref" : "first_instance.yaml#/bar/foo" },
140
+ "barfoo" : {"$ref" : "second_instance.yaml#/bar/foo_2" },
141
+ "barfoobar" : {"$ref" : "second_instance.yaml#/barfoobar" },
142
+ }
143
+
144
+ external_schemas_result = {
145
+ "/home/user/first_instance.yaml" : {
146
+ "bar" : {"foo" : {"description" : "foo_first_description" }},
147
+ },
148
+ "/home/user/second_instance.yaml" : {
149
+ "bar" : {"foo_2" : {"description" : "foo_second_description" }},
150
+ "barfoobar" : {
151
+ "type" : "object" ,
152
+ "allOf" : [{"description" : "first_description" }, {"description" : "second_description" }],
153
+ },
154
+ },
155
+ }
156
+
157
+ errors = []
158
+
159
+ CollisionResolver (root_schema , external_schemas , errors , "/home/user" ).resolve ()
160
+
161
+ assert len (errors ) == 0
162
+ assert root_schema == root_schema_result
163
+ assert external_schemas == external_schemas_result
0 commit comments