导出Swagger接口定义文件

在AWS API Gateway界面上,可以导出swagger接口定义文件。

而后利用Node js swagger-ui 依赖,生成swagger接口地址

CloudFormation模版配置API Gateway参数

对于RequestBody配置方式

例:给该method配置RequestModels

MethodPostForUpdateDraftToCurrentVersion:
Type: 'AWS::ApiGateway::Method'
Properties:
HttpMethod: POST
RequestModels:
application/json: UpdateDraftToCurrentVersionModel
ResourceId: !Ref ResourceDocumentUpdateDraftToCurrentVersion
RestApiId: !Ref RestApiDDTM
AuthorizationType: NONE
Integration:
Type: AWS_PROXY
IntegrationHttpMethod: POST
Uri: !Sub
- arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${FnArn}:${FnVersion}/invocations
- {FnArn : !Ref functionArn,FnVersion : '${stageVariables.version}'}
IntegrationResponses:
- StatusCode: 200
MethodResponses:
- StatusCode: 200
ResponseModels:
application/json: Empty

UpdateDraftToCurrentVersionModel:
Type: "AWS::ApiGateway::Model"
Properties:
RestApiId:
Ref: RestApiDDTM
ContentType: "application/json"
Description: "request body for UpdateDraftToCurrentVersion"
Name: UpdateDraftToCurrentVersionModel
Schema:
"$schema": "http://json-schema.org/draft-04/schema#"
title: UpdateDraftToCurrentVersionModel
type: object
properties:
params:
type: object
properties:
userId:
type: integer
documentId:
type: integer
companyId:
type: integer
documentVersionId:
type: integer
templates:
type: array
items:
type: object
properties:
contentType:
type: string
locale:
type: string
content:
type: string
textContent:
type: string
fileContent:
type: string

生成swagger API后,实际上的requestBody为:
{
"userId":integer,
"documentId":integer,
"companyId":integer,
"documentVersionId":integer,
templates:[
{
"contentType":"string",
"locale":"string",
"content":"string",
"textContent":"string",
"fileContent":"string"
}
]
}




对于RequestParam配置方式

请求路径:/document/listDocSamplePage?page=1&pageSize=&query=

增加RequestParameters参数

keywmethod.request.querystring.{paramName}

MethodGetForListDocSamplePage:
Type: 'AWS::ApiGateway::Method'
Properties:
HttpMethod: GET
RequestParameters:
method.request.querystring.page: false
method.request.querystring.pageSize: false
method.request.querystring.query: false


生成Swagger API效果:


 

 

对于PathVaribles配置方式

请求路径:/document/findFullDocSample/{id}

增加RequestParameters参数

key:method.request.path.{pathVariableName}

value:值是否必须

MethodGetForFindFullDocSampleId:
Type: 'AWS::ApiGateway::Method'
Properties:
HttpMethod: GET
RequestParameters:
method.request.path.id: true

Swagger Api 效果:


posted on 2019-03-13 15:17  陌生初见  阅读(514)  评论(0编辑  收藏  举报