feat: Allow uploading OpenAPI spec to register x402 resources (#97)#795
Open
tarai-dl wants to merge 1 commit into
Open
feat: Allow uploading OpenAPI spec to register x402 resources (#97)#795tarai-dl wants to merge 1 commit into
tarai-dl wants to merge 1 commit into
Conversation
Adds ability to register x402 resources from an OpenAPI specification with x-402 extensions, as an alternative to probing endpoints. - New API endpoint: POST /api/x402/registry/register-openapi Accepts an OpenAPI spec (JSON) with x-402 extensions and registers all matching endpoints as x402 resources. - New UI: OpenAPI Spec tab on the register page Users can paste or upload an OpenAPI spec file, preview detected endpoints, and register them in bulk. - Supports x-402 and x402 extension fields on operations - Extracts input/output schemas from OpenAPI parameters and requestBody - Docs: Example OpenAPI spec with x-402 extensions Implements Merit-Systems#97
Contributor
|
Someone is attempting to deploy a commit to the Merit Systems Team on Vercel. A member of the Team first needs to authorize it. |
| @@ -1,40 +1,64 @@ | |||
| import { Body, Heading } from '@/app/_components/layout/page-utils'; | |||
| import Link from 'next/link'; | |||
| 'use client'; | |||
Contributor
| const op = operation as OpenApiOperation; | ||
| const x402Config = op['x-402'] ?? op['x402']; | ||
|
|
||
| if (!x402Config?.enabled && !x402Config?.paymentRequirements) continue; |
Contributor
There was a problem hiding this comment.
| if (method.startsWith('x-') || method === 'parameters') continue; | ||
| const operation = op as Record<string, unknown>; | ||
| const x402 = operation['x-402'] ?? operation['x402']; | ||
| if (x402) { |
Contributor
There was a problem hiding this comment.
Suggested change
| if (x402) { | |
| const x402Config = x402 as Record<string, unknown> | undefined; | |
| if (x402Config?.enabled || x402Config?.paymentRequirements) { |
Form preview and registration handler have inconsistent filtering logic for x-402 endpoints, causing disabled endpoints to appear in preview but fail during registration
| const paymentOption = { | ||
| protocol: 'x402' as const, | ||
| scheme: 'exact' as const, | ||
| network: price.network ?? 'base', |
Contributor
| network: price.network ?? 'base', | ||
| amount: String(price.amount ?? '0'), | ||
| maxAmountRequired: String(price.amount ?? '0'), | ||
| payTo: '', |
Contributor
Comment on lines
+81
to
+83
| const fullUrl = serverUrl | ||
| ? `${serverUrl.replace(/\/$/, '')}${path}` | ||
| : path; |
Contributor
There was a problem hiding this comment.
Suggested change
| const fullUrl = serverUrl | |
| ? `${serverUrl.replace(/\/$/, '')}${path}` | |
| : path; | |
| // Ensure path starts with / for correct URL construction | |
| const normalizedPath = path.startsWith('/') ? path : `/${path}`; | |
| const fullUrl = serverUrl | |
| ? `${serverUrl.replace(/\/$/, '')}${normalizedPath}` | |
| : normalizedPath; |
URL concatenation assumes paths always start with /, causing malformed URLs when a path lacks the leading slash
| 'Register x402 resources from an OpenAPI specification with x-402 extensions' | ||
| ) | ||
| .handler(({ body }) => | ||
| handleRegistryRegisterOpenApi(body.spec as string, body.baseUrl) |
Contributor
| @@ -0,0 +1,270 @@ | |||
| import { jsonResponse } from '@/app/api/x402/_lib/utils'; | |||
| import { registerResource } from '@/lib/resources'; | |||
| import { convertOpenApiSchemaToV1 } from '@/lib/openapi-to-v1'; | |||
Contributor
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
This PR implements the ability to register x402 resources from an OpenAPI specification with
x-402extensions, as an alternative to probing endpoints directly.Closes #97
Changes
New API Endpoint
/api/x402/registry/register-openapix-402extensionsbaseUrlparameter to override the spec's servers arrayNew UI Component
.json,.yaml,.ymlfilesOpenAPI Parsing
x-402orx402extension fieldsenabled,price.amount,price.network,price.assetfieldsHow to Use
Add
x-402extensions to your OpenAPI spec operations:{ "paths": { "/api/premium-data": { "post": { "x-402": { "enabled": true, "price": { "amount": "1000", "network": "base" } }, "requestBody": { ... }, "responses": { ... } } } } }See
docs/examples/openapi-x402-example.jsonfor a complete example.Test Plan
Relates to Algora bounty #97 ($100)