Camunda OpenAPI Schema Bundler
The camunda-schema-bundler is a utility designed to process and normalize the multi-file Camunda OpenAPI specification into a single, clean JSON file suitable for code generation. It addresses several common issues encountered with naive OpenAPI bundling, such as resolving path-local `$ref`s, ensuring all component schemas are included, correcting URI-encoded references (e.g., `%24like` instead of `$like`), and preventing inline duplicates of schemas by converting them to proper `#/components/schemas/...` references. Beyond the bundled spec, it also extracts structured metadata and an endpoint map, tracing operations back to their source files. The current stable version is 1.7.0, with minor releases occurring frequently, typically monthly, to introduce features like support for `x-semantic-provider` and `x-deprecated-enum-members`, and to fix bugs. It serves as a crucial pre-processing step for official Camunda SDKs in various languages, including TypeScript, C#, and Python.
Common errors
-
Error: Node.js v16.x.x is not supported. Please use Node.js v18 or higher.
cause The package's `engines` constraint prevents it from running on Node.js versions older than 18.fixUpgrade your Node.js environment to version 18 or higher. For example, using `nvm install 18 && nvm use 18`. -
ReferenceError: require is not defined in ES module scope
cause Attempting to use CommonJS `require()` syntax in an ES Module environment when `camunda-schema-bundler` is an ESM-first library.fixChange your import statements to use ES Module syntax: `import { bundle } from 'camunda-schema-bundler';` Ensure your `package.json` has `"type": "module"` or your file uses `.mjs` extension. -
Error: Not found: https://github.com/camunda/camunda-platform-7-rest-api/tree/invalid-branch
cause The specified `--ref` (or `ref` in programmatic options) for fetching the upstream OpenAPI specification does not exist in the repository.fixVerify the Git branch, tag, or SHA provided for `--ref` (or `ref`) is correct and exists in the target GitHub repository. Common issues include typos or using a deprecated branch name.
Warnings
- breaking The package requires Node.js version 18 or higher. Running with older Node.js versions will result in runtime errors or failures.
- gotcha Older versions (prior to v1.3.3) had a bug (`fix deduplication leading to collapsed schemas`) that could result in incorrect or collapsed schemas in the bundled output, potentially leading to data loss or incorrect interpretations by downstream generators.
- gotcha When bundling for generators that expect path-local dereferenced schemas (e.g., C# / Microsoft.OpenApi), you must enable the `--deref-path-local` CLI option or its programmatic equivalent in the `bundle` function to avoid unresolvable references.
Install
-
npm install camunda-schema-bundler -
yarn add camunda-schema-bundler -
pnpm add camunda-schema-bundler
Imports
- bundle
const bundle = require('camunda-schema-bundler');import { bundle } from 'camunda-schema-bundler'; - BundleOptions
import type { BundleOptions } from 'camunda-schema-bundler'; - cli
import { cli } from 'camunda-schema-bundler';
Quickstart
import { bundle } from 'camunda-schema-bundler';
import * as fs from 'node:fs/promises';
import * as path from 'node:path';
async function runBundler() {
const outputDir = path.join(process.cwd(), 'bundled-spec');
await fs.mkdir(outputDir, { recursive: true });
console.log('Starting Camunda schema bundling...');
try {
await bundle({
fetch: true, // Fetch the latest spec from GitHub (default: main branch)
outputSpec: path.join(outputDir, 'rest-api.bundle.json'),
outputMetadata: path.join(outputDir, 'spec-metadata.json'),
outputEndpointMap: path.join(outputDir, 'endpoint-map.json'),
ref: process.env.CAMUNDA_SCHEMA_REF ?? 'main', // Use 'main' or specify a tag/branch like 'stable/8.8'
repoUrl: process.env.CAMUNDA_SCHEMA_REPO ?? 'https://github.com/camunda/camunda-platform-7-rest-api',
});
console.log(`Bundling completed successfully. Output files generated in ${outputDir}`);
} catch (error) {
console.error('Error during bundling:', error);
process.exit(1);
}
}
runBundler();