OpenAPI 扩展
扩展(也称为规范扩展或供应商扩展)是以 x-
开头的自定义属性,例如 x-logo
。这些用于添加 OpenAPI 标准默认不包含的额外信息或功能。例如,许多工具(包括 Amazon API Gateway、ReDoc、APIMatic 和 Fern)都使用扩展来包含特定于其产品的详细信息。
添加扩展
API 规范的根级别和以下位置支持扩展
info
部分paths
部分,单独的路径和操作- 操作参数
响应
标签
- 安全方案
扩展值可以是基本类型、数组、对象或 null
。如果该值是对象或对象数组,则对象的属性名称不需要以 x-
开头。
示例
使用 Amazon API Gateway 自定义授权器的 API 可能包含类似于此的扩展
1components:2 securitySchemes:3 APIGatewayAuthorizer:4 type: apiKey5 name: Authorization6 in: header7 x-amazon-apigateway-authtype: oauth28 x-amazon-apigateway-authorizer:9 type: token10 authorizerUri: arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:account-id:function:function-name/invocations11 authorizerCredentials: arn:aws:iam::account-id:role12 identityValidationExpression: "^x-[a-z]+"13 authorizerResultTtlInSeconds: 60