-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
catch common resource schema issues in cfn validate #729
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -145,18 +145,6 @@ def load_resource_spec(resource_spec_file): # pylint: disable=R # noqa: C901 | |
LOG.debug("Resource spec validation failed", exc_info=True) | ||
raise SpecValidationError(str(e)) from e | ||
|
||
min_max_keywords = { | ||
"minimum", | ||
"maximum", | ||
"minLength", | ||
"maxLength", | ||
"minProperties", | ||
"maxProperties", | ||
"minItems", | ||
"maxItems", | ||
"exclusiveMinimum", | ||
"exclusiveMaximum", | ||
} | ||
try: # pylint: disable=R | ||
for _key, schema in JsonSchemaFlattener(resource_spec).flatten_schema().items(): | ||
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 | |
try: | ||
property_type = property_details["type"] | ||
property_keywords = property_details.keys() | ||
for types, allowed_keywords in [ | ||
keyword_mappings = [ | ||
( | ||
{"integer", "number"}, | ||
{ | ||
"minimum", | ||
"maximum", | ||
"exclusiveMinimum", | ||
"exclusiveMaximum", | ||
"multipleOf", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cant leave the comment above but could u take this structure out and create a static There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I support this idea too. Also can you create There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Started with dictionary, but Switched |
||
}, | ||
), | ||
( | ||
{"string"}, | ||
{ | ||
"minLength", | ||
"maxLength", | ||
"pattern", | ||
}, | ||
), | ||
( | ||
{"object"}, | ||
{ | ||
"minProperties", | ||
"maxProperties", | ||
"additionalProperties", | ||
"patternProperties", | ||
}, | ||
), | ||
( | ||
{"array"}, | ||
{ | ||
"minItems", | ||
"maxItems", | ||
"additionalItems", | ||
"uniqueItems", | ||
}, | ||
), | ||
]: | ||
] | ||
type_specific_keywords = set().union( | ||
*(mapping[1] for mapping in keyword_mappings) | ||
) | ||
for types, allowed_keywords in keyword_mappings: | ||
if ( | ||
property_type in types | ||
and min_max_keywords - allowed_keywords & property_keywords | ||
and type_specific_keywords - allowed_keywords | ||
& property_keywords | ||
ammokhov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
): | ||
LOG.warning( | ||
"Incorrect min/max JSON schema keywords for type: %s for property: %s", | ||
"Incorrect JSON schema keyword(s) %s for type: %s for property: %s", | ||
type_specific_keywords - allowed_keywords | ||
& property_keywords, | ||
Comment on lines
+208
to
+209
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you put this in a variable and use it above and here? |
||
property_type, | ||
property_name, | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if u are not using
_key
could u change it to_
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to clarify - you are using flattened schema to avoid recursive traversal, since all the subschemas are on the same level?