merchant: serve OpenAPI spec for x402scan discovery#14
Open
A1igator wants to merge 2 commits into
Open
Conversation
Adds GET /openapi.json to the AI garbage detector merchant so the demo endpoints are discoverable by agents through x402scan. The document follows the x402scan discovery spec: each route declares x-payment-info with fixed USD pricing and an input schema (parameters) so endpoints are classified as invocable, not just visible. Handlers now honor the documented query parameters (?location= on /weather, ?seed= on /garbage) so the spec matches actual behavior. A new optional PUBLIC_URL env populates the OpenAPI servers field for public deployments; otherwise it falls back to the request origin. README adds a short discovery section pointing at /openapi.json and the x402scan registration page.
Two issues surfaced by self-review: 1. Price drift: `paidRoute.accepts[0].price = "$0.01"` and the OpenAPI `x-payment-info.amount = "0.010000"` were two unlinked string literals. A future price bump would touch one and leave the other stale. Extract `PRICE_USD_CENTS` as the single source and derive the display ($0.01) and OpenAPI (0.010000) forms from it. 2. PUBLIC_URL path leak: `@agentcash/discovery` (the package x402scan uses to ingest OpenAPI docs) does `new URL(servers[0].url).pathname` and prepends it to every registered route. So `PUBLIC_URL=https://x.com/api` would silently register `/api/weather` instead of `/weather`. Wrap the resolved URL in a `toOrigin` helper that collapses to `URL.origin` and note the normalization in the README.
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
GET /openapi.jsonto the AI garbage detector merchant so its demo endpoints are discoverable by agents through x402scan.x-payment-info(fixed USD $0.01,protocols: [{ x402: {} }]) and an input schema (parameters) so x402scan classifies them as invocable, not just visible.?location=on/weather,?seed=on/garbage) so the spec matches actual behavior.PUBLIC_URLenv populates the OpenAPIserversfield for public deployments; falls back to the request origin.Why x402scan needs this
x402scan's discovery precedence is OpenAPI first, runtime 402 probe second. Without
/openapi.jsonthe AI garbage detector cannot be listed in the marketplace, and endpoints without an input schema are skipped during registration as non-invocable.Test plan
buildOpenApi("https://example.com")and validate the output against the spec's required fields (openapi,info.title,info.x-guidance,info.version,paths, per-routex-payment-info+responses.402).curl http://localhost:4021/openapi.json | jq(requires the usual.env.merchantsetup).PUBLIC_URLset, submit the deployment URL at https://www.x402scan.com/resources/register and confirm both routes are listed.🤖 Generated with Claude Code