【问题标题】:How to validate in AWS serverless schema without plugin using only request如何仅使用请求在没有插件的情况下验证 AWS 无服务器架构
【发布时间】:2019-07-04 05:12:09
【问题描述】:

我正在尝试使用正文/有效负载和参数验证发布请求:

curl -X POST \
  [url]/api/{param1}/comment/{param2} \
  -H 'Content-Type: application/json' \
  -H 'cache-control: no-cache' \
  -d '{
        "bodyParam1": "45",
        "bodyParam2": 123123,
        "bodyParam3": 123
}
'

使用 node js 的无服务器框架。

这是我用 lambda 和 lambda-proxy 测试过的 serverless.yml,但我无法验证参数:

 functions:
  someName:
    handler: src/comment.post
    events:
      - http:
          integration: lambda-proxy
          path: /api/{param1}/comment/{param2}
          method: post
          request:
            schema:
              application/json: ${file(./src/models/schema1.json)}
          cors: true

这是我的 schema1.json:

{
  "definitions" : {},
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "title" :"Get object",
  "required": [
    "bodyParam1",
    "bodyParam2",
    "bodyParam3"
  ],
  "properties": {
    "bodyParam1":
    {
      "type":
      "string"
    },
    "bodyParam2":
    {
      "type":
      "integer"
    },
    "bodyParam3":
    {
      "type":
      "integer"
    }
  }
}

请注意,这是对无服务器请求的原生支持,而不是插件版本。

【问题讨论】:

  • 搞清楚这个了吗?

标签: validation serverless-framework aws-serverless


【解决方案1】:

使用aws cli

aws cloudformation validate-template --template-body file://schema1.json

【讨论】:

  • 但你不知道在 serverless.yml 中不使用 aws cli 的方法吗?
猜你喜欢
  • 2011-09-25
  • 2018-08-14
  • 1970-01-01
  • 2011-02-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-21
  • 2021-09-14
相关资源
最近更新 更多