Skip to content

feat: serve OpenAPI spec at <prefix>/__tapi/openapi.json#333

Open
mismosmi wants to merge 6 commits into
mainfrom
claude/openapi-spec-serving-TDqi9
Open

feat: serve OpenAPI spec at <prefix>/__tapi/openapi.json#333
mismosmi wants to merge 6 commits into
mainfrom
claude/openapi-spec-serving-TDqi9

Conversation

@mismosmi
Copy link
Copy Markdown
Member

Summary

  • Adds an openapi: { title: string; version: string } option to defineApi.
  • When set, GET <basePath>/__tapi/openapi.json returns the spec produced by the existing generateOpenAPISchema (no behavior change to the schema itself).
  • When omitted, the path is not reserved and falls through to normal route matching (404 unless the user defined the route themselves).
  • Spec is generated on first request and memoized on the request-handler closure.

Usage

const api = defineApi({
  openapi: { title: "My API", version: "1.0.0" },
}).route("/things", { GET: defineHandler(...) });
$ curl http://localhost:3000/api/__tapi/openapi.json

Test plan

  • Unit tests in create-request-handler.test.ts cover: spec served with correct content-type and body when configured, 404 when not configured, basePath is respected, output is byte-identical across requests (memoization).
  • pnpm --filter @farbenmeer/tapi test — 64/64 passing.
  • pnpm --filter @farbenmeer/tapi build — typecheck passes.
  • Manual smoke test against an example app.

Notes

The original prompt referenced issue #326, but that issue is about asynchronous workflows. The branch name and task description make it clear the intended work was OpenAPI spec serving; this PR addresses that. Happy to retitle/relabel if a different issue is the right tracker.

https://claude.ai/code/session_01WFKtX6dLxJ1FCyQT2mpnPW


Generated by Claude Code

Accept `openapi: { title, version }` on `defineApi` and expose the
generated spec from the request handler when configured. Falls through
to normal route matching when the option is omitted.

https://claude.ai/code/session_01WFKtX6dLxJ1FCyQT2mpnPW
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 24, 2026

🦋 Changeset detected

Latest commit: 468ee6a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@farbenmeer/tapi Patch
@farbenmeer/bunny Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mismosmi mismosmi changed the title feat: serve OpenAPI spec at &lt;prefix&gt;/__tapi/openapi.json feat: serve OpenAPI spec at <prefix>/__tapi/openapi.json May 24, 2026
@mismosmi
Copy link
Copy Markdown
Member Author

pick one of the examples and add an e2e test that verifies the openapi schema

Enables openapi config on the contact-book api and adds a playwright dev
e2e test that fetches /api/__tapi/openapi.json and asserts the served
spec contains the configured info, the registered routes/methods, the
dynamic path param, and the POST body schema.

https://claude.ai/code/session_01WFKtX6dLxJ1FCyQT2mpnPW
@mismosmi
Copy link
Copy Markdown
Member Author

bunny now serves the openapi spec from two different paths - /.well-know/openapi.json and /api/__tapi/openapi.json

remove the well-known path.

The OpenAPI spec is now served by tapi at /api/__tapi/openapi.json when
`openapi: { title, version }` is passed to `defineApi`. Removed the
duplicate Bunny-side serving from both dev and prod, along with the
now-unused `apiInfo` option on `createBunnyApp`.

https://claude.ai/code/session_01WFKtX6dLxJ1FCyQT2mpnPW
@mismosmi mismosmi marked this pull request as ready for review May 24, 2026 16:05
@mismosmi mismosmi requested a review from pex May 24, 2026 16:05

interface Options {
cache?: Cache;
openapi?: OpenAPIInfo;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

rename this parameter to 'oas' instead of 'openapi'

Renames the user-facing config field on defineApi and the matching
ApiDefinition field/type from openapi/OpenAPIInfo to oas/OasInfo, per
review feedback. URL path and existing function names are unchanged.

https://claude.ai/code/session_01WFKtX6dLxJ1FCyQT2mpnPW
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