快速开始

以 Markdown 格式查看

在 5 分钟内快速上手 Fern。本快速开始指南将引导您安装 CLI、初始化项目并在本地生成您的第一个 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

生成

fern init 默认包含一个 TypeScript SDK 生成器。运行 fern generate 来查看它的运行效果:

$fern generate

这会创建一个包含您生成的 SDK 的 sdks/typescript 文件夹:

fern# 由 fern init 创建
sdks# 由 fern generate 创建
typescript
Client.ts
index.ts
core
api

下一步

现在您已经有了一个可工作的 SDK,可以设置 GitHub 仓库并配置发布、生成其他语言的 SDK,或了解更多关于 Fern SDK 的信息。