Quickstart

Beta
View as Markdown
Early access

The CLI generator is in early access. Reach out to get started.

This guide walks through generating a CLI from an OpenAPI spec and running it via Fern’s cloud generation. By the end you will have a compiled binary that maps every API endpoint to a subcommand, with authentication, output formatting, and pagination wired up from your spec.

Generate a CLI
Generate a CLI from an OpenAPI specification with Fern. Follow the [CLI Generator quickstart](https://buildwithfern.com/learn/cli-generator/get-started/quickstart.md) step by step.

To generate entirely on your own machine without sending your spec to Fern, run generation locally with --local.

Prerequisites

  • Fern CLI v5.37.9 or later (npm install -g fern-api)
  • Rust toolchain (stable)
  • An OpenAPI 3.x spec with at least one endpoint

Setup

1

Initialize a Fern project

$mkdir my-api-config && cd my-api-config
$fern init --organization my-org

This creates a fern/ directory containing the default configuration files.

2

Add your OpenAPI spec

Place your spec at fern/openapi.yml (or any path you reference in the next step). The spec must include at least one path, and any securitySchemes declared under components become the credentials the CLI reads at runtime.

3

Configure the generator

Replace the contents of fern/generators.yml:

fern/generators.yml
1api:
2 specs:
3 - openapi: openapi.yml
4default-group: cli
5groups:
6 cli:
7 generators:go
8 - name: fern-cli-generator
9 version: 0.23.4
10 output:
11 location: local-file-system
12 path: ../my-cli
13 config:
14 binaryName: my-cli

The path is relative to the fern/ directory, so this writes the generated Rust project to a sibling my-cli/ directory. To ship the CLI to npm, Homebrew, or GitHub Releases instead of building it locally, configure a publishing target.

4

Generate the CLI

$fern generate --group cli

Fern reads the OpenAPI spec, runs the CLI generator, and writes a complete Rust project to the output path.

5

Build and run

$cd ../my-cli
$cargo build
$./target/debug/my-cli --help

The --help output shows the full command tree: top-level commands derived from OpenAPI tags, subcommands from individual operations, and built-in utilities like completion and man.

6

Customize the output

  • Rename commands, hide endpoints, or patch metadata without forking your spec by layering overrides and overlays onto generators.yml.
  • Ship one binary that drives multiple APIs by listing them under api.specs with multi-spec merging.
  • Add subcommands that don’t map to an endpoint — login flows, config helpers, local utilities — with custom commands.

Next steps