swagger - AWS API Gateway 将 OAS3 路径和查询参数类型更改为字符串
问题描述
使用OAS3
定义创建 API 网关时,路径和查询参数类型将更改为字符串。我找不到任何说明预期行为或原因的 AWS 文档。我知道在手动配置 API Gateway 时它不会公开type
路径/查询变量,但是有没有办法让 API Gateway 保留 OAS3
路径/查询参数类型以备文档之用?
我们正在尝试使用无服务器开发人员门户来托管我们的 API 文档,并且我们需要公开正确的参数类型;例如,对于limit
查询参数,我们需要将其显示为integer
.
这是一个基本示例的 SAM。path 参数param
是 aninteger
并且 swagger 生成的文档正确显示它,但是 API Gateway 将其更改为 astring
并且生成的文档将其显示为 a string
:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
ComplexityScoreProxy:
Type: AWS::Serverless::Api
Properties:
StageName: dev
DefinitionBody:
openapi: 3.0.1
info:
version: "1"
title: Aws API Gateway Boolean Test
paths:
/{param}:
get:
x-amazon-apigateway-integration:
type: http_proxy
uri: https://example.com
httpMethod: GET
responses:
"200":
statusCode: 200
parameters:
- name: param
in: path
required: true
schema:
type: integer
responses:
"200":
description: OK
将 SAM 放入 tempalte.yaml 并运行 cloudformation 进行部署:
aws cloudformation deploy --template-file template.yaml --stack-name boolean-test
获取身份证
aws apigateway get-rest-apis --query "items[?name=='Aws API Gateway Boolean Test'].id"
检索 OAS 用--rest-api-id
正确的 id 替换:
aws apigateway get-export --parameters extensions='apigateway' --rest-api-id XXXXXXXXXX --stage-name dev --export-type swagger latestoas.json
导出的 OAS3 定义将参数显示为字符串:
"paths" : {
"/{param}" : {
"get" : {
"parameters" : [ {
"name" : "param",
"in" : "path",
"required" : true,
"schema" : {
"type" : "string"
}
} ],
此外,在 Serverless Developer Portal 中查看生成的 swagger 文档会显示param
为string
.
解决方案
推荐阅读
- javascript - 当我调用 axios 请求时如何让微调器显示
- php - WordPress安装期间大约404
- time-complexity - 这种方法的最佳/平均/和最坏情况复杂度(大 O)是多少?
- python - 如何在不丧失键盘/鼠标控制的情况下实现自动化(类似于 selenium 的受控窗口)
- c - 并行区域上的矩阵元素之和导致 OpenMP 上的错误答案
- c# - 是否有有效的算术捷径可用于优化点云的过滤?
- node.js - 在这种情况下使用 GET 而不是 POST 的原因是什么?
- html - snapchat的标签是什么?
- go - 当我使用客户端去 kubernetes 监视列表时的一些问题
- reactjs - 是否可以延迟组件在 React 中被销毁?