Skip to content

feat: auto-serve OpenAPI spec at /openapi.json for x402 resource servers#1965

Open
zdql wants to merge 3 commits intox402-foundation:mainfrom
zdql:feat/openapi-auto-hosting
Open

feat: auto-serve OpenAPI spec at /openapi.json for x402 resource servers#1965
zdql wants to merge 3 commits intox402-foundation:mainfrom
zdql:feat/openapi-auto-hosting

Conversation

@zdql
Copy link
Copy Markdown
Contributor

@zdql zdql commented Apr 8, 2026

Summary

  • Adds a new @x402/core/openapi module that generates an OpenAPI 3.1.0 spec from RoutesConfig, including x-payment-info on each operation (compatible with agentcash-discovery)
  • All framework middlewares (Express, Hono, Fastify, Next.js) now auto-register GET /openapi.json — zero config for sellers, opt-out with openAPIOptions: false
  • Extracts isSingleRouteConfig() and normalizeRoutes() into @x402/core/server, deduplicating 7 copies of the RoutesConfig discrimination logic across the codebase

How it works

The OpenAPI spec is lazily generated from the existing route config on first request. Each operation gets:

  • x-payment-info with structured price (fixed/dynamic) and protocols: [{ x402: {} }]
  • Parameters extracted from route patterns (:param{param}) and bazaar discovery schemas
  • Response schemas from bazaar discovery extension declarations
  • x-guidance support in info for API-level documentation

@github-actions github-actions bot added typescript sdk Changes to core v2 packages labels Apr 8, 2026
zdql and others added 2 commits April 8, 2026 13:32
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>
@zdql zdql force-pushed the feat/openapi-auto-hosting branch from 248fd12 to b3df9e2 Compare April 8, 2026 17:32
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

sdk Changes to core v2 packages typescript

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant