Skip to content

Commit

Permalink
Prevent infinite loops in keyword building
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong committed Sep 5, 2024
1 parent 00501ed commit e8b38bf
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"op": "test",
"path": "/definitions/SingleAxisOptions/properties/YAxisOptions",
"value": {
"$ref": "#/definitions/YAxisOptions"
}
},
{
"op": "replace",
"path": "/definitions/SingleAxisOptions/properties/YAxisOptions",
"value": {
"properties": {
"YAxis": {
"$ref": "#/definitions/SingleYAxisOption"
}
}
}
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"op": "test",
"path": "/definitions/SingleAxisOptions/properties/YAxisOptions",
"value": {
"$ref": "#/definitions/YAxisOptions"
}
},
{
"op": "replace",
"path": "/definitions/SingleAxisOptions/properties/YAxisOptions",
"value": {
"properties": {
"YAxis": {
"$ref": "#/definitions/SingleYAxisOption"
}
}
}
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -9314,7 +9314,11 @@
"additionalProperties": false,
"properties": {
"YAxisOptions": {
"$ref": "#/definitions/YAxisOptions"
"properties": {
"YAxis": {
"$ref": "#/definitions/SingleYAxisOption"
}
}
}
},
"type": "object"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8932,7 +8932,11 @@
"additionalProperties": false,
"properties": {
"YAxisOptions": {
"$ref": "#/definitions/YAxisOptions"
"properties": {
"YAxis": {
"$ref": "#/definitions/SingleYAxisOption"
}
}
}
},
"type": "object"
Expand Down
32 changes: 16 additions & 16 deletions test/integration/test_schema_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,47 +112,47 @@ def validate_basic_schema_details(
except RefResolutionError:
self.fail(f"Can't find prop {prop} for {section} in {filepath}")

def _build_keywords(
self, obj: Any, schema_resolver: RefResolver, refs: list[str] | None = None
):
if refs is None:
refs = []
def _build_keywords(self, obj: Any, schema_resolver: RefResolver, refs: list[str]):
if not isinstance(obj, dict):
yield []
yield [], refs
return

if "type" in obj:
if "object" in ensure_list(obj["type"]):
if "properties" in obj:
for k, v in obj["properties"].items():
for item in self._build_keywords(v, schema_resolver, refs):
yield [k] + item
for item, refs in self._build_keywords(
v, schema_resolver, refs
):
yield [k] + item, refs
if "array" in ensure_list(obj["type"]):
if "items" in obj:
for item in self._build_keywords(
for item, refs in self._build_keywords(
obj["items"], schema_resolver, refs
):
yield ["*"] + item
yield ["*"] + item, refs

if "$ref" in obj:
ref = obj["$ref"]
if ref in refs:
yield []
yield [], refs
return
_, resolved_schema = schema_resolver.resolve(ref)
for item in self._build_keywords(
resolved_schema, schema_resolver, refs + [ref]
refs += [ref]
for item, refs in self._build_keywords(
resolved_schema, schema_resolver, refs
):
yield item
yield item, refs

yield []
yield [], refs

def build_keywords(self, schema_resolver):
self._found_keywords.append(
"/".join(["Resources", schema_resolver.referrer["typeName"], "Properties"])
)
refs = []
for k, v in schema_resolver.referrer.get("properties").items():
for item in self._build_keywords(v, schema_resolver):
for item, refs in self._build_keywords(v, schema_resolver, refs):
self._found_keywords.append(
"/".join(
[
Expand Down

0 comments on commit e8b38bf

Please sign in to comment.