Fern 定义中的受众

在 Fern 定义中使用受众来为不同的 API 消费者群体进行分段。

以 Markdown 格式查看
团队版和企业版功能

此功能仅适用于团队版和企业版计划。要开始使用,请联系 support@buildwithfern.com

受众是一个用于为不同消费者分段 API 的有用工具。您可以配置 Fern Docs 来发布特定于某个受众的文档。您也可以在 OpenAPI 规范中使用受众

受众的常见示例包括:

  • 内部消费者(例如,使用 API 的前端开发人员)
  • Beta 测试者
  • 客户

默认情况下,如果没有指定受众,所有消费者都可以访问。

配置

Fern 定义具有为不同端点、类型和属性标记不同受众的一级概念。

要在 Fern 定义中使用受众,请将其添加到 api.yml 中。

在下面的示例中,我们为 internalbetacustomer 群体创建了受众:

api.yml
1name: api
2audiences:
3 - internal
4 - beta
5 - customers

端点受众

要为特定消费者标记端点,请添加包含相关群体的 audience

在此示例中,sendEmail 端点仅对内部消费者可用:

user.yml
1service:
2 base-path: /users
3 auth: true
4 endpoints:
5 sendEmail:
6 audiences:
7 - internal
8 path: /send-email
9 ...

类型受众

类型也可以为不同受众进行标记。

在此示例中,Email 类型对内部和 beta 消费者可用:

user.yml
1Email:
2 properties:
3 subject: string
4 body: optional<string>
5 audiences:
6 - internal
7 - beta

属性受众

类型的属性也可以为不同受众进行标记。

在此示例中,to 属性仅对 beta 消费者可用:

user.yml
1Email:
2 properties:
3 subject: string
4 body: optional<string>
5 to:
6 type: string
7 docs: The recipient of the email
8 audiences:
9 - beta

SDK 受众

generators.yml 中,您可以应用受众过滤器,以便只有某些端点传递给生成器。

以下示例配置 SDK 过滤 customers

generators.yml
1groups:
2 external:
3 audiences:
4 - customers
5 generators:
6 ...

文档受众

如果生成 Fern Docs,请更新您的 docs.yml 配置以包含您的受众。

以下示例显示如何配置 docs.yml 来为 customers 受众发布文档:

docs.yml
1navigation:
2 - api: API Reference
3 audiences:
4 - customers