This issue was found by a Codex global code scan of the repository.
Affected code:
|
if not argument.repeat: |
|
data["properties"] = properties |
|
data["required"] = required |
|
if allof: |
|
data["allOf"] = allof |
|
else: |
|
data["items"] = { |
|
"type": "object", |
|
"properties": properties, |
|
"required": required, |
|
} |
|
if allof: |
|
data["items"]["allOf"] = allof |
Problem:
For repeat=True, schema generation always puts subfield validation under items. That works for list-style repeated arguments, but for dict-style repeated arguments the top-level type is "object"; JSON Schema ignores items on objects.
Reproducer:
from dargs import Argument
from dargs.json_schema import generate_json_schema
from jsonschema import validate
arg = Argument("base", dict, [Argument("sub1", int), Argument("sub2", str)], repeat=True)
schema = generate_json_schema(arg)
validate({"item1": {"sub1": 1, "sub2": None}}, schema)
validate({"item1": {"sub1": 1}}, schema)
print(schema)
Observed behavior:
Both invalid objects validate because the generated schema has type: ["object"] plus items, and the item schema is ignored.
Expected behavior:
Dict-style repeated arguments should use object-key validation, for example additionalProperties or patternProperties, so every repeated entry is checked against the subfield schema.
This issue was found by a Codex global code scan of the repository.
Affected code:
dargs/dargs/json_schema.py
Lines 116 to 128 in b4db564
Problem:
For
repeat=True, schema generation always puts subfield validation underitems. That works for list-style repeated arguments, but for dict-style repeated arguments the top-level type is"object"; JSON Schema ignoresitemson objects.Reproducer:
Observed behavior:
Both invalid objects validate because the generated schema has
type: ["object"]plusitems, and the item schema is ignored.Expected behavior:
Dict-style repeated arguments should use object-key validation, for example
additionalPropertiesorpatternProperties, so every repeated entry is checked against the subfield schema.