feat(fast-validator): add multi-error accumulation and RFC 6901 JSON pointer precision - #308
Conversation
There was a problem hiding this comment.
🔵 Needs a closer look
It changes core validation semantics by recursively stripping additionalProperties/unevaluatedProperties: false (silently weakening validation) and reworks error control flow, which warrants human review beyond the flagged stray artifact.
Pull request overview
This PR overhauls the --fast validator (fast_validator.py) to improve error reporting during high-speed batch validation. Instead of aborting on the first failure and surfacing generic $ root errors from fastjsonschema's oneOf/anyOf handling, it now accumulates all failures per item, attributes each to its schema source, and normalizes field paths into $.-style pointers. It also adds more aggressive schema patching so more community extensions compile under fastjsonschema without being skipped.
Changes:
- Adds
parse_json_pointer,FastSTACValidationError, andFastSTACMultiValidationError, plus multi-error accumulation across base + all extension schemas invalidator/run/run_dict/_validate_recursive. - Adds
compile_unrolled_schema(per-branchoneOf/anyOfcompilation to recover exact field paths) and expandsoptimize_schema_for_compilerto stripadditionalProperties/unevaluatedProperties: false,$comment, and prune empty subschemas. - Bumps version to
4.6.0(CHANGELOG +pyproject.toml), updates a test collection expectation to v1.1.0 schemas, removes a network-dependent test, and addstests/test_error_reporting.py.
File summaries
| File | Description |
|---|---|
| stac_validator/fast_validator.py | Core logic: JSON-pointer normalization, error classes, multi-error accumulation, branch unrolling, broader schema patching. |
| tests/test_error_reporting.py | New offline tests covering pointer parsing, error classes, oneOf unmasking, and multi-error accumulation. |
| tests/test_validate_item_collection.py | Updates expected schema versions to v1.1.0/projection v2.0.0; removes a remote paginated test. |
| test.json | Adds a 3089-line Sentinel-2 item at the repo root (appears to be a benchmarking/debug leftover). |
| pyproject.toml | Version bump 4.5.2 → 4.6.0. |
| CHANGELOG.md | Adds v4.6.0 release notes and compare links. |
Review details
- Files reviewed: 5/6 changed files
- Comments generated: 2
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Summary
This PR resolves issues with vague error reporting during high-speed batch validation. Previously,
fastjsonschemaswallowed nested field paths behind generic top-level$root errors when evaluating composite extension schemas (oneOf/anyOf). Additionally, the validation loop short-circuited on the first broken field, requiring multi-pass debugging across large batch jobs.This release introduces multi-error accumulation, lazy branch unrolling, RFC 6901 JSON Pointer formatting, and multi-tier schema compilation to ensure 100% extension compatibility at full C-speed.
Key Changes
Multi-Error Accumulation (
FastSTACMultiValidationError)FastValidatorexecution pass to evaluate the base schema and all active item extensions in a single run.RFC 6901 JSON Pointer Normalization (
parse_json_pointer)fastjsonschema's internal CPython variable names (e.g.,data['properties']['eo:cloud_cover']anddata.properties.sat:relative_orbit) into standard JSON Pointers (e.g.,$.properties.eo:cloud_cover).Compile-Time Branch Unrolling (
compile_unrolled_schema)oneOf/anyOfsubschema branches independently to preventfastjsonschema's internaltry...exceptexception handling from discarding leaf-node field paths.Resilient Multi-Tier Schema Patching
optimize_schema_for_compiler()to strip restrictiveadditionalProperties: falseflags from shared extension objects.{}) and draft-2020-12 conditional blocks that causedIndentationErrororJsonSchemaDefinitionExceptionskips on extensions likefile/v2.1.0,product/v1.0.0, andstorage/v2.0.0.Benchmark & Diagnostic Comparison
Before (
v4.5.2):After (
v4.6.0):