跳转到内容

OpenAPI 扩展

扩展(也称为规范扩展供应商扩展)是以 x- 开头的自定义属性,例如 x-logo。这些用于添加 OpenAPI 标准默认不包含的额外信息或功能。例如,许多工具(包括 Amazon API Gateway、ReDoc、APIMatic 和 Fern)都使用扩展来包含特定于其产品的详细信息。

添加扩展

API 规范的根级别和以下位置支持扩展

  • info 部分
  • paths 部分,单独的路径和操作
  • 操作参数
  • 响应
  • 标签
  • 安全方案

扩展值可以是基本类型、数组、对象或 null。如果该值是对象或对象数组,则对象的属性名称不需要以 x- 开头。

示例

使用 Amazon API Gateway 自定义授权器的 API 可能包含类似于此的扩展

1
components:
2
securitySchemes:
3
APIGatewayAuthorizer:
4
type: apiKey
5
name: Authorization
6
in: header
7
x-amazon-apigateway-authtype: oauth2
8
x-amazon-apigateway-authorizer:
9
type: token
10
authorizerUri: arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:account-id:function:function-name/invocations
11
authorizerCredentials: arn:aws:iam::account-id:role
12
identityValidationExpression: "^x-[a-z]+"
13
authorizerResultTtlInSeconds: 60

没有找到您要找的内容? 向社区提问
发现错误? 请告知我们