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