幂等性

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

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

Fern 通过两个协同工作的扩展支持幂等性配置:x-fern-idempotency-headers 配置您的 API 使用的幂等性头部,x-fern-idempotent 将单个端点标记为幂等的。配置后,Fern 生成的 SDK 允许用户指定幂等性头部以进行安全的请求重试。

配置幂等性头部

在 OpenAPI 规范的根级别添加 x-fern-idempotency-headers 扩展,以定义您的 API 用于幂等性的头部:

openapi.yml
1x-fern-idempotency-headers:
2 - header: Idempotency-Key
3 name: idempotency_key
4 - header: Idempotency-Expiration
5 name: idempotency_expiration

每个幂等性头部支持以下属性:

属性描述
headerHTTP 头部名称(例如:Idempotency-Key
name生成的 SDK 中使用的参数名称(例如:idempotency_key

将端点标记为幂等的

在单个端点上添加 x-fern-idempotent 扩展并将其设置为 true,以将它们标记为幂等的:

openapi.yml
1x-fern-idempotency-headers:
2 - header: Idempotency-Key
3 name: idempotency_key
4
5paths:
6 /plants:
7 post:
8 x-fern-idempotent: true
9 operationId: create_plant
10 requestBody:
11 required: true
12 content:
13 application/json:
14 schema:
15 type: object
16 properties:
17 name:
18 type: string
19 species:
20 type: string
21 responses:
22 '201':
23 description: Plant created successfully