我尝试使用Swagger / OpenAPI定义我的AWS Api Gateway基础架构。到目前为止一切正常,但是我的端点需要API密钥时遇到问题。
My Swagger文件看起来像这样(缩短):
---
swagger: 2.0
basePath: /dev
info:
title: My API
description: Proof of concept
schemes:
- https
securityDefinitions:
api_key:
type: apiKey
name: X-Api-Key
in: header
paths:
/example-path:
options:
consumes:
- application/json
produces:
- application/json
x-amazon-apigateway-integration:
type: mock
requestTemplates:
application/json: |
{
"statusCode" : 200
}
responses:
"default":
statusCode: "200"
responseParameters:
method.response.header.Access-Control-Allow-Methods: "'GET,HEAD,OPTIONS'"
method.response.header.Access-Control-Allow-Headers: "'Content-Type,Authorization,X-Amz-Date,X-Api-Key,X-Amz-Security-Token'"
method.response.header.Access-Control-Allow-Origin: "'*'"
responseTemplates:
application/json: |
{}
responses:
200:
description: Default response for CORS method
headers:
Access-Control-Allow-Headers:
type: "string"
Access-Control-Allow-Methods:
type: "string"
Access-Control-Allow-Origin:
type: "string"
get:
security:
- api_key: []
x-amazon-apigateway-integration:
# Further definition of the endpoint, calling Lambda etc...
在CloudFormation模板内链接,Swagger文件已成功处理。但是,当我在AWS Web Console中打开端点时,所需的API密钥的标记仍为 false 。
有什么建议吗?感谢。
答案 0 :(得分:4)
找到解决方案:API密钥必须命名为x-api-key
(全部小写)。
似乎只有这样才能在导入过程中识别设置。