生成 SDK

以 Markdown 格式查看

按照此页面上的说明生成 TypeScript SDK。

已经完成了 快速开始?跳转到 设置 GitHub 仓库

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
generators.yml# generators and API spec configuration
3

Validate your API definition

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

$fern check
4

生成 SDK

fern init 默认包含 TypeScript SDK 生成器,因此您可以立即生成:

$fern generate

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# 由 fern init 创建
sdks# 由 fern generate 创建
typescript
Client.ts
index.ts
errors
core
api
5

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-typescript-sdk).
  3. Install the Fern GitHub App on both repositories.
6

发布到 npm

按照 发布到 npm 指南来配置您的包并通过 GitHub Actions 设置自动发布。