Skip to content

Add JSON Schema contract for /calculate, matching buem-gateway/meme - #24

Merged
jravani merged 1 commit into
mainfrom
chore/request-response-json-schema
Aug 1, 2026
Merged

jravani merged 1 commit into
mainfrom
chore/request-response-json-schema

Conversation

@jravani

@jravani jravani commented Aug 1, 2026

Copy link
Copy Markdown
Member

Closes #23.

Summary

  • Adds schemas/request_schema.json + schemas/response_schema.json (JSON Schema draft 2020-12) documenting the /calculate/:code contract, mirroring every field/constraint already hand-enforced in internal/api/handler/calculation.go and surfaces.go — including additionalProperties: false at both the top level and each surfaces[] item, the schema-side mirror of DisallowUnknownFields (Reject unknown fields in /calculate request body #22).
  • Adds schemas/example_request.json / schemas/example_response.json.
  • Adds test/schema_check.py (adapted from enerplanet/meme's script of the same name) validating both schemas are well-formed draft-2020-12 and both examples validate against them.
  • Wires it into CI (.github/workflows/ci.yml, new schema-check job matching buem-gateway's validate-schemas job) and Makefile (make schema-check, matching meme's target of the same name).

This is documentation + CI only — no change to internal/api/handler/*.go, docs/openapi.yaml, or any Go dependency. Matches how buem-gateway and meme both actually do this: hand-written Go validation stays the runtime gate; the JSON Schema is a CI-checked contract document, not a runtime validator (neither sibling loads its schema files from Go).

Test plan

  • make schema-check passes locally
  • Sanity-checked the schema actually rejects bad input, not just accepts everything: negative A_ref, unknown top-level field, unknown surfaces[] field, invalid type enum value, and zero area were all rejected
  • go build ./..., go vet ./..., go test ./... all still pass (no Go files touched)
  • CI (first run on this PR)

Adds schemas/{request,response}_schema.json + example payloads and a
CI drift-check (test/schema_check.py, make schema-check), matching
the pattern buem-gateway and meme both use: a hand-authored schema as
a documented, CI-checked contract, not a runtime validator. Runtime
validation stays the hand-written Go checks in calculation.go and
surfaces.go; additionalProperties: false mirrors the
DisallowUnknownFields behavior added in #22.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@jravani
jravani merged commit f1b95c8 into main Aug 1, 2026
6 checks passed
@jravani
jravani deleted the chore/request-response-json-schema branch August 1, 2026 21:25
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.

Add JSON Schema contract for /calculate, matching buem-gateway/meme

2 participants