Skip to content

Commit 828f9e9

Browse files
authored
Fix traversal (#64)
1 parent 58bb37c commit 828f9e9

File tree

3 files changed

+63
-12
lines changed

3 files changed

+63
-12
lines changed

src/rpdk/guard_rail/utils/schema_utils.py

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ def __traverse(
9797
else:
9898
# if combiners are specified then we need to squash variants
9999
# and iterate over each sub schema
100+
101+
if _PROPERTIES in definition_replica:
102+
nested_properties = definition_replica[_PROPERTIES]
103+
while nested_properties:
104+
_prop_name, _prop_definition = nested_properties.popitem()
105+
__traverse(
106+
_prop_name,
107+
_prop_definition,
108+
cur_path + (_prop_name,),
109+
all_paths,
110+
)
111+
100112
if _ALL_OF in definition_replica:
101113
for sub_schema in definition_replica[_ALL_OF]:
102114
__traverse(prop_name, sub_schema, cur_path, all_paths)
@@ -107,18 +119,7 @@ def __traverse(
107119
for sub_schema in definition_replica[_ONE_OF]:
108120
__traverse(prop_name, sub_schema, cur_path, all_paths)
109121
else:
110-
# if no combiners were found then we check if there are
111-
# nested properties
112-
if _PROPERTIES in prop_definition:
113-
nested_properties = definition_replica[_PROPERTIES]
114-
while nested_properties:
115-
_prop_name, _prop_definition = nested_properties.popitem()
116-
__traverse(
117-
_prop_name,
118-
_prop_definition,
119-
cur_path + (_prop_name,),
120-
all_paths,
121-
)
122+
pass
122123

123124
resolved_schema = resolve_schema(schema)
124125
properties_replica = deepcopy(resolved_schema.get(_PROPERTIES, {}))
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"definitions": {
3+
"LaunchTemplateSpecification": {
4+
"type": "object",
5+
"additionalProperties": false,
6+
"properties": {
7+
"LaunchTemplateName": {
8+
"type": "string",
9+
"description": "The name of the launch template. You must specify the LaunchTemplateName or the LaunchTemplateId, but not both."
10+
},
11+
"LaunchTemplateId": {
12+
"type": "string",
13+
"description": "The ID of the launch template. You must specify the LaunchTemplateName or the LaunchTemplateId, but not both."
14+
},
15+
"Version": {
16+
"type": "string",
17+
"description": "The version number of the launch template."
18+
}
19+
},
20+
"oneOf": [
21+
{
22+
"required": [
23+
"LaunchTemplateName",
24+
"Version"
25+
]
26+
},
27+
{
28+
"required": [
29+
"LaunchTemplateId",
30+
"Version"
31+
]
32+
}
33+
]
34+
}
35+
},
36+
"properties": {
37+
"LaunchTemplate": {
38+
"$ref": "#/definitions/LaunchTemplateSpecification"
39+
}
40+
}
41+
}

tests/unit/utils/test_schema_utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ def test_resolve_schema(schema, result):
9797
"/properties/Tuples/*/Field/*/NewType",
9898
},
9999
),
100+
(
101+
"data/schemas-for-testing/schema-launch-template.json",
102+
{
103+
"/properties/LaunchTemplate",
104+
"/properties/LaunchTemplate/LaunchTemplateName",
105+
"/properties/LaunchTemplate/LaunchTemplateId",
106+
"/properties/LaunchTemplate/Version",
107+
},
108+
),
100109
],
101110
)
102111
def test_add_paths_to_schema(schema, result):

0 commit comments

Comments
 (0)