生成 SDK

以 Markdown 格式查看

按照本页面的说明生成 Rust SDK。

1

Install the Fern CLI

$npm install -g fern-api
2

Initialize the fern folder

Initialize the fern folder with your existing OpenAPI specification, or start from scratch with a Fern Definition template. Specify your organization name using the --organization flag.

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

OpenAPI accepts both JSON and YAML formats. You can always convert a Fern Definition to OpenAPI or OpenAPI to a Fern Definition later on.

This creates a fern folder in your current directory.

fern
fern.config.json# root-level configuration
api# your API
generators.yml# generators you're using
openapi
openapi.yml# API-level configuration
3

Validate your API definition

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

$fern check
4

添加 SDK 生成器

运行以下命令将 Rust SDK 生成器添加到 generators.yml

$fern add fern-rust-sdk --group {{GROUP_NAME}}

此命令会将以下 group 添加到 generators.yml

generators.yml
1 rust-sdk: # group name
2 generators:
3 - name: fernapi/fern-rust-sdk
4 version: 0.35.0
5 output:
6 location: local-file-system
7 path: ../sdks/rust
5

生成 SDK

运行以下命令生成您的 SDK:

$fern generate --group rust-sdk

This 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 --group rust-sdk
rust
Cargo.toml
README.md
reference.md
rustfmt.toml
src
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

发布到 crates.io

按照发布到 crates.io 指南配置您的 crate 并通过 GitHub Actions 设置自动化发布。