11import pytest
22
33from openapi_parser import parse
4- from openapi_parser .specification import Specification
4+ from openapi_parser .enumeration import DataType
5+ from openapi_parser .specification import Array , Object , Specification
56from tests .openapi_fixture import create_specification
67
78
@@ -14,3 +15,46 @@ def test_run_parser(swagger_specification: Specification) -> None:
1415 actual_specification = parse ("tests/data/swagger.yml" )
1516
1617 assert actual_specification == swagger_specification
18+
19+
20+ def test_parse_recursive_schema () -> None :
21+ actual_specification = parse ("tests/data/recursive.yml" )
22+
23+ assert actual_specification .version == "3.0.0"
24+ assert actual_specification .info .title == "Recursive schema test"
25+ assert "Equipment" in actual_specification .schemas
26+ assert "Feature" in actual_specification .schemas
27+
28+
29+ def test_parse_recursive_schema_with_recursion_limit_2 () -> None :
30+ spec = parse ("tests/data/recursive.yml" , recursion_limit = 2 )
31+
32+ equipment = spec .schemas ["Equipment" ]
33+ assert isinstance (equipment , Object )
34+
35+ features = equipment .properties [0 ]
36+ assert features .name == "Features"
37+ assert isinstance (features .schema , Array )
38+
39+ feature_level_1 = features .schema .items
40+ assert isinstance (feature_level_1 , Object )
41+
42+ equipment_level_2 = feature_level_1 .properties [0 ].schema .items
43+ assert isinstance (equipment_level_2 , Object )
44+ assert equipment_level_2 .type == DataType .OBJECT
45+ assert len (equipment_level_2 .properties ) == 2
46+ assert equipment_level_2 .properties [0 ].name == "Features"
47+
48+ feature_level_3 = equipment_level_2 .properties [0 ].schema .items
49+ assert isinstance (feature_level_3 , Object )
50+ assert len (feature_level_3 .properties ) == 2
51+ assert feature_level_3 .properties [0 ].name == "Equipments"
52+
53+ equipment_level_4 = feature_level_3 .properties [0 ].schema .items
54+ assert isinstance (equipment_level_4 , Object )
55+ assert len (equipment_level_4 .properties ) == 2
56+ assert equipment_level_4 .properties [0 ].name == "Features"
57+
58+ placeholder = equipment_level_4 .properties [0 ].schema .items
59+ assert isinstance (placeholder , Object )
60+ assert len (placeholder .properties ) == 0
0 commit comments