Skip to content

feat(extensions): add discovery OpenAPI document builder#2025

Open
zdql wants to merge 2 commits intox402-foundation:mainfrom
zdql:feat/discovery-openapi
Open

feat(extensions): add discovery OpenAPI document builder#2025
zdql wants to merge 2 commits intox402-foundation:mainfrom
zdql:feat/discovery-openapi

Conversation

@zdql
Copy link
Copy Markdown
Contributor

@zdql zdql commented Apr 13, 2026

Summary

  • Adds discovery, a pure function in @x402/extensions that turns an x402 RoutesConfig into an OpenAPI 3.1 document ready to host at /openapi.json.
  • Derives paths, parameters, requestBody, responses[200/402/401], x-payment-info, and SIWX security from the routes map and existing bazaar declarations.
  • Exposes DiscoveryOptions, OpenAPIDocument, and their Zod schemas (DiscoveryOptionsSchema, OpenAPIDocumentSchema) for runtime validation.
  • Adds a dedicated docs page at docs/extensions/discovery.mdx, a row in the Available Extensions table, and a nav entry in docs.json.

Why

bazaar describes a single endpoint inside a 402 response, which is great for on-demand cataloging but does not give crawlers or AI agents a single URL they can fetch to enumerate everything a server offers. discovery closes that gap by reusing the routes map the server already has, with a one-line call-site in the server's framework (e.g. app.get("/openapi.json", (_req, res) => res.json(discovery(routes, options)))).

What it derives automatically

Source in RouteConfig Lands in
Route key "POST /analyze" paths["/analyze"].post
config.description operation.summary
config.accepts[0].price operation["x-payment-info"].price
config.extensions.bazaar body schema requestBody.content["application/json"].schema
config.extensions.bazaar query/path schemas operation.parameters[]
config.extensions.bazaar.info.output.example responses["200"] (with inferred schema)
config.extensions["sign-in-with-x"] present security: [{ siwx: [] }], no x-payment-info

Path params (:id, [id]) are auto-converted to OpenAPI {id} syntax. Every paid operation gets responses["402"]; SIWX-only operations get responses["401"] plus a top-level components.securitySchemes.siwx block.

What the caller must provide

DiscoveryOptions carries document-level metadata that cannot be synthesized from routes:

  • info.title / info.version (required)
  • info.xGuidance — high-level agent guidance (required; emitted as info["x-guidance"])
  • info.description (optional)
  • servers (optional)
  • protocols (optional, defaults to [{ x402: {} }])

Introduces `discovery`, a pure function that converts an x402 `RoutesConfig`
into an AgentCash-compatible OpenAPI 3.1 document for hosting at /openapi.json.
Derives paths, parameters, request bodies, payment info, and SIWX security
from the same routes map and bazaar declarations the server already has, so
there is no second source of truth. Exported from `@x402/extensions` alongside
Zod schemas for options and output validation.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 13, 2026

@zdql is attempting to deploy a commit to the Coinbase Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions bot added typescript sdk Changes to core v2 packages docs labels Apr 13, 2026
- Fill JSDoc block descriptions and @returns tags on discovery/utils.ts
  helpers to satisfy jsdoc/require-description and jsdoc/require-returns.
- Apply prettier reflows in discovery/{index,types}.ts and src/index.ts.
- Add a minor-bump changeset for @x402/extensions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs sdk Changes to core v2 packages typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant