跳到内容

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

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

© . All rights reserved.