Skip to content

fix(discovery): prefer the advisory whose method matches the declared OpenAPI method#933

Open
craigbidenbot[bot] wants to merge 1 commit into
mainfrom
craig/fix-probe-prefer-declared-method
Open

fix(discovery): prefer the advisory whose method matches the declared OpenAPI method#933
craigbidenbot[bot] wants to merge 1 commit into
mainfrom
craig/fix-probe-prefer-declared-method

Conversation

@craigbidenbot
Copy link
Copy Markdown
Contributor

@craigbidenbot craigbidenbot Bot commented May 28, 2026

Summary

pickX402Advisory was picking the most-preferred-by-method advisory (POST > GET > …), then rewriting .method to whatever the OpenAPI spec declared. When the payment middleware on a merchant API fires before method routing, the probe gets a 402 for every HTTP method — but only the declared method's advisory carries the per-method inputSchema extracted from the spec. The rewrite preserved the registered method but silently dropped the schema, surfacing as "Missing input schema" on registration.

Now: when a declared method is supplied AND an advisory matches it exactly, return that advisory unchanged. Only fall back to the preferred-method-then-rewrite path when no advisory matches.

Closes #923.

Changes

  • apps/scan/src/lib/discovery/probe.ts: pickX402Advisory now short-circuits on direct method match before falling back to method preference. Case-insensitive match on preferredMethod.
  • apps/scan/src/lib/discovery/probe.test.ts (new): 7 unit tests covering empty discovery, no x402 candidates, method-preference path, the GoldBean regression case (#923), case-insensitive match, and the no-matching-advisory fallback.

Repro (issue #923)

GoldBean API (https://goldbean-api.xyz) declares 120 GET /paid/* endpoints. Their payment middleware 402s on every HTTP method, so the probe yields advisories for both GET (with inputSchema from the spec's query parameters) and POST (no schema — no POST in the spec).

Before: pickX402Advisory picks POST (method preference), rewrites .method → "GET", and the GET advisory's schema is lost. Registration fails with Missing input schema on the 89 endpoints with no x402-bazaar input block.

After: matching advisory wins, schema survives, endpoints register cleanly.

Test Plan

  • pnpm --filter @x402scan/app test:run src/lib/discovery/probe.test.ts — 7/7 pass
  • pnpm --filter @x402scan/app test:run — 117/117 pass (no regressions)
  • pnpm format:check:dir apps/scan/src/lib/discovery/probe*.ts — clean
  • pnpm --filter @x402scan/app lint:fix apps/scan/src/lib/discovery/probe*.ts — clean
  • Pre-existing type errors on main (route typing, missing @signinwithethereum/siwe) confirmed unrelated to this change

After merge, recommend re-running batchTest against goldbean-api.xyz to clear out the 89 stale failures.

… OpenAPI method

When the payment middleware fires before HTTP method routing, the probe
yields a 402 for every method — but only one method is declared in the
OpenAPI spec, and only that method's advisory carries the per-method
`inputSchema` extracted from the spec.

`pickX402Advisory` was picking the most-preferred-by-method advisory
(POST > GET > …), then rewriting `.method` to whatever the spec
declared. That preserved the registered method but silently dropped the
schema, surfacing as 'Missing input schema' on registration.

Now: when a declared method is supplied AND an advisory matches it
exactly, return that advisory unchanged. Only fall back to the
preferred-method-then-rewrite path when no advisory matches.

Repro: see x402scan#923 (GoldBean — 89 of 120 GET-only endpoints registered
without their query-parameter schema).
@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented May 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
x402scan Ready Ready Preview, Comment May 28, 2026 11:09am

Request Review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GoldBean API (goldbean-api.xyz) — 120 endpoints fail batchTest after successful discovery

0 participants