Incorrect validation of valid payload with valid schema
Maintainer antworten meist innerhalb von 6 Tagen
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 45/100
- Issue-Typ
- Bug
- Klarheit
- Klar beschrieben
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- python
- Bereich
- backend-api-design
Rechercherichtung
Reproduziere den Fehler mit base.json, camera.json, den Payload-Dateien und dem gezeigten Draft202012Validator-Skript. Verfolge zunächst nach, wie die Registry $dynamicRef und den relativen $ref auf #/$defs/size über die beiden Schemas hinweg auflöst. Als erledigt gilt die Ermittlung, ob die Ausnahme mit JSON Schema übereinstimmt, und, falls nicht, das Hinzufügen eines Regressionstests, der diese Schemaanordnung abdeckt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
I have a schema that heavily utilises $dynamicRef to inject parts of schema from other files.
Namely, here is the base schema:
base.json:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "base.json",
"type": "object",
"additionalProperties": false,
"properties": {
"orderNumber": {
"type": "integer",
"minimum": 0
},
"downstreamNumber": {
"$dynamicRef": "#specialDownstreamNumber"
},
"schemaName": {
"$dynamicRef": "#concreteName"
},
"schemaVersion": {
"$dynamicRef": "#concreteVersion"
},
"timestamp": {
"type": "integer"
},
"data": {
"$dynamicRef": "#concreteData"
}
},
"required": [
"data",
"orderNumber",
"schemaName",
"schemaVersion",
"downstreamNumber",
"timestamp"
],
"$defs": {
"name": {
"const": "base",
"$dynamicAnchor": "concreteName"
},
"version": {
"const": "0.0.0",
"$dynamicAnchor": "concreteVersion"
},
"data": {
"not": true,
"$dynamicAnchor": "concreteData"
},
"downstreamNumber": {
"type": "integer",
"minimum": 1,
"$dynamicAnchor": "specialDownstreamNumber"
}
}
}
And here is the specific JSON that fills in the data for the base:
camera.json:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "camera.json",
"$ref": "base.json",
"$defs": {
"name": {
"const": "camera.info",
"$dynamicAnchor": "concreteName"
},
"version": {
"const": "1.0.0",
"$dynamicAnchor": "concreteVersion"
},
"data": {
"$dynamicAnchor": "concreteData",
"type": "object",
"additionalProperties": false,
"properties": {
"cameraFacing": {
"enum": [
"Front",
"Back"
]
},
"cameraFrameSize": {
"$ref": "#/$defs/size"
},
"roi": {
"$ref": "#/$defs/size"
},
"viewPortAspectRatio": {
"type": "number"
}
},
"required": [
"cameraFacing",
"cameraFrameSize",
"roi",
"viewPortAspectRatio"
]
},
"downstreamNumber": {
"type": "integer",
"minimum": 0,
"$dynamicAnchor": "specialDownstreamNumber"
},
"size": {
"type": "object",
"additionalProperties": false,
"properties": {
"width": {
"type": "integer"
},
"height": {
"type": "integer"
}
},
"required": [
"width",
"height"
]
}
}
}
Here is the JSON that I'm trying to validate:
{
"orderNumber": 4,
"downstreamNumber": 1,
"schemaVersion": "1.0.0",
"schemaName": "camera.info",
"timestamp": 1756525700,
"data": {
"cameraFacing": "Back",
"cameraFrameSize": {
"width": 3841,
"height": 2161
},
"roi": {
"width": 3840,
"height": 1858
},
"viewPortAspectRatio": 2.066
}
}
Here is how I'm doing the validation:
import json
from pathlib import Path
from jsonschema.validators import Draft202012Validator
from referencing import Registry, Resource
ROOT = Path(__file__).absolute().parent
SCHEMAS = ROOT / Path("schema")
def validate_file(validator: Draft202012Validator, file: Path):
with open(file, "rt", encoding="utf-8") as f:
instance = json.load(f)
instance = json.loads(file.read_text())
print(f"Validating {file}...")
validator.validate(instance)
def retrieve_from_filesystem(uri: str):
path = SCHEMAS / Path(uri)
contents = json.loads(path.read_text())
return Resource.from_contents(contents)
def main():
registry = Registry(retrieve=retrieve_from_filesystem)
schema_file = SCHEMAS / Path("camera.json")
with open(schema_file, "rt", encoding="utf-8") as f:
schema = json.load(f)
validator = Draft202012Validator(
schema,
registry=registry
)
tests_path = ROOT / Path("payload")
for file in tests_path.iterdir():
validate_file(validator, file)
if __name__ == "__main__":
main()
The validation fails with exception:
jsonschema.exceptions._WrappedReferencingError: PointerToNowhere: '/$defs/size' does not exist within {'$schema': 'https://json-schema.org/draft/2020-12/schema', '$id': 'base.json', 'type': 'object', 'additionalProperties': False, 'properties': {'orderNumber': {'type': 'integer', 'minimum': 0}, 'downstreamNumber': {'$dynamicRef': '#specialDownstreamNumber'}, 'schemaName': {'$dynamicRef': '#concreteName'}, 'schemaVersion': {'$dynamicRef': '#concreteVersion'}, 'timestamp': {'type': 'integer'}, 'data': {'$dynamicRef': '#concreteData'}}, 'required': ['data', 'orderNumber', 'schemaName', 'schemaVersion', 'downstreamNumber', 'timestamp'], '$defs': {'name': {'const': 'base', '$dynamicAnchor': 'concreteName'}, 'version': {'const': '0.0.0', '$dynamicAnchor': 'concreteVersion'}, 'data': {'not': True, '$dynamicAnchor': 'concreteData'}, 'downstreamNumber': {'type': 'integer', 'minimum': 1, '$dynamicAnchor': 'specialDownstreamNumber'}}}
Which is incorrect, as camera.json does contain /$defs/size. I've tried validating the payload with a different validator and it validates the payload successfully.
I don't see anything wrong with my schema definitions and boon has no problem validating the payload.
Is this a bug in jsonschema library or did I do something wrong and boon fails to detect it?
- Vorherrschende Sprache
- Python
- Sterne
- 5k
- Forks
- 741
- Ø Merge
- 4 T. 17 Std.
- Gemergte PRs (30 T.)
- 6
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus python-jsonschema/jsonschema
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
python-jsonschema/jsonschema#1610 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 6 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
python-jsonschema/jsonschema#1588 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 6 Tagen
-
Iterator error contexts lose parent links and absolute pathsEvtl. wieder frei @DawnofGenX hat das vor 59 Tagen übernommen, und es ist kein Pull Request offen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
python-jsonschema/jsonschema#1584 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 6 Tagen
-
regex format checker crashes with RecursionError on deeply nested patternsEvtl. vergeben @DawnofGenX hat das vor 59 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
python-jsonschema/jsonschema#1538 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 6 Tagen
-
is_duration raises an uncaught decimal.Overflow on a duration with a large exponentEvtl. wieder frei Ein Pull Request dazu wurde ohne Merge geschlossen. OffenNeeds Test Upstream
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
python-jsonschema/jsonschema#1511 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 6 Tagen
Alle Issues in python-jsonschema/jsonschema
Ähnliche Issues
-
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 78/100
web-push-libs/pywebpush#216 · 1 Kommentar ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
AgriciDaniel/claude-seo#572 ·
Maintainer antworten meist innerhalb von 5 Tagen
-
area:print-dispatch
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 92/100
Maintainer antworten meist innerhalb von 1 Tag
-
area: docs domain: technical-writing good first issue type: documentation
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 80/100
Deepak3699/Ai_Mentor#919 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag