Skip to content

Commit a9ab27a

Browse files
authored
catch common resource schema issues in cfn validate (#729)
expanding type_specific_keywords similar to #414
1 parent 8111630 commit a9ab27a

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

src/rpdk/core/data_loaders.py

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,6 @@ def load_resource_spec(resource_spec_file): # pylint: disable=R # noqa: C901
145145
LOG.debug("Resource spec validation failed", exc_info=True)
146146
raise SpecValidationError(str(e)) from e
147147

148-
min_max_keywords = {
149-
"minimum",
150-
"maximum",
151-
"minLength",
152-
"maxLength",
153-
"minProperties",
154-
"maxProperties",
155-
"minItems",
156-
"maxItems",
157-
"exclusiveMinimum",
158-
"exclusiveMaximum",
159-
}
160148
try: # pylint: disable=R
161149
for _key, schema in JsonSchemaFlattener(resource_spec).flatten_schema().items():
162150
for property_name, property_details in schema.get("properties", {}).items():
@@ -168,44 +156,57 @@ def load_resource_spec(resource_spec_file): # pylint: disable=R # noqa: C901
168156
try:
169157
property_type = property_details["type"]
170158
property_keywords = property_details.keys()
171-
for types, allowed_keywords in [
159+
keyword_mappings = [
172160
(
173161
{"integer", "number"},
174162
{
175163
"minimum",
176164
"maximum",
177165
"exclusiveMinimum",
178166
"exclusiveMaximum",
167+
"multipleOf",
179168
},
180169
),
181170
(
182171
{"string"},
183172
{
184173
"minLength",
185174
"maxLength",
175+
"pattern",
186176
},
187177
),
188178
(
189179
{"object"},
190180
{
191181
"minProperties",
192182
"maxProperties",
183+
"additionalProperties",
184+
"patternProperties",
193185
},
194186
),
195187
(
196188
{"array"},
197189
{
198190
"minItems",
199191
"maxItems",
192+
"additionalItems",
193+
"uniqueItems",
200194
},
201195
),
202-
]:
196+
]
197+
type_specific_keywords = set().union(
198+
*(mapping[1] for mapping in keyword_mappings)
199+
)
200+
for types, allowed_keywords in keyword_mappings:
203201
if (
204202
property_type in types
205-
and min_max_keywords - allowed_keywords & property_keywords
203+
and type_specific_keywords - allowed_keywords
204+
& property_keywords
206205
):
207206
LOG.warning(
208-
"Incorrect min/max JSON schema keywords for type: %s for property: %s",
207+
"Incorrect JSON schema keyword(s) %s for type: %s for property: %s",
208+
type_specific_keywords - allowed_keywords
209+
& property_keywords,
209210
property_type,
210211
property_name,
211212
)

0 commit comments

Comments
 (0)