zklighter-perps
v1.0.269
Published
Lighter Perps SDK
Readme
zklighter-perps-ts
Auto-generated TypeScript SDK for the Lighter Perps API, published to npm as
zklighter-perps.
The SDK source (index.ts, runtime.ts, apis/, models/) is generated by
the OpenAPI Generator from the backend's
OpenAPI spec. Do not edit the generated files by hand — they are overwritten on
every regeneration. The package ships raw .ts ("main": "index.ts"), so
consumers compile it themselves.
Generation pipeline (CircleCI)
Defined in .circleci/config.yml. The update_ts_sdk
workflow (manually triggered) runs three jobs in sequence:
update_openapi— cloneszklighter-perps, runsgoctl-swaggerto emit the rawopenapi.json, and persists it. This job no longer transforms the spec; it only generates and persists it.openapi_postprocess— runs.circleci/openapi_postprocess.py, the single source of truth for all spec fixups (see below).update_ts_sdk— runs the OpenAPI Generator on the post-processed spec, bumps the package version, and opens a PR.
The update_npm_package workflow runs on main:
typecheck—npm install && npm run typecheck(tsc --noEmitusingtsconfig.json). Runs on every branch, including the timestamped branches opened byupdate_ts_sdk, so a regenerated SDK that would fail to compile in a consumer (e.g.perps-fe) is caught on its PR.update_npm_package— publishes to npm (requirestypecheckto pass).
OpenAPI post-processing
The spec emitted by goctl-swagger has quirks that either break the OpenAPI
Generator or produce an awkward SDK, so we post-process it before generation.
All of this lives in one place — .circleci/openapi_postprocess.py.
(Historically some of these fixes were inline jq/sed commands in the
update_openapi job; they have been consolidated into the script so the logic
is in a single, testable file.)
Why each transform exists:
- Drop internal endpoints/definitions (
/api/v1/feedback,/api/v1/ws_status,/stream,/api/v1/permission,ReqSendFeedback) — not part of the public SDK surface. - Strip empty-string keys — the generator emits
""keys the OpenAPI Generator cannot process. - Mirror
summaryintodescription— preserves the original human-readable text as the generated doc comment beforesummaryis overwritten in step 8. - Seed
summaryfromoperationId— normalizes naming before step 8. - Add a documented
400response referencingResultCodeto every operation, so the SDK models the standard error shape. - Model the
typesparameter as a byte array (arrayofuint8) instead of the non-standard scalar the spec declares. - Remove placeholder
"-"enum/array values that aren't real values. - Derive stable, path-based
operationId/summary(e.g./api/v1/account→account) so generated method names are predictable. - Inline non-standard
int16/map$refs (int16,mapint16string,mapstringfloat64) — these are not standard OpenAPI and make the generator emit broken model references. - Move array-level
enumintoitems— correct placement for array schemas. - Make the
transfer/historytypeparam an array of enum strings. - Trim over-eager
requiredfields — the backend marks fields required that are actually optional in responses; we relax them so deserialization doesn't reject valid payloads.
Local development
npm install # installs TypeScript (the only dependency)
npm run typecheck # same check CI runs: tsc --noEmitTo test the post-processing script against a spec locally, place an
openapi.json next to the script and run python3 openapi_postprocess.py
(it reads/writes ./openapi.json).
