Skip to content

Latest commit

 

History

History
56 lines (40 loc) · 1.89 KB

File metadata and controls

56 lines (40 loc) · 1.89 KB

Publishing Output (Client SDK / Server)

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.

Synchronizing Output

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.

Example .github/workflows/sync-sdk.yml

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'

Publishing the Generated Client

The output generated by from_openapi to_sdk provides a package.json scaffolding if --no-installable-package is not passed.

  1. Change directory to the output.
  2. Ensure versioning matches standard semantic versioning practices.
  3. Transpile if necessary (npm run build or tsc).
  4. Publish exactly as you publish any other TS package (npm publish).