Add request schema to an http event for the stepfunction for validation
zoiman opened this issue ยท 8 comments
This is a Feature Proposal
Description
For feature proposals:
- What is the use case that should be solved. The more detail you describe this in the easier it is to understand for us.
It would be useful to have the possibility to add a request schema to a http event for the statemachine similar how you would add it for a function. This way, none valid input will be rejected before it hits the statemachine and there is no invocation which reduces cost.
- If there is additional config how would it look
I tried to add the event schema to my statemachine which did not result in any error, however no model was created in the apigateway. The generated serverless-state.json looked like this:
"stateMachines": {
"mystatemachine": {
"id": "mystatemachine",
"events": [
{
"http": {
"path": "start",
"method": "post",
"private": true,
"request": {
"schemas": {
"application/json": {
"type": "object",
"properties": {
"Input": {
"type": "string"
}
},
"required": [
"Input"
]
}
}
}
}
}
In comparison a similar request schema for a function looks like this:
"functions": {
"hello": {
"handler": "src/functions/hello/handler.main",
"events": [
{
"http": {
"method": "post",
"path": "hello",
"request": {
"schemas": {
"application/json": {
"$ref": "$[\"service\"][\"provider\"][\"compiledCloudFormationTemplate\"][\"Resources\"][\"ApiGatewayMethodHelloPostApplicationJsonModel\"][\"Properties\"][\"Schema\"]"
}
}
},
"integration": "AWS_PROXY"
}
}
I believe it's because there's no action taken to create an API Gateway model
can I do this manually? Or shouldn't this be done by the plugin?
I would also be interested in a solution. Seems like schema is not at all implemented, only template.
@zoiman you could use a request schema with a function aka. lambda and kick off the step function from there.
I think a better idea here is to create the Model for Api Gateway. Let me try to create a PR this week for it.
I think a better idea here is to create the Model for Api Gateway. Let me try to create a PR this week for it.
This is turning out to be a bit more complicated than I'd thought, might take me some time to finish. Please watch this repo for updates
I am trying the schema validation with the file method, same as serverless docs, but in step functions it doesn't work, so this future proposal could help for this too.
๐ This issue has been resolved in version 3.15.0 ๐
The release is available on:
Your semantic-release bot ๐ฆ๐