amazon-web-services - API 网关的“导出为 Swagger”和“导出为 Swagger + Postman”缺少“参数”对象
问题描述
我有一个 API 网关端点 (/item/{itemId}),其中有一个路径参数“itemId”。这是我用来在 API 网关中创建端点的招摇定义。
{
"swagger": "2.0",
"info": {
"version": "v1",
"title": "sample-postman-import"
},
"host": "example.com",
"basePath": "/api",
"schemes": ["https"],
"paths": {
"/item/{itemId}": {
"get": {
"produces": [
"application/json"
],
"parameters": [
{
"name": "itemId",
"in": "path",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "200 response"
}
}
}
}
}
部署 API 后,当我将其导出为 swagger 定义时,导出的定义缺少“参数”对象,使其成为不完整的 swagger 文件。当我看到同样的问题时
- 尝试从 UI 导出,如https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-export-api.html所示
- 使用来自 javascript aws-sdk https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/APIGateway.html#getExport-property的 getExport API 调用
这是导出的样子:
{
"swagger": "2.0",
"info": {
"version": "v1",
"title": "sample-postman-import_old"
},
"host": "example.com",
"basePath": "/api",
"schemes": ["https"],
"paths": {
"/item/{itemId}": {
"get": {
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "200 response"
}
}
}
}
}
}
解决方案
当我使用 Terraform 创建 API 网关时,我遇到了同样的问题。在 AWS UI 上显示了参数,但是当我通过 AWS CLI 使用aws apigateway get-method
命令请求方法信息时,未提供参数。因此,请确保根据需要设置了“requestParameters”,如果没有,请通过 CLI 或 Terraform 进行设置。
推荐阅读
- php - 如果我有 csrf 令牌,我什至需要不记名令牌吗?
- c++ - 找到不为零的最小数字
- python - Tensorflow: how to save a model before the end of optimization?
- spring - 在我的代码中尝试打开 - 关闭原则,但在 java 中出现奇怪的行为
- openam - 启用 openam cdsso 时重定向到自定义登录页面
- java - Kafka和数据库调用之间的Spring @Transactional问题
- kubernetes - k3s ctr 图像导入到不同的目录
- c# - 如何验证字符串、整数、日期时间
- java - 输入的数据没有被存储,也没有显示错误
- apache - 如何将 activiti 工作流引擎与 Vertx 集成?