跳至內容

OpenAPI 擴展

擴展(也稱為規格擴展供應商擴展)是以 x- 開頭的自訂屬性,例如 x-logo。這些屬性用於新增 OpenAPI 標準預設不包含的額外資訊或功能。例如,許多工具(包括 Amazon API Gateway、ReDoc、APIMatic 和 Fern)都使用擴展來包含特定於其產品的詳細資訊。

新增擴展

API 規格的根層級和以下位置支援擴展

  • info 區段
  • paths 區段、個別路徑和操作
  • 操作參數
  • 回應
  • 標籤
  • 安全性配置

擴展值可以是基本類型、陣列、物件或 null。如果值是物件或物件陣列,則物件的屬性名稱不需要以 x- 開頭。

範例

使用 Amazon API Gateway 自訂授權方的 API 可能會包含類似於此的擴展

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

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