serverless: Query string does not honor required/not required
This is a Bug Report
Description
- What went wrong?
I created a query string parameter set to true, which marks it as required. However, nothing happens when it’s not passed.
- What did you expect should have happened?
I expect to see an error when the parameter is missing.
- What was the config you used?
See below for serverless.yml.
- What stacktrace or error message from your provider did you see?
None. Expected to see an error when query string parameter is missing.
I want my request to have a certain query string parameter. I saw the following here:
To pass optional and required parameters to your functions, so you can use them in API Gateway tests and SDK generation, marking them as true will make them required, false will make them optional.
However, when marking a query string as true does not seem to make it required. When using the following code (clean start from serverless create --template aws-nodejs-typescript), all requests pass to the hello path, even if the query string is not set.
serverless.yml:
service:
  name: example-test
plugins:
  - serverless-webpack
  - serverless-offline
provider:
  name: aws
  runtime: nodejs6.10
functions:
  hello:
    handler: handler.hello
    events:
      - http:
          method: get
          path: hello
          request:
            parameters:
              querystrings:
                url: true
Similar or dependent issues:
Additional Data
- Serverless Framework Version you’re using: 1.27.3
- Operating System: Ubuntu 18.04 LTS
- Stack Trace: N/A
- Provider Error messages: N/A
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 25
- Comments: 18 (1 by maintainers)
Commits related to this issue
- fix: set RequestValidatorId for request parameters (#5034) — committed to kazkansouh/serverless by kazkansouh 3 years ago
- fix: set RequestValidatorId for request parameters (#5034) — committed to kazkansouh/serverless by kazkansouh 3 years ago
- fix: set RequestValidatorId for request parameters (#5034) — committed to kazkansouh/serverless by kazkansouh 3 years ago
If you set params as required via serverless syntax you then can just also activate the validator for parameters like so
Here is the working template:
In serverless.yml add this
I literally gave a full explaination right above your comment
Oookay I got it! It should be:
ApiGatewayMethodFooGet, wherefoois my handler name andgetis the HTTP method I’m handling.@akleiber thank you 🙏