跳至內容

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

找不到您要尋找的內容嗎?詢問社群
發現錯誤?告訴我們