Add JSON Schema contract for /calculate, matching buem-gateway/meme - #24
Merged
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Closes #23.
Summary
schemas/request_schema.json+schemas/response_schema.json(JSON Schema draft 2020-12) documenting the/calculate/:codecontract, mirroring every field/constraint already hand-enforced ininternal/api/handler/calculation.goandsurfaces.go— includingadditionalProperties: falseat both the top level and eachsurfaces[]item, the schema-side mirror ofDisallowUnknownFields(Reject unknown fields in /calculate request body #22).schemas/example_request.json/schemas/example_response.json.test/schema_check.py(adapted fromenerplanet/meme's script of the same name) validating both schemas are well-formed draft-2020-12 and both examples validate against them..github/workflows/ci.yml, newschema-checkjob matchingbuem-gateway'svalidate-schemasjob) andMakefile(make schema-check, matchingmeme'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 howbuem-gatewayandmemeboth 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-checkpasses locallyA_ref, unknown top-level field, unknownsurfaces[]field, invalidtypeenum value, and zeroareawere all rejectedgo build ./...,go vet ./...,go test ./...all still pass (no Go files touched)