Skip to content

feat: auto-generate OpenAPI spec from route schemas#154

Merged
Jing-yilin merged 2 commits into
fix/worlds-endpoint-discoveryfrom
feat/gateway-auto-openapi
Mar 24, 2026
Merged

feat: auto-generate OpenAPI spec from route schemas#154
Jing-yilin merged 2 commits into
fix/worlds-endpoint-discoveryfrom
feat/gateway-auto-openapi

Conversation

@Jing-yilin
Copy link
Copy Markdown
Contributor

Stacked on #153

Replace the hand-maintained gateway/openapi.yaml with @fastify/swagger auto-generation from route schemas.

Changes

  • Register @fastify/swagger + @fastify/swagger-ui in the gateway
  • Extract reusable JSON Schema definitions into gateway/schemas.mjs
  • Add inline schema to all 10 gateway routes (health, agents, worlds, world/:id, agent.json, peer/ping, peer/peers, peer/announce, peer/heartbeat, peer/message)
  • Serve Swagger UI at GET /docs and JSON spec at GET /docs/json
  • Delete gateway/openapi.yaml (no longer needed)
  • Update Dockerfile to include schemas.mjs

Benefits

  • Schema changes are made alongside route code -- can never go out of sync
  • Fastify validates responses against the schema at runtime (catches type bugs)
  • /docs provides interactive API explorer for development
  • Previously failing 6 gateway tests now pass (response serialization through schemas fixes Fastify inject issues)

Replace manual gateway/openapi.yaml with @fastify/swagger auto-generation.
All 10 routes now have inline JSON Schema definitions that Fastify uses for
both response validation and OpenAPI spec generation.

- Add @fastify/swagger + @fastify/swagger-ui dependencies
- Extract reusable schemas into gateway/schemas.mjs
- Add inline schema to all gateway and peer routes
- Serve Swagger UI at /docs and JSON spec at /docs/json
- Remove hand-maintained openapi.yaml
- Update Dockerfile to include schemas.mjs
- Add /docs/json spec test
Copy link
Copy Markdown
Contributor Author

@Jing-yilin Jing-yilin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. gateway/server.mjs:611, gateway/server.mjs:656, gateway/server.mjs:692
    The new POST route schemas only declare response, so the generated /docs/json spec no longer includes any requestBody for /peer/announce, /peer/heartbeat, or /peer/message. That is a regression from the deleted gateway/openapi.yaml, and it makes the auto-generated spec incomplete for anyone trying to call those endpoints from the docs alone. I verified this locally by injecting /docs/json: all three operations currently have requestBody === undefined even though AnnounceRequest, HeartbeatRequest, and SignedMessage are registered in gateway/schemas.mjs.

  2. test/gateway-worlds.test.mjs:70
    The new docs test only checks that the paths and component schema names exist, so it still passes when the POST operations lose their request contracts entirely. Since this PR replaces the hand-maintained OpenAPI file, the test should assert that those three operations actually reference their request schemas.

Add body schema refs for /peer/announce, /peer/heartbeat, /peer/message
so the auto-generated OpenAPI spec includes requestBody documentation.
Disable body validation in the peer plugin scope to avoid interfering
with the custom rawBody content parser used for signature verification.
Add test assertion that POST operations reference their request schemas.
@Jing-yilin Jing-yilin merged commit 1a1bc7e into fix/worlds-endpoint-discovery Mar 24, 2026
@Jing-yilin Jing-yilin deleted the feat/gateway-auto-openapi branch March 24, 2026 06:29
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