Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PetStore SDK Generation (Fern)

This repository contains a complete Fern configuration that generates SDKs and a CLI from a single OpenAPI spec. Use it as a template to see how Fern turns an API definition into production-ready, published client libraries.

What gets generated

Every push to main triggers GitHub Actions that call fern generate to produce:

Output Repository Published to
TypeScript SDK petstore-typescript-sdk npm (@fern-api/example-typescript-sdk-petstore)
Rust SDK petstore-rust-sdk crates.io (petstore)
CLI petstore-cli npm (@fern-api/example-cli-petstore)

Additional generators for Python, Go, Java, C#, and Ruby are included in generators.yml as commented-out blocks — uncomment what you need.

Repository structure

fern/
├── openapi.yml          # PetStore OpenAPI 3.0 spec (the source of truth)
├── generators.yml       # Fern generator config — defines which SDKs to generate
└── fern.config.json     # Fern project config (org + CLI version)

.github/workflows/
├── fern-check.yml            # Validates the spec on every PR
├── ts-sdk.yml                # Generates + publishes the TypeScript SDK
├── rust-sdk.yml              # Generates + publishes the Rust SDK
├── cli.yml                   # Generates + publishes the CLI
├── python-sdk.yml.example    # Template — rename to .yml when python-sdk is uncommented
├── go-sdk.yml.example        # Template — rename to .yml when go-sdk is uncommented
├── java-sdk.yml.example      # Template — rename to .yml when java-sdk is uncommented
├── csharp-sdk.yml.example    # Template — rename to .yml when csharp-sdk is uncommented
└── ruby-sdk.yml.example      # Template — rename to .yml when ruby-sdk is uncommented

How it works

  1. Define your API — Write or import an OpenAPI spec into fern/openapi.yml.
  2. Configure generators — In fern/generators.yml, declare which SDKs and CLIs to generate, where to publish them, and which GitHub repos receive the generated code.
  3. Add a workflow — Each generator group needs a GitHub Actions workflow. Workflow templates for every supported language are included in .github/workflows/.
  4. Push to main — GitHub Actions first run a preview generation (fern generate --group <group-name> --preview) and validate the output (build + test), then run the real fern generate to publish.

Note: Generation requires a FERN_TOKEN tied to your Fern organization. The token authenticates with Fern's generation service and controls access to paid features like auto-publishing, pagination, retries, and OAuth support.

Adding a new language

To enable a new SDK (for example, Python):

  1. Uncomment the group in fern/generators.yml:
    python-sdk:
      generators:
        - name: fernapi/fern-python-sdk
          version: 5.14.8
          output:
            location: pypi
            package-name: petstore-sdk
          github:
            repository: your-org/petstore-python-sdk
            mode: release
          config:
            client:
              class_name: PetstoreClient
  2. Update the placeholders — Set your package-name, repository, and client class name.
  3. Create the target GitHub repo (e.g. your-org/petstore-python-sdk) and install the Fern GitHub App on it.
  4. Add FERN_TOKEN — In your config repo's Settings → Secrets, add your Fern token. This is the only secret required — Fern handles registry authentication via OIDC.
  5. Activate the workflow template — Rename .github/workflows/python-sdk.yml.example to python-sdk.yml and add the push trigger so it runs on changes to main:
    on:
      push:
        branches:
          - main
        paths:
          - "fern/openapi.yml"
          - "fern/openapi-overlay.yml"
          - "fern/fern.config.json"
          - "fern/generators.yml"
      workflow_dispatch:
    See ts-sdk.yml for a complete example.
  6. Push to main — The workflow runs automatically.

Use this as a template

  1. Fork this repo (or copy the fern/ folder into your own project).
  2. Replace fern/openapi.yml with your own OpenAPI spec.
  3. Update generators.yml — rename packages, point github.repository to your own repos, and uncomment the languages you want.
  4. Sign up for Fern and generate a token:
    npm install -g fern-api
    fern token
  5. Add FERN_TOKEN as a GitHub Actions secret (Settings → Secrets → Actions). This is the only secret you need — Fern handles registry publishing via OIDC.
  6. Push to main — your SDKs are generated and published automatically.

Local development

Install the Fern CLI:

npm install -g fern-api

Validate the configuration:

fern check

Preview what would be generated (outputs to your local filesystem):

fern generate --group ts-sdk --local

Learn more

About

sample config repo for testing

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors