Skip to content

fix(validator): close validation gaps and realign schema.json - #73

Merged
jedymatt merged 2 commits into
mainfrom
fix/validator-schema-gaps
Jul 7, 2026
Merged

fix(validator): close validation gaps and realign schema.json#73
jedymatt merged 2 commits into
mainfrom
fix/validator-schema-gaps

Conversation

@jedymatt

@jedymatt jedymatt commented Jul 4, 2026

Copy link
Copy Markdown
Owner

Related issue: #42 — this is the first incremental pass toward the validator rewrite tracked there (does not close it).

Summary

The hand-written validator.py and res/schema.json had been two independent, drifting definitions of "valid seed data" ever since the jsonschema dependency was dropped in v0.3.0.dev2 (the ! relationship prefix landed in the same commit and broke the schema's object-vs-scalar assumption). This closes four validation gaps and regenerates the schema so both describe the exact same format. Advances #42.

Validator fixes

  • Empty entity {} — previously passed validation, then crashed the seeder with an opaque AttributeError. Now raises a clean MissingKeyError. (The len == 0 early-return that skipped the model check is gone; empty lists are still a valid "seed nothing" no-op.)
  • Closed key set (check_keys) — unknown/typo keys within the old 2-key budget were silently ignored. Now raise InvalidKeyError with a precise message. This also improves the basic Seeder's error for a filter key from the misleading "Missing data key(s)" to "Unexpected key(s): filter".
  • Exactly one source key — an entity with both data and filter silently used data. Now raises InvalidKeyError.
  • Empty data: {} vs data: [] — kept as-is by design ({} = one row of DB defaults, [] = zero rows). Documented rather than changed.

Schema realignment

  • res/schema.json regenerated to mirror the fixed validator: ! prefix via patternProperties, additionalProperties: false (closed key set), oneOf (exactly one source), and a parent_entity/entity split encoding the parent-requires-model / child-optional rule (the distinction the old parent.json once needed a whole second file for).
  • Cross-validated against all 32 test fixtures: 0 mismatches between the schema and hybrid_validate.
  • Added package-data so the schema ships in the wheel (verified), and a README section on wiring it into editors (YAML modeline + VS Code json.schemas/yaml.schemas).

Cleanup

  • Removed the now-unused MaxLengthExceededError (not part of the public API / docs).

Test plan

  • 6 new validator tests (empty dict parent/child, unknown key parent/child, both-sources, basic-rejects-filter); updated the former extra-key test to expect the more precise InvalidKeyError.
  • Full suite: 98 passed.
  • Schema is well-formed Draft-07 and agrees with the validator on every fixture.

🤖 Generated with Claude Code

The hand-written validator and res/schema.json had drifted since the
jsonschema dependency was dropped in v0.3.0.dev2. Fix four validation
gaps and regenerate the schema so both describe the same format.

- Empty entity {} now raises MissingKeyError instead of passing
  validation and crashing the seeder with AttributeError
- Enforce a closed key set (check_keys) so unknown/typo keys raise
  InvalidKeyError instead of being silently ignored
- Require exactly one source key; {data, filter} now raises instead
  of silently picking data and ignoring filter
- Regenerate res/schema.json to match the validator: '!' relationship
  prefix via patternProperties, additionalProperties:false, oneOf
  source, parent/child model split (0 mismatches across 32 fixtures)
- Ship schema.json as package-data; document editor validation in README
- Remove now-unused MaxLengthExceededError

Advances #42.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jedymatt jedymatt mentioned this pull request Jul 4, 2026
- Keep MaxLengthExceededError as a deprecated alias of InvalidKeyError so
  existing imports and except clauses keep working
- Treat an empty parent dict as a valid no-op again (placeholder seed
  files); empty child dicts still raise MissingKeyError
- Reject non-string attribute names with InvalidTypeError instead of
  leaking AttributeError from iter_ref_kwargs
- Pin README schema URLs to a release tag instead of main
- Drop dead PARENT_WITH_EXTRA_LENGTH_INVALID fixture and fix a wrong
  comment about the old 2-key budget

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@jedymatt
jedymatt merged commit ff624e1 into main Jul 7, 2026
16 checks passed
@jedymatt
jedymatt deleted the fix/validator-schema-gaps branch July 7, 2026 02:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant