This document shows how to publish the output of the cdd-ts compiler (the generated client library, models, and server) and how to keep them synchronized with an upstream OpenAPI definition.
To automatically keep the client library up-to-date with your backend server's OpenAPI spec, you should set up a GitHub Actions cron job.
Create a file in your target output repository:
name: Sync SDK
on:
schedule:
- cron: '0 0 * * *' # Run daily at midnight
workflow_dispatch: # Allow manual trigger
jobs:
update-sdk:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: 18
- name: Install cdd-ts
run: npm install -g cdd-ts
- name: Download Latest OpenAPI Spec
run: curl -s https://api.my-backend.com/openapi.yaml -o openapi.yaml
- name: Generate SDK
run: cdd-ts from_openapi to_sdk -i openapi.yaml -o ./src/api --framework fetch
- name: Create Pull Request if changes detected
uses: peter-evans/create-pull-request@v5
with:
title: 'chore: update SDK based on latest OpenAPI'
branch: 'update-sdk'
commit-message: 'Update SDK with latest OpenAPI spec'The output generated by from_openapi to_sdk provides a package.json scaffolding if --no-installable-package is not passed.
- Change directory to the output.
- Ensure versioning matches standard semantic versioning practices.
- Transpile if necessary (
npm run buildortsc). - Publish exactly as you publish any other TS package (
npm publish).