zoukankan      html  css  js  c++  java
  • AWS API Gateway Swagger定义

    导出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 效果:


  • 相关阅读:
    使用docker搭建gitlab版本控制系统
    Spring Boot与Docker部署
    CentOS7 使用yum命令安装Java SDK(openjdk)
    配置带用户权限的docker registry v2
    Docker搭建带有访问认证的私有仓库
    CentOS7 关闭防火墙
    CentOS7.2网络配置
    Docker Machine 简介
    docker的常用命令汇总
    实时查看docker容器日志
  • 原文地址:https://www.cnblogs.com/yoyoblogs/p/10523369.html
Copyright © 2011-2022 走看看