Skip to content

Commit

Permalink
Fix an issue with nested in schema (#3189)
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong authored May 2, 2024
1 parent 1654c78 commit 2f45e3d
Showing 1 changed file with 44 additions and 33 deletions.
77 changes: 44 additions & 33 deletions src/cfnlint/template/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,46 @@ def get_valid_refs(self):
results[pseudoparam] = element
return results

def _get_valid_getatts_from_schema(self, schema, pointer):
results = {}
try:
item = resolve_pointer(schema, pointer)
except KeyError:
return results

pointer = pointer.replace("/properties/", "").replace("#/definitions/", "")

item_type = item.get("type")
if item_type is None:
if "$ref" in item:
results.update(
self._get_valid_getatts_from_schema(schema, item.get("$ref"))
)
else:
return results
_type = None
primitive_type = None
if item_type == "string":
primitive_type = "String"
elif item_type == "number":
primitive_type = "Double"
elif item_type == "integer":
primitive_type = "Integer"
elif item_type == "boolean":
primitive_type = "Boolean"
elif item_type == "array":
_type = "List"
primitive_type = "String"

results[".".join(pointer.split("/"))] = {}
if _type:
results[".".join(pointer.split("/"))]["Type"] = _type
results[".".join(pointer.split("/"))]["PrimitiveItemType"] = primitive_type
elif primitive_type:
results[".".join(pointer.split("/"))]["PrimitiveType"] = primitive_type

return results

# pylint: disable=too-many-locals
def get_valid_getatts(self):
resourcetypes = cfnlint.helpers.RESOURCE_SPECS["us-east-1"].get("ResourceTypes")
Expand Down Expand Up @@ -424,40 +464,11 @@ def build_output_string(resource_type, property_name):
if value["Type"] == schema["typeName"]:
results[name] = {}
for ro_property in schema.get("readOnlyProperties", []):
try:
item = resolve_pointer(schema, ro_property)
except KeyError:
continue
item_type = item["type"]
_type = None
primitive_type = None
if item_type == "string":
primitive_type = "String"
elif item_type == "number":
primitive_type = "Double"
elif item_type == "integer":
primitive_type = "Integer"
elif item_type == "boolean":
primitive_type = "Boolean"
elif item_type == "array":
_type = "List"
primitive_type = "String"

ro_property = ro_property.replace(
"/properties/", ""
results[name].update(
self._get_valid_getatts_from_schema(
schema, ro_property
)
)
results[name][".".join(ro_property.split("/"))] = {}
if _type:
results[name][".".join(ro_property.split("/"))][
"Type"
] = _type
results[name][".".join(ro_property.split("/"))][
"PrimitiveItemType"
] = primitive_type
elif primitive_type:
results[name][".".join(ro_property.split("/"))][
"PrimitiveType"
] = primitive_type

return results

Expand Down

0 comments on commit 2f45e3d

Please sign in to comment.