快速开始

以 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. 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

生成

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 的信息。