Skip to content
Last updated

Generating an API Client

Use OpenAPI Generator to scaffold a typed, ready-to-use client from the Bookable Bookings API spec. This removes the need to hand-write HTTP calls, models, or serialization logic.


Prerequisites

OpenAPI Generator requires Java 11+ to run. Install it once, then use either the CLI wrapper or the npx approach — no permanent global install needed.

# Check Java version
java -version

Install the CLI wrapper via npm (recommended for Node-based projects):

npm install @openapitools/openapi-generator-cli --save-dev

Or run it on-demand without installing:

npx @openapitools/openapi-generator-cli version

Download the spec

curl -O https://bookable.redocly.app/_spec/apis/BookingApi.yml

Or reference it directly in the generate command using the URL — no local copy needed.


Generate a client

Run generate with the target language generator, the spec file, and an output directory.

npx @openapitools/openapi-generator-cli generate \
  -i BookingApi.yml \
  -g typescript-fetch \
  -o ./src/bookable-client \
  --additional-properties=supportsES6=true,npmName=bookable-client

Replace BookingApi.yml with the remote URL https://bookable.redocly.app/_spec/apis/BookingApi.yml to always generate from the latest published spec.


Configure the generated client

The generated client defaults to the base URL defined in the spec. Override it at runtime and inject the OAuth token before making requests.

import { Configuration, BookingsApi } from './src/bookable-client';

const config = new Configuration({
  basePath: 'https://api-sandbox.bookabletech.com', // or https://api.bookabletech.com
  accessToken: async () => {
    // Return a valid Bearer token — fetch from your token store or refresh if needed
    return myTokenStore.getAccessToken();
  },
});

const api = new BookingsApi(config);

const availability = await api.getAvailability({
  operatorId: 'op_123',
  date: '2026-06-15',
  partySize: 2,
});

Token management

The generated client does not handle token refresh automatically. Use a wrapper or middleware to fetch a token via the OAuth client credentials flow before each request, or cache it and refresh when it is about to expire.

See Authentication for the full token endpoint and request format.


Pinning the generator version

To ensure reproducible builds, pin the generator version in your project config:

// openapitools.json (created automatically on first run)
{
  "$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json",
  "spaces": 2,
  "generator-cli": {
    "version": "7.10.0"
  }
}

Run npx @openapitools/openapi-generator-cli version-manager list to see available versions.


Available generators

OpenAPI Generator supports 50+ languages and frameworks. Run the following to list all options:

npx @openapitools/openapi-generator-cli list

Common choices for Bookable integrations:

GeneratorOutput
typescript-fetchTypeScript with native fetch
typescript-axiosTypeScript with Axios
javascriptPlain JavaScript (CommonJS)
pythonPython (requests)
javaJava (OkHttp + Gson)
csharpC# (.NET)
goGo
rubyRuby
phpPHP