55import pytest
66
77
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+
846def test__collision_resolver ():
947
1048 from openapi_python_client .resolver .collision_resolver import CollisionResolver
@@ -17,6 +55,7 @@ def test__collision_resolver():
1755 "barfoobar" : {"$ref" : "first_instance.yaml#/bar/foo" },
1856 "localref" : {"$ref" : "#/local_ref" },
1957 "local_ref" : {"description" : "a local ref" },
58+ "array" : ["array_item_one" , "array_item_two" ],
2059 "last" : {"$ref" : "first_instance.yaml#/fourth_instance" },
2160 "baz" : {"$ref" : "fifth_instance.yaml#/foo" },
2261 }
@@ -27,7 +66,10 @@ def test__collision_resolver():
2766 "bar" : {"foo" : {"description" : "nested foo" }},
2867 "fourth_instance" : {"$ref" : "fourth_instance.yaml#/foo" },
2968 },
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+ },
3173 "/home/user/third_instance.yaml" : {"foo" : {"description" : "foo_third_description" }},
3274 "/home/user/fourth_instance.yaml" : {"foo" : {"description" : "foo_fourth_description" }},
3375 "/home/user/fifth_instance.yaml" : {"foo" : {"description" : "foo_second_description" }},
@@ -41,6 +83,7 @@ def test__collision_resolver():
4183 "barfoobar" : {"$ref" : "first_instance.yaml#/bar/foo" },
4284 "localref" : {"$ref" : "#/local_ref" },
4385 "local_ref" : {"description" : "a local ref" },
86+ "array" : ["array_item_one" , "array_item_two" ],
4487 "last" : {"$ref" : "first_instance.yaml#/fourth_instance" },
4588 "baz" : {"$ref" : "fifth_instance.yaml#/foo_2" },
4689 }
@@ -51,7 +94,10 @@ def test__collision_resolver():
5194 "bar" : {"foo" : {"description" : "nested foo" }},
5295 "fourth_instance" : {"$ref" : "fourth_instance.yaml#/foo_4" },
5396 },
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+ },
55101 "/home/user/third_instance.yaml" : {"foo_3" : {"description" : "foo_third_description" }},
56102 "/home/user/fourth_instance.yaml" : {"foo_4" : {"description" : "foo_fourth_description" }},
57103 "/home/user/fifth_instance.yaml" : {"foo_2" : {"description" : "foo_second_description" }},
@@ -64,3 +110,54 @@ def test__collision_resolver():
64110 assert len (errors ) == 0
65111 assert root_schema == root_schema_result
66112 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