Nat*_*ial 5 aws-cloudformation swagger aws-api-gateway openapi aws-sam
使用OAS3定义创建 API 网关时,路径和查询参数类型会更改为字符串。我找不到任何说明预期行为或原因的 AWS 文档。我知道手动配置 API Gateway 时它不会公开type路径/查询变量,但是有没有办法让 API Gateway 保留 OAS3路径/查询参数类型以供文档使用?
我们正在尝试使用 Serverless Developer Portal 来托管我们的 API 文档,我们需要公开正确的参数类型;例如,对于limit查询参数,我们需要将其显示为integer.
这是一个基本示例的 SAM。路径参数param是 aninteger并且 swagger 生成的文档正确显示它,但是 API Gateway 将其更改为 astring并且生成的文档将其显示为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
Run Code Online (Sandbox Code Playgroud)
将 SAM 放入 tempalte.yaml 并运行 cloudformation 进行部署:
aws cloudformation deploy --template-file template.yaml --stack-name boolean-test
Run Code Online (Sandbox Code Playgroud)
获取身份证
aws apigateway get-rest-apis --query "items[?name=='Aws API Gateway Boolean Test'].id"
Run Code Online (Sandbox Code Playgroud)
检索替换--rest-api-id为正确 id的 OAS :
aws apigateway get-export --parameters extensions='apigateway' --rest-api-id XXXXXXXXXX --stage-name dev --export-type swagger latestoas.json
Run Code Online (Sandbox Code Playgroud)
导出的 OAS3 定义将参数显示为字符串:
"paths" : {
"/{param}" : {
"get" : {
"parameters" : [ {
"name" : "param",
"in" : "path",
"required" : true,
"schema" : {
"type" : "string"
}
} ],
Run Code Online (Sandbox Code Playgroud)
另外,在无服务器开发者观看所生成的文档招摇门户显示param作为string。
| 归档时间: |
|
| 查看次数: |
487 次 |
| 最近记录: |