跳到内容

Swagger 扩展

扩展(或供应商扩展)是以外 x- 开头的自定义属性,例如 x-logo。它们可用于描述标准 Swagger 规范未涵盖的额外功能。许多支持 Swagger 的 API 相关产品都利用扩展来记录其自身的属性,例如 Amazon API Gateway、ReDoc、APIMatic 等。扩展在 API 规范的根级别以及以下位置受支持

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

扩展值可以是原语、数组、对象或 null。如果值是对象或对象数组,则对象的属性名不需要以 x- 开头。

示例

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

1
securityDefinitions:
2
APIGatewayAuthorizer:
3
type: apiKey
4
name: Authorization
5
in: header
6
x-amazon-apigateway-authtype: oauth2
7
x-amazon-apigateway-authorizer:
8
type: token
9
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
10
authorizerCredentials: arn:aws:iam::account-id:role
11
identityValidationExpression: "^x-[a-z]+"
12
authorizerResultTtlInSeconds: 60

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

© 2025 swagger.org.cn. All rights reserved.