Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add request schema to an http event for the stepfunction for validation #554

Closed
zoiman opened this issue Feb 13, 2023 · 8 comments · Fixed by #573
Closed

Add request schema to an http event for the stepfunction for validation #554

zoiman opened this issue Feb 13, 2023 · 8 comments · Fixed by #573
Labels

Comments

@zoiman
Copy link

zoiman commented Feb 13, 2023

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"
            }
          }
@KillDozerX2
Copy link

I believe it's because there's no action taken to create an API Gateway model

@zoiman
Copy link
Author

zoiman commented Feb 15, 2023

can I do this manually? Or shouldn't this be done by the plugin?

@lxhunter
Copy link

lxhunter commented Feb 21, 2023

I would also be interested in a solution. Seems like schema is not at all implemented, only template.

@lxhunter
Copy link

lxhunter commented Feb 26, 2023

@zoiman you could use a request schema with a function aka. lambda and kick off the step function from there.

@KillDozerX2
Copy link

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.

@KillDozerX2
Copy link

KillDozerX2 commented Mar 8, 2023

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

@paolorossig
Copy link
Contributor

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.

@horike37
Copy link
Collaborator

🎉 This issue has been resolved in version 3.15.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants