c#-AWS Lambda代理Swagger模板集成

我正在尝试设置swagger模板以一次调用全部.

可以说在processlambda下面有两个“功能”.
这是正确的openapi 3.0模板,还是我必须专门配置请求类型和响应类型?

{
   "openapi": "3.0.0",
   "info": {
      "version": "2016-09-12T17:50:37Z",
      "title": "ProxyIntegrationWithLambda"
   },
   "paths": {
      "/GetItemById": {
         "x-amazon-apigateway-any-method": {
            "parameters": [
               {
                  "name": "proxy",
                  "in": "path",
                  "required": true,
                  "schema": {
                     "type": "string"
                  }
               }
            ],
            "responses": {},
            "x-amazon-apigateway-integration": {
               "responses": {
                  "default": {
                     "statusCode": "200"
                  }
               },
               "uri": "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:123456789012:function:SimpleLambda4ProxyResource/invocations",
               "passthroughBehavior": "when_no_match",
               "httpMethod": "POST",
               "cacheNamespace": "roq9wj",
               "cacheKeyParameters": [
                  "method.request.path.proxy"
               ],
               "type": "aws_proxy"
            }
         }
      }
   },
      "/SaveItem": {
         "x-amazon-apigateway-any-method": {
            "parameters": [
               {
                  "name": "proxy",
                  "in": "path",
                  "required": true,
                  "schema": {
                     "type": "string"
                  }
               }
            ],
            "responses": {},
            "x-amazon-apigateway-integration": {
               "responses": {
                  "default": {
                     "statusCode": "200"
                  }
               },
               "uri": "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:123456789012:function:SimpleLambda4ProxyResource/invocations",
               "passthroughBehavior": "when_no_match",
               "httpMethod": "POST",
               "cacheNamespace": "roq9wj",
               "cacheKeyParameters": [
                  "method.request.path.proxy"
               ],
               "type": "aws_proxy"
            }
         }
      }
   },
   "servers": [
      {
         "url": "https://gy415nuibc.execute-api.us-east-1.amazonaws.com/{basePath}",
         "variables": {
            "basePath": {
              "default": "/Process"
            }
         }
      }
   ]
}

尚未对此进行测试,但是C#函数代码使用API​​Gateway响应/请求标准arts对象

解决方法:

或者,您可以使用的一个好方法是配置API网关(指向AWS Lambda),然后从API Gateway配置中配置07​​000您的openapi规范,然后配置generate您的c#客户端.

配置API网关后,您可以运行以下步骤:

第2步中的第1步,运行get-export,例如:

aws apoigateway get-export 
  --rest-api-id 'idfromapigateway-grab-inside-awsdashboard' 
  --stage-namem 'stage-grab-inside-awsdashboard' 
  --export-type 'swagger' outputfile-with-openapispec-generated-step1.json

第2步,共2步)Generate客户端,例如:

nswag swagger2csclient /input:outputfile-with-openapispec-generated-step1.json
  /classname:SpecifyYourCSharpClassName
  /namespace:SpecifyYourCSharpNamespace
  /output:SpecifyYourCSharpFile

步骤2的结果将生成可用于集成测试的c#类.

上一篇:IDEA报Unable to save settings: Failed to save settings. Please restart IntelliJ IDEA


下一篇:记一次失败的面试经历