OrbitDocs packages are coming to npm soon. Until then, run it from the GitHub repo →
SDKs, mock & lint

SDKs

Generate client SDKs in TypeScript, Python, Go, Java, C# and PHP from your API spec, and keep your own code when you regenerate.

orbitdocs sdk generates a client library for your API in up to six languages, from the spec OrbitDocs extracted from your Nest app. Each SDK gets code samples in your API reference. Your own additions to an SDK survive every regeneration.

This section also covers the mock server and spec linting:

Generate your first SDK

Configure the languages

Add an sdks section with one entry per language:

orbitdocs.config.ts
import { defineConfig } from '@orbitdocs/next/config';

export default defineConfig({
  site: { title: 'Acme' },
  apis: [{ id: 'travel', source: { nest: { module: 'dist/app.module.js', build: 'nest build' } } }],
  sdks: {
    typescript: { package: '@acme/sdk' },
    python: { package: 'acme_sdk' },
    go: { module: 'github.com/acme/acme-go' },
    java: { groupId: 'com.acme', artifactId: 'acme-sdk', package: 'com.acme.sdk' },
    csharp: { package: 'Acme.Sdk' },
    php: { namespace: 'Acme\\Sdk', package: 'acme/sdk' },
  },
});

Extract the spec

npx orbitdocs extract

orbitdocs sdk reads openapi/<api>.json and doesn't extract it for you.

Generate

npx orbitdocs sdk                          # every configured language, every API
npx orbitdocs sdk --lang typescript,python # only these languages
npx orbitdocs sdk --api travel             # only this API

Each SDK is written to sdks/<api>/<language>/, relative to the docs app. The command also writes .orbitdocs/sdk-samples.json, the code samples for the reference.

Languages

LanguageGeneratorNeeds
TypeScriptHey API (@hey-api/openapi-ts): a fetch client with typed functions, no runtime dependencyNode only
Python, Go, Java, C#, PHPOpenAPI GeneratorJava 11 or later on PATH

Both generators ship with the OrbitDocs CLI. If Java is missing, the command fails with openapi-generator failed for <lang> (it needs Java 11 or later on PATH).

Settings per language

LanguageRequiredOptionalPassed to the generator as
typescriptpackage (npm name)version (default 0.1.0), outpackage.json name and version
pythonpackage (import name)project (default: package with _ → -), version, outpackageName, projectName, packageVersion
gomodule (github.com/acme/acme-go)package (default: last part of the module, letters and digits only), version, outpackageName, packageVersion; git host, user and repo from module
javagroupId, artifactId, packageversion, outgroupId, artifactId, artifactVersion, invokerPackage; APIs in <package>.api, models in <package>.model; native HTTP client
csharppackageversion, outpackageName, packageVersion; targets net8.0
phpnamespacepackage (Composer name), version, outinvokerPackage, composerPackageName, artifactVersion

out is a folder relative to the docs app. It replaces sdks/<api>/<language>.

Several APIs

Each API gets its own SDK. Without out, they go to sdks/<api>/<language>. With out, write {api} where the API id goes; without {api} and with more than one API, each API gets a subfolder of out (<out>/<api>), so no SDK overwrites another. One API uses out as written.

{api} also works in package names, so each API's SDK has its own name. In Python, Java and Go packages and PHP namespaces a - in the id becomes _.

orbitdocs.config.ts
sdks: {
  typescript: { package: '@acme/{api}-sdk', out: 'packages/{api}-sdk' },
  python: { package: 'acme_{api}' },
},

orbitdocs sdk warns when several APIs would share one package name. The reference's code samples (.orbitdocs/sdk-samples.json) are kept per API, each from that API's SDK.

Keep your own code

Regeneration rewrites generated code only. Where your code is safe depends on the language.

TypeScript

sdks/travel/typescript/
├── package.json        written once, then yours
├── tsconfig.json       written once, then yours
├── README.md           written once, then yours
└── src/
    ├── index.ts        written once, then yours (re-exports generated/)
    └── generated/      deleted and rewritten on every run

Add helpers next to src/generated/ and export them from src/index.ts. The package builds with npm run build (tsup) to dist/.

sdks/travel/typescript/src/index.ts
export * from './generated';
export { client } from './generated/client.gen';

// Yours: survives regeneration.
export { withRetry } from './retry';

Python, Go, Java, C# and PHP

OpenAPI Generator writes the whole folder, except the files listed in .openapi-generator-ignore. OrbitDocs creates that file on the first run with:

.openapi-generator-ignore
# Files OrbitDocs never overwrites when it regenerates this SDK.
CHANGELOG.md
custom/**
.github/**
.gitlab-ci.yml
LICENSE

Put your own code in custom/, or add your own paths to the file. OrbitDocs never rewrites it after the first run.

OrbitDocs generates code. It doesn't version, publish or release SDKs to npm, PyPI or other registries. Commit the sdks/ folder and publish from your own pipeline.

Options

Prop

Type

orbitdocs sdk flags

FlagDefault
--lang <languages>every configured languageComma-separated: typescript,python,go,java,csharp,php. Each must be configured.
--api <id>every API in sdks.apisGenerate for one API.
--workflow <github|gitlab>Write a CI workflow instead of generating. See Regenerate in CI.
test (argument)Run the contract tests. See SDK contract tests.

Next steps

Last updated on

On this page