in glean_parser/metrics.py [0:0]
def _validate_substructure(structure):
extra = set(structure.keys()) - Object.ALLOWED_TOPLEVEL
if extra:
extra = ", ".join(extra)
allowed = ", ".join(Object.ALLOWED_TOPLEVEL)
raise ValueError(
f"Found additional fields: {extra}. Only allowed: {allowed}"
)
if "type" not in structure:
raise ValueError(
f"missing `type` in object structure. Allowed: {Object.ALLOWED_TYPES}"
)
if structure["type"] not in Object.ALLOWED_TYPES:
raise ValueError(
"invalid `type` in object structure. found: {}, allowed: {}".format(
structure["type"], Object.ALLOWED_TYPES
)
)
if structure["type"] == "object":
if "items" in structure:
raise ValueError("`items` not allowed in object structure")
if "properties" not in structure:
raise ValueError("`properties` missing for type `object`")
for key in structure["properties"]:
value = structure["properties"][key]
structure["properties"][key] = Object._validate_substructure(value)
if structure["type"] == "array":
if "properties" in structure:
raise ValueError("`properties` not allowed in array structure")
if "items" not in structure:
raise ValueError("`items` missing for type `array`")
value = structure["items"]
structure["items"] = Object._validate_substructure(value)
return structure