How to enable request validation?
Hi
I would like to enable request validation to my API, so I can stop invalid requests from invoking lambdas [1] and also make sure the data my users send is correct.
I've followed a couple of recommendations I found in this repo, and I used leangle to add models. While the models are uploaded and are available in the API gateway console, and the Request Body is correctly assigned to my schema (called TextSchema), as seen in this screenshot the Request Validator setting is not set to Validate body, query string parameters, and headers , and the request is not validated using the schema.
I've managed to make the Validator work by manually setting the correct value in the form, then deploying the API from the console, but as soon as I change something and deploy chalice from the cli (or the cdk) these values are reset and the API stops validating requests.
My API is experimental, so this is all the code
import leangle
from chalice import Blueprint
from marshmallow import Schema, fields
app = Blueprint("myApp")
@leangle.add_schema()
class TextSchema(Schema):
text = fields.Str()
@app.route('/test', methods=['POST'])
@leangle.describe.parameter(name='body', _in='body', description='Receive text', schema='TextSchema')
def process_text():
text = app.current_request.json_body['text']
return text
What is it that I am missing? Or is there a better way to do this?
Thank you
[1] https://dev.to/dvddpl/reduce-lambda-invocations-and-code-boilerplate-by-adding-a-json-schema-validator-to-your-api-gateway-15af
Same question. Is it possible in Chalice define request model and assgin it for validation to any API's methods? Thanks.