feat: auto-serve OpenAPI spec at /openapi.json for x402 resource servers#1965
Open
zdql wants to merge 3 commits intox402-foundation:mainfrom
Open
feat: auto-serve OpenAPI spec at /openapi.json for x402 resource servers#1965zdql wants to merge 3 commits intox402-foundation:mainfrom
zdql wants to merge 3 commits intox402-foundation:mainfrom
Conversation
Adds automatic OpenAPI 3.1.0 spec generation and hosting so that x402 sellers get a discoverable /openapi.json endpoint with zero configuration. The spec includes x-payment-info on each operation, matching the format expected by agentcash-discovery. - New @x402/core/openapi module (schemas, route parsing, payment info, bazaar extraction, operation builder) - All framework middlewares (Express, Hono, Fastify, Next.js) auto-register GET /openapi.json, opt-out with openAPIOptions: false - Extract isSingleRouteConfig/normalizeRoutes into @x402/core to deduplicate 7 copies of RoutesConfig discrimination across the codebase Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
248fd12 to
b3df9e2
Compare
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
@x402/core/openapimodule that generates an OpenAPI 3.1.0 spec fromRoutesConfig, includingx-payment-infoon each operation (compatible with agentcash-discovery)GET /openapi.json— zero config for sellers, opt-out withopenAPIOptions: falseisSingleRouteConfig()andnormalizeRoutes()into@x402/core/server, deduplicating 7 copies of theRoutesConfigdiscrimination logic across the codebaseHow it works
The OpenAPI spec is lazily generated from the existing route config on first request. Each operation gets:
x-payment-infowith structured price (fixed/dynamic) andprotocols: [{ x402: {} }]:param→{param}) and bazaar discovery schemasx-guidancesupport ininfofor API-level documentation