Skip to content

Commit 52b75ff

Browse files
authored
Syntax error analyzer handles defs (#80)
* Analyzing errors in defs Signed-off-by: Mandana Vaziri <[email protected]> * cleanup Signed-off-by: Mandana Vaziri <[email protected]> --------- Signed-off-by: Mandana Vaziri <[email protected]>
1 parent 45d6269 commit 52b75ff

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

pdl/pdl_schema_error_analyzer.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ def analyze_errors(defs, schema, data, loc: LocationType) -> list[str]: # noqa:
117117
ret += analyze_errors(
118118
defs, schema["properties"][field], data[field], newloc
119119
)
120+
if "additionalProperties" in schema.keys() and not isinstance(
121+
schema["additionalProperties"], bool
122+
):
123+
for key, value in data.items():
124+
nloc = append(loc, key)
125+
ret += analyze_errors(
126+
defs, schema["additionalProperties"], value, nloc
127+
)
120128

121129
elif is_any_of(schema):
122130
if len(schema["anyOf"]) == 2 and nullable(schema):

tests/data/line/hello31.pdl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
defs:
2+
3+
# ... several other defs, ~85 lines
4+
get_current_weather:
5+
function:
6+
subject: str
7+
return:
8+
api: https
9+
url: https://api.weatherapi.com/v1/current.json?key=cf601276764642cb96224947230712&q=
10+
input: "{{ subject }}"
11+
show_result: false

tests/test_examples.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
pathlib.Path("tests") / "data" / "line" / "hello8.pdl",
1414
pathlib.Path("tests") / "data" / "line" / "hello10.pdl",
1515
pathlib.Path("tests") / "data" / "line" / "hello11.pdl",
16+
pathlib.Path("tests") / "data" / "line" / "hello31.pdl",
1617
]
1718

1819

tests/test_line_table.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,18 @@ def test_line29(capsys):
405405

406406
def test_line30(capsys):
407407
do_test(line30, capsys)
408+
409+
410+
line31 = {
411+
"file": "tests/data/line/hello31.pdl",
412+
"errors": [
413+
"",
414+
"tests/data/line/hello31.pdl:0 - Missing required field: function",
415+
"tests/data/line/hello31.pdl:0 - Missing required field: return",
416+
"tests/data/line/hello31.pdl:11 - Field not allowed: show_result",
417+
],
418+
}
419+
420+
421+
def test_line31(capsys):
422+
do_test(line31, capsys)

0 commit comments

Comments
 (0)