Swagger 扩展
扩展,或供应商扩展,是以 x-
开头的自定义属性,例如 x-logo
。 它们可用于描述标准 Swagger 规范未涵盖的额外功能。 许多支持 Swagger 的 API 相关产品都使用扩展来记录他们自己的属性,例如 Amazon API Gateway、ReDoc、APIMatic 等。 扩展在 API 规范的根级别和以下位置受支持
info
部分paths
部分,各个路径和操作- 操作参数
响应
标签
- 安全方案
扩展值可以是原始值、数组、对象或 null
。 如果值是对象或对象数组,则该对象的属性名称不需要以 x-
开头。
示例
使用 Amazon API Gateway 自定义授权程序的 API 将包含类似于此的扩展
1securityDefinitions:2 APIGatewayAuthorizer:3 type: apiKey4 name: Authorization5 in: header6 x-amazon-apigateway-authtype: oauth27 x-amazon-apigateway-authorizer:8 type: token9 authorizerUri: arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:account-id:function:function-name/invocations10 authorizerCredentials: arn:aws:iam::account-id:role11 identityValidationExpression: "^x-[a-z]+"12 authorizerResultTtlInSeconds: 60