新发布的“x-amazon-apigateway-request-validator”(我相信4月份)应该能够针对API的POST / PUT有效负载运行JSON模式验证。
我现在尝试以几种不同的方式实现这一点,但我无法使其工作......我添加了验证器:
"x-amazon-apigateway-request-validators": { "ValidateBody": { "validateRequestParameters": false, "validateRequestBody": true }, "ValidateHeaders": { "validateRequestParameters": true, "validateRequestBody": false }}
对于任何methind我会寻找特定的标题,所以我也有Swagger的“根”中的参数:
"x-amazon-apigateway-request-validator": "ValidateHeaders"在POST中,我有一个x-amazon-apigateway-request-validator: ValidateBody ,然后是一个带有JSON模式的Model,其中required几个元素。
然而,只要它是JSON就可以POST任何东西...没有对JSON模式进行验证...
我错过了什么?
The newly released "x-amazon-apigateway-request-validator" (in April I believe) is supposed to be able to run a JSON schema validation against the POST/PUT payload of an API.
I've tried to implement this in several different ways now but I can't make it work... I have added the validators:
"x-amazon-apigateway-request-validators": { "ValidateBody": { "validateRequestParameters": false, "validateRequestBody": true }, "ValidateHeaders": { "validateRequestParameters": true, "validateRequestBody": false }}
For any methind I will look for specific headers so I also have the parameters in the "root" of the Swagger:
"x-amazon-apigateway-request-validator": "ValidateHeaders"In the POST I have a x-amazon-apigateway-request-validator: ValidateBody and then a Model with the JSON schema where several elements are required.
I can however POST anything as long as it is JSON... There is no validation against the JSON schema done...
What am I missing?
最满意答案
这是工作! 部署和新代码的实际使用之间存在时间差,即使我似乎没有进行任何缓存。
出去吃午饭,回到工作的解决方案!
{ "message": "Invalid request body" }能够修改响应消息会很好...
It is working! There is a time lag between the deploy and the actual usage of the new code even though I am not doing any caching it seems.
Went out for lunch and came back to a working solution!
{ "message": "Invalid request body" }It would be nice to be able to modify the response message though...
如何获取AWS API Gateway以针对模型验证JSON Body(How to get AWS API Gateway to validate JSON Body against Model)新发布的“x-amazon-apigateway-request-validator”(我相信4月份)应该能够针对API的POST / PUT有效负载运行JSON模式验证。
我现在尝试以几种不同的方式实现这一点,但我无法使其工作......我添加了验证器:
"x-amazon-apigateway-request-validators": { "ValidateBody": { "validateRequestParameters": false, "validateRequestBody": true }, "ValidateHeaders": { "validateRequestParameters": true, "validateRequestBody": false }}
对于任何methind我会寻找特定的标题,所以我也有Swagger的“根”中的参数:
"x-amazon-apigateway-request-validator": "ValidateHeaders"在POST中,我有一个x-amazon-apigateway-request-validator: ValidateBody ,然后是一个带有JSON模式的Model,其中required几个元素。
然而,只要它是JSON就可以POST任何东西...没有对JSON模式进行验证...
我错过了什么?
The newly released "x-amazon-apigateway-request-validator" (in April I believe) is supposed to be able to run a JSON schema validation against the POST/PUT payload of an API.
I've tried to implement this in several different ways now but I can't make it work... I have added the validators:
"x-amazon-apigateway-request-validators": { "ValidateBody": { "validateRequestParameters": false, "validateRequestBody": true }, "ValidateHeaders": { "validateRequestParameters": true, "validateRequestBody": false }}
For any methind I will look for specific headers so I also have the parameters in the "root" of the Swagger:
"x-amazon-apigateway-request-validator": "ValidateHeaders"In the POST I have a x-amazon-apigateway-request-validator: ValidateBody and then a Model with the JSON schema where several elements are required.
I can however POST anything as long as it is JSON... There is no validation against the JSON schema done...
What am I missing?
最满意答案
这是工作! 部署和新代码的实际使用之间存在时间差,即使我似乎没有进行任何缓存。
出去吃午饭,回到工作的解决方案!
{ "message": "Invalid request body" }能够修改响应消息会很好...
It is working! There is a time lag between the deploy and the actual usage of the new code even though I am not doing any caching it seems.
Went out for lunch and came back to a working solution!
{ "message": "Invalid request body" }It would be nice to be able to modify the response message though...
发布评论