Skip to content

Generate SPLAT JSON Schema from the Go types#24

Closed
stackedsax wants to merge 1 commit into
mainfrom
feat/splat-json-schema
Closed

Generate SPLAT JSON Schema from the Go types#24
stackedsax wants to merge 1 commit into
mainfrom
feat/splat-json-schema

Conversation

@stackedsax

Copy link
Copy Markdown
Contributor

What

Generate a JSON Schema for the SPLAT job spec directly from the Go types, so it
can't drift from the implementation.

  • internal/splat/schema reflects splat.Job into a JSON Schema (draft
    2020-12). The opaque scalar wrappers (Quantity, Duration) are mapped to
    string via the reflector's type mapper, keeping the dependency out of the
    core splat package.
  • schema/splat.schema.json is the committed artifact. Regenerate with
    make schema (go test ./internal/splat/schema -update).
  • A drift test runs under go test ./... (already in CI's test job), failing if
    the committed schema is stale — no new CI wiring needed.
  • New dep: github.com/invopop/jsonschema.

⚠️ Surfaced a pre-existing bug (tracked separately)

Validating the current examples/*.yaml against the generated schema fails:
they use snake_case field names (cpus_per_task, client_id, …) while the
Go types — and everything the tool actually parses — use camelCase
(cpusPerTask, clientId). Confirmed at runtime: a snake_case SPLAT file has
its fields silently dropped on convert; the camelCase equivalent works. So
the examples and SPEC.md's field reference are wrong, not the schema. Fixing
that (docs → camelCase, or add snake_case support in the parser) is a separate
decision, so this PR does not gate CI on example validation yet.

Testing

  • go test ./internal/splat/schema — drift check + a shape sanity check.
  • Full suite / vet / gofmt clean.

🤖 Generated with Claude Code

Add internal/splat/schema, which reflects splat.Job into a JSON Schema
(draft 2020-12) with the opaque scalar wrappers (Quantity, Duration) mapped
to strings. The committed schema/splat.schema.json is regenerated with
`make schema` (go test ./internal/splat/schema -update); a drift test runs
under `go test ./...` so the schema can never silently fall out of sync with
the types.

Depends on github.com/invopop/jsonschema (kept out of the core splat package
via the reflector's type Mapper).

Note: validating the current examples/ against this schema fails because they
use snake_case field names while the types/schema use camelCase — a
pre-existing docs/impl mismatch tracked separately; the schema here reflects
what the tool actually accepts.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016PnTz6Zxqa4jHocK8kCbyx
@stackedsax

Copy link
Copy Markdown
Contributor Author

Superseded by the combined schema + camelCase + CI-validation PR (the schema commit is included there, and the examples now validate against it).

@stackedsax stackedsax closed this Jul 18, 2026
@stackedsax
stackedsax deleted the feat/splat-json-schema branch July 18, 2026 21:34
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