TypeScript Client Generation#

Scope: advanced template API surface. This guide consumes REST/RPC endpoints generated by the advanced template — it is not a client for the pgmi deployment CLI.

Generate TypeScript types and a fetch-based client from your deployment’s /openapi.json. Download openapi.json with session handles first; see Client generation .

openapi-typescript (types only)#

Generates TypeScript types from the spec. Pair with openapi-fetch for a typed fetch wrapper.

npx openapi-typescript openapi.json -o src/api.d.ts

Use the types with openapi-fetch:

import createClient from "openapi-fetch";
import type { paths } from "./api";

// The transport's cookie carries the login session; the tab sends its organization session.
const client = createClient<paths>({
  baseUrl: "http://localhost:8080/api",
  credentials: "include",
  headers: { "x-organization-session": organizationSession },
});

const { data, error } = await client.GET("/hello", {
  params: { query: { name: "World" } },
});

openapi-generator (full client)#

Generates a complete client with models and API classes:

npx @openapitools/openapi-generator-cli generate \
  -i openapi.json \
  -g typescript-fetch \
  -o src/generated

CI Integration#

Add to your build pipeline so the client stays in sync with the spec:

# GitHub Actions example
- run: |
    curl -fsS -H "Cookie: __Host-session=$LOGIN_SESSION" -H "x-organization-session: $ORGANIZATION_SESSION" \
      -o openapi.json "$API_URL/openapi.json"
    npx openapi-typescript openapi.json -o src/api.d.ts
  env:
    API_URL: ${{ vars.API_URL }}
    LOGIN_SESSION: ${{ secrets.LOGIN_SESSION }}
    ORGANIZATION_SESSION: ${{ secrets.ORGANIZATION_SESSION }}