Repository navigation
feat(schema): pkg/schema engine with embedded schemas, custom keywords and guide validation (AFDEV-10) - #2
Merged
Merged
Conversation
…s and guide validation (AFDEV-10) Embed the v1 schema files through a root schemas package, compile them at init against a strict keyword allow-list, implement the x- keywords and the text and date-time primitives, and validate payloads as a guide that never rejects. Fixture-driven tests read conformance/ directly.
…t compile, items {} mirrors the reference (AFDEV-10)
Review findings: the decimal comparator keeps exponents exact instead of saturating; a schema file with a repeated member fails at init; an items schema without keywords is skipped like the reference; the fixture pre-check for duplicate members tracks object state correctly and the occurred_at test allows the context value cut.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
pkg/schema, the v1 schema engine (package 2 of the v4 server work):schemasat the repository root embedsenvelope.v1.jsonandkinds/*.json(go:embedcannot reach a parent directory and the files stay at the contract path).pkg/schemacompiles every file at package init; there is no I/O at call time.List()exposes{kind, versions}includingenvelope,Document(kind, version)returns the file bytes verbatim for the later HTTP package.x-max-bytes,x-trim,x-normalize: token,x-recommended,x-unique-by,x-on-violation, plus the standard keywords the shipped schemas use. Compilation checks every node against a strict keyword and value-shape allow-list (the same set the Python reference andscripts/contract-check.pyenforce) and panics at init on anything else, so no keyword is ever silently ignored.x-on-violation: moveis accepted only at the envelope'sadditionalProperties.Validate(kind, version, payload, placed)and(*Schema).Guidenever reject: transforms rewrite the payload in place, every other violation is oneDetail{code, pointer, message}with the code fromconformance/warnings.json(a test asserts the Go keyword-to-code table equals the contract's). Unknown kinds and versions yieldno_schema/unknown_schema_version.Trim,LowerSimple,Token,NewlinesToSpaces,TruncateBytes,EscapeToken,ParseDateTime,NormalizeDateTime,FormatDateTime. The White_Space set is spelled out from the contract; lower-casing is the simple per-code-point mapping.json.Number(source spelling kept, never converted). Integer classification and range/enum comparisons use a decimal comparator over the spelling (sign, significant digits, saturated exponent), so2.0is an integer and equals2in an enum,-0equals0, and a pathological exponent costs nothing.Why a hand-written walker
The candidate library (
github.com/santhosh-tekuri/jsonschema/v6, checked against v6.0.3) lets a custom keyword only return an error: it cannot rewrite the instance, it is silent where the guide wantsunknown_field, and it reports every failing keyword where the guide wants one warning per member. A full walker is needed beside it anyway, so it would cover nine standard keywords and add two modules. The walker mirrorsconformance/reference/guide.pyline for line.Tests
Table tests per keyword, placed members, pointer escaping, compile-time rejections, text primitives, comparator vectors, RFC 3339 vectors. Fixture-driven tests read
conformance/directly: normalisation vectors from every hash and decode fixture whose bodyencoding/jsoncan parse faithfully (bodies with invalid UTF-8 or duplicate members are the decoder's and are skipped by name), the kind-schema guide fixtures end to end on the payload, and theoccurred_atfixtures.Docs
docs/develop.md: layout lines forpkg/schema/and theschemasGo package, and the rule thatpkg/schemais the one implementation of the contract's text and schema rules.Verification
All gates green locally:
just check(tree clean afterwards),go test -race -count=1 ./..., live e2e 55/55, shellcheck (CI and develop.md forms), skill tests 124/124,just contract. Alsogo vetandstaticcheck 2026.2.1clean on the whole module (run viago run; not a CI gate yet).Out of scope: the decoder, serving schemas over HTTP, the canonical writer.