feat(extensions): add discovery OpenAPI document builder#2025
Open
zdql wants to merge 2 commits intox402-foundation:mainfrom
Open
feat(extensions): add discovery OpenAPI document builder#2025zdql wants to merge 2 commits intox402-foundation:mainfrom
zdql wants to merge 2 commits intox402-foundation:mainfrom
Conversation
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>
|
@zdql is attempting to deploy a commit to the Coinbase Team on Vercel. A member of the Team first needs to authorize it. |
- 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>
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.
Summary
discovery, a pure function in@x402/extensionsthat turns an x402RoutesConfiginto an OpenAPI 3.1 document ready to host at/openapi.json.parameters,requestBody,responses[200/402/401],x-payment-info, and SIWX security from the routes map and existing bazaar declarations.DiscoveryOptions,OpenAPIDocument, and their Zod schemas (DiscoveryOptionsSchema,OpenAPIDocumentSchema) for runtime validation.docs/extensions/discovery.mdx, a row in the Available Extensions table, and a nav entry indocs.json.Why
bazaardescribes 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.discoverycloses 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
RouteConfig"POST /analyze"paths["/analyze"].postconfig.descriptionoperation.summaryconfig.accepts[0].priceoperation["x-payment-info"].priceconfig.extensions.bazaarbody schemarequestBody.content["application/json"].schemaconfig.extensions.bazaarquery/path schemasoperation.parameters[]config.extensions.bazaar.info.output.exampleresponses["200"](with inferred schema)config.extensions["sign-in-with-x"]presentsecurity: [{ siwx: [] }], nox-payment-infoPath params (
:id,[id]) are auto-converted to OpenAPI{id}syntax. Every paid operation getsresponses["402"]; SIWX-only operations getresponses["401"]plus a top-levelcomponents.securitySchemes.siwxblock.What the caller must provide
DiscoveryOptionscarries document-level metadata that cannot be synthesized from routes:info.title/info.version(required)info.xGuidance— high-level agent guidance (required; emitted asinfo["x-guidance"])info.description(optional)servers(optional)protocols(optional, defaults to[{ x402: {} }])