Skip to content
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

Fix an issue with nested in schema #3189

Merged
merged 10 commits into from
May 2, 2024
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 @@
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

Check warning on line 359 in src/cfnlint/template/template.py

View check run for this annotation

Codecov / codecov/patch

src/cfnlint/template/template.py#L358-L359

Added lines #L358 - L359 were not covered by tests

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

item_type = item.get("type")
if item_type is None:
if "$ref" in item:
results.update(

Check warning on line 366 in src/cfnlint/template/template.py

View check run for this annotation

Codecov / codecov/patch

src/cfnlint/template/template.py#L366

Added line #L366 was not covered by tests
self._get_valid_getatts_from_schema(schema, item.get("$ref"))
)
else:
return results

Check warning on line 370 in src/cfnlint/template/template.py

View check run for this annotation

Codecov / codecov/patch

src/cfnlint/template/template.py#L370

Added line #L370 was not covered by tests
_type = None
primitive_type = None
if item_type == "string":
primitive_type = "String"
elif item_type == "number":
primitive_type = "Double"

Check warning on line 376 in src/cfnlint/template/template.py

View check run for this annotation

Codecov / codecov/patch

src/cfnlint/template/template.py#L376

Added line #L376 was not covered by tests
elif item_type == "integer":
primitive_type = "Integer"

Check warning on line 378 in src/cfnlint/template/template.py

View check run for this annotation

Codecov / codecov/patch

src/cfnlint/template/template.py#L378

Added line #L378 was not covered by tests
elif item_type == "boolean":
primitive_type = "Boolean"

Check warning on line 380 in src/cfnlint/template/template.py

View check run for this annotation

Codecov / codecov/patch

src/cfnlint/template/template.py#L380

Added line #L380 was not covered by tests
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 @@
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
Loading