Skip to content

Generate TypeScript and Python route snippets from openapi.yaml - #461

Open
Naajih09 wants to merge 7 commits into
Divinity-Labs:mainfrom
Naajih09:docs/277-route-snippets
Open

Naajih09 wants to merge 7 commits into
Divinity-Labs:mainfrom
Naajih09:docs/277-route-snippets

Conversation

@Naajih09

Copy link
Copy Markdown

Body:

Closes #277

What this does

Adds a generator that writes TypeScript and Python snippets for each GET route group in openapi.yaml, so the snippets are derived from the spec and cannot drift from it.

  • scripts/gen-snippets.ts: reads openapi.yaml, groups GET routes by path prefix (price, analytics, service), and renders one .ts and one .py file per group under snippets/.
  • tests/snippets.test.ts: checks that the generator is deterministic, that the committed snippet files match a fresh render, and that no snippet contains a placeholder host or address.
  • package.json: adds snippets:gen.

The generator fails the build if a GET route is neither in a group nor listed in SKIPPED, so a new route cannot be dropped silently.

Running the snippets

Each snippet reads its configuration from the environment and fails with a clear message if something is missing:

  • LENS_BASE_URL (required): the live service URL.
  • STELLAR_SECRET (TypeScript, gated routes): a testnet secret key used to sign x402 payments.
  • LENS_X_PAYMENT (Python, gated routes): a pre-signed base64 X-PAYMENT header.
  • LENS_API_KEY (/usage/me): a client API key.

No key, secret, or address is written into any snippet.

Known limits

  • Live base URL. I don't have the public URL. openapi.yaml lists localhost:4000, the README lists localhost:3002, and neither is a live service. I need the maintainers to confirm it before this can be verified end to end.
  • Python x402. The TypeScript gated snippets use @x402/fetch. I haven't confirmed a Python signer, so the Python gated snippets expect a pre-signed LENS_X_PAYMENT header. This is a stopgap.
  • Not run end to end. I haven't executed the generator or the snippets against a live service. The first npm run snippets:gen and npm test may surface errors.
  • Skipped routes. POST and DELETE operations are not generated, because they need request bodies, admin keys, or signed payment payloads. /graphql is skipped because docs/graphql.md covers it.
  • Spec disagreement. The README says /graphql is not payment-gated, and the spec marks its POST as gated. The generator follows the spec. Please confirm which is correct.
  • Network default. The spec defaults network to testnet. Snippets send that default explicitly.

@drips-wave

drips-wave Bot commented Oct 17, 2026

Copy link
Copy Markdown

@Naajih09 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

Miracle656 added a commit that referenced this pull request Oct 22, 2026
  tsc --noEmit   clean
  vitest         99 files, 1140 passing (up from 97 / 1135)
  dropped-tests  none

  #280  close the vulnerabilities that are actually reachable
  #426  keep watched pairs as metric labels, bounded
  #529  GET /price/:asset/fiat for local currency
  #530  standard 429 response contract with retryAfter

#530 pairs well with what landed earlier: #307 standardised empty-vs-missing
status codes, and this does the same for rate limiting. An API that answers
429 without telling a client when to come back forces every consumer to invent
its own backoff, and they will not agree.

#461 (generate TypeScript and Python route snippets from the OpenAPI spec) was
dropped. It fails three of its own tests even after running `npm run
snippets:gen`:

  × render deterministically
  × committed files match the generator
  × contain no placeholder hosts or addresses

The regeneration produced no files at all, so the generator is not doing what
the test expects of it. The third case is the one I care about most -- a
snippet carrying a placeholder address is exactly how an invented contract id
reaches a contributor, which has already cost us a sweep. Worth getting right
rather than merging around.

Claude-Session: https://claude.ai/code/session_01USgemLt4Rnz4SGB1Srf3GB

@Miracle656 Miracle656 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Held — three of this PR's own tests fail, and they still fail after running the generator:

× render deterministically
× committed files match the generator
× contain no placeholder hosts or addresses

I ran npm run snippets:gen on the merged tree and it produced no files at all — git status was clean afterwards. So either the generator is not writing where the test looks, or it is exiting before it writes. Worth checking that first; the other two failures may well fall out of it.

The third case is the one I would fix even if the others were passing. A snippet that ships a placeholder host or address is precisely how an invented contract id reaches a contributor — a previous issue batch of ours shortened one contract id and five people invented their own to fill the gap, which cost a full review sweep to untangle. A generated snippet is worse again, because it looks authoritative and people paste it.

So: every address in a generated snippet should be either a real, full, 56-character value from the spec, or so obviously fake that nobody could mistake it for one. Nothing in between.

The idea is good and I want it — a client snippet that cannot drift from the spec is worth having, and it pairs with #403's generated TypeScript client. Get the generator writing and the three tests green and I will take it.

@Naajih09

Naajih09 commented Oct 23, 2026 •

Copy link
Copy Markdown
Author

@Miracle656
Thanks for the detailed review. The generator was failing on unlisted routes and missing spec examples, so I fixed both:

  • Every GET route is now in a snippet group or in SKIPPED with a reason. /venues/registry and /snapshot are in service; /live and /ready are skipped as orchestrator probes.
  • Every path parameter in openapi.yaml has an example, so snippets no longer rely on guessed values.
  • The truncated USDC:GBBD47... example on POST /pairs is now the full issuer.
  • openapi.json is regenerated to match the spec.
  • The only addresses in the generated snippets are full 56-character values from the spec. No placeholder hosts.

npm test passes (911 tests, one pre-existing skip). The generator now writes the snippet files.
image

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.

Route code snippets exist in no language but curl

2 participants