Skip to content

Add µEd OpenAPI validation middleware#17

Open
m-messer wants to merge 5 commits into
mainfrom
feature/mued-schema-validation
Open

Add µEd OpenAPI validation middleware#17
m-messer wants to merge 5 commits into
mainfrom
feature/mued-schema-validation

Conversation

@m-messer
Copy link
Copy Markdown
Member

Summary

  • Embeds the official µEd OpenAPI 3.1.0 spec (runtime/schema/mued_v0.1.0.yml) into the binary
  • Adds kin-openapi middleware (internal/server/openapi.go) that validates all µEd route traffic against the spec at the HTTP layer, wired into the server chain via fx after NormalizePath
  • Request validation is strict — invalid µEd request bodies return 400 before the handler is reached
  • Response validation is strict — responses that don't conform to the spec return 500; the original error message is preserved when the worker returns a known error shape (error response conversion to µEd format is tracked in a separate PR)

How validation is layered

The legacy / route has no matching path in the spec so the middleware passes it through entirely unchanged, including the raw worker response body. The existing gojsonschema validation of the legacy worker protocol inside RuntimeHandler is also unchanged.

Layer Route What is validated Schema
OpenAPI middleware (new) µEd routes HTTP request/response shape mued_v0.1.0.yml
RuntimeHandler gojsonschema (existing) Legacy / {response, answer, params} worker protocol request-eval.json etc.

Test plan

  • go build ./... passes
  • go test ./... passes
  • POST /evaluate with missing submission field returns 400
  • POST /evaluate with a valid µEd body reaches the worker as before
  • GET /evaluate/health continues to work
  • POST / (legacy route) bypasses the OpenAPI validator and returns the raw worker response unchanged

🤖 Generated with Claude Code

m-messer and others added 5 commits May 14, 2026 16:51
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Relocates the spec from api/ into runtime/schema/ alongside the existing
JSON schema files, and renames it to mued_v0.1.0.yml to make the version
explicit. Removes the api/ package; embed is now owned by runtime/schema.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Previously, responses that failed spec validation were only logged as
warnings and forwarded anyway. Now a failed µEd response validation
returns 500 to the caller. The legacy / route is unaffected — it has
no matching path in the spec so the middleware passes it through
unchanged.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

2 participants