【发布时间】: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