Skip to navigation

Generating an SDK

View as Markdown
Enterprise feature

This feature is available only for the Enterprise plan. To get started, reach out to support@buildwithfern.com.

Generate a Rust SDK by following the instructions on this page.

Generate a Rust SDK
Generate a Rust SDK with Fern. Follow the [Rust SDK quickstart](https://buildwithfern.com/learn/sdks/generators/rust/quickstart.md) step by step.
1

Install the Fern CLI

npm install -g fern-api
2

Initialize the fern folder

Initialize the fern folder with your existing OpenAPI specification. Specify your organization name using the --organization flag.

fern init --openapi path/to/openapi.yml \
--organization <YourOrganization>

OpenAPI accepts both JSON and YAML formats.

This creates a fern folder in your current directory.

fern
fern.config.json# root-level configuration
sdk-config.yml# SDK targets and API spec configuration
openapi.yml# copy of a local spec
3

Validate your API definition

Check that your API definition is valid, and fix errors before proceeding:

fern check
4

Add the SDK target

Add a Rust target to the targets list in sdk-config.yml:

sdk-config.yml
targets:
- language: rust
output:
delivery: files
path: ../sdks/rust

The target uses the newest supported Rust generator. To pin a version, set generatorVersion on the target.

5

Generate the SDK

Run the following command to generate your SDK:

fern generate --target rust

The first time you run fern generate, you must log in. Confirm the prompt and choose any of the login methods to authenticate, then generation continues automatically.

fern generate creates a sdks folder in your current directory. The resulting folder structure looks like this:

fern# created by fern init
sdks# created by fern generate --target rust
rust
Cargo.toml
README.md
reference.md
rustfmt.toml
src

SDK users import src/prelude.rs with use your_crate::prelude::*;. The prelude re-exports the client, request and response types, and StreamExt for iterating server-sent event streams and paginated responses.

6

Set up GitHub repositories

Fern uses a multi-repo structure: your source repository contains the fern/ folder, and each SDK gets its own separate repository.

  1. Create a source repository for your fern/ folder if you don’t have one already (e.g., your-org/your-api-definitions).
  2. Create an SDK repository for your SDK (e.g., your-org/your-api-rust-sdk).
  3. Install the Fern GitHub App on both repositories.
7

Publish to crates.io

Follow the Publishing to crates.io guide to configure your crate and set up automated publishing via GitHub Actions.