OpenAPI 擴展
擴展(也稱為規格擴展或供應商擴展)是以 x-
開頭的自訂屬性,例如 x-logo
。這些屬性用於新增 OpenAPI 標準預設不包含的額外資訊或功能。例如,許多工具(包括 Amazon API Gateway、ReDoc、APIMatic 和 Fern)都使用擴展來包含特定於其產品的詳細資訊。
新增擴展
API 規格的根層級和以下位置支援擴展
info
區段paths
區段、個別路徑和操作- 操作參數
回應
標籤
- 安全性配置
擴展值可以是基本類型、陣列、物件或 null
。如果值是物件或物件陣列,則物件的屬性名稱不需要以 x-
開頭。
範例
使用 Amazon API Gateway 自訂授權方的 API 可能會包含類似於此的擴展
1components:2 securitySchemes:3 APIGatewayAuthorizer:4 type: apiKey5 name: Authorization6 in: header7 x-amazon-apigateway-authtype: oauth28 x-amazon-apigateway-authorizer:9 type: token10 authorizerUri: arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:account-id:function:function-name/invocations11 authorizerCredentials: arn:aws:iam::account-id:role12 identityValidationExpression: "^x-[a-z]+"13 authorizerResultTtlInSeconds: 60