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

Default validator being created #29

Open
chippyash opened this issue Mar 1, 2022 · 3 comments
Open

Default validator being created #29

chippyash opened this issue Mar 1, 2022 · 3 comments

Comments

@chippyash
Copy link

Although I have specified a request validator (using FN::ImportValue), serverless deploy is still creating a default request validator for the stack. Checking the .serverless/cloudformation-template-update-stack.json I can see it declared as a resource, but it is never referenced anywhere else in stack spec.

Is this predicted behaviour or am I missing something?

serverless V3.0.0

provider:
  apiGateway:
    restApiId: ${self:custom.environment.apiGateway.restApiId}
    restApiRootResourceId: ${self:custom.environment.apiGateway.restApiRootResourceId}
...
plugins:
  - serverless-iam-roles-per-function
  - serverless-plugin-log-subscription
  - serverless-plugin-scripts
  - serverless-reqvalidator-plugin
...
functions:
  plan:
    handler: ./bin/xxx
    events:
      - http:
          method: put
          path: aum/xxx
          reqValidatorName:
            Fn::ImportValue: 'apiGwRequestValidateAll'
          request:
            schemas:
              application/json: ${file(serverless/schema/xxx.json)}
            parameters:
              headers:
                x-context-id:
                  required: false
                  mappedValue: context.requestId
@RafPe
Copy link
Owner

RafPe commented Mar 9, 2022

@chippyash thanks for opening the issue. Can you specify where apiGwRequestValidateAll is ref from? I don not see any more detail in the provided file

@chippyash
Copy link
Author

@RafPe That is a reference to an externally created request validator created in another stack. As per your documentation. That works fine btw.

@chippyash
Copy link
Author

I have a workaround for this at the moment which involves using the serverless-plugin-scripts plugin

custom:
  scripts:
    hooks:
      'after:package:finalize': bash ./scripts/remove-request-validator.sh

the script

#!/usr/bin/env bash
echo "Removing service default request validator"
cat .serverless/serverless-state.json  \
  | jq 'del(.service.provider.compiledCloudFormationTemplate.Resources.ApiGatewayMystackRequestValidator)' \
  > ./state.json
rm .serverless/serverless-state.json
mv ./state.json .serverless/serverless-state.json

cat .serverless/cloudformation-template-update-stack.json  \
  | jq 'del(.Resources.ApiGatewayMystackRequestValidator)' \
  > ./stack.json
rm .serverless/cloudformation-template-update-stack.json
mv ./stack.json .serverless/cloudformation-template-update-stack.json

Not particularly elegant, but it works! If we could get the same functionality into your plugin with perhaps a flag in the custom settings to switch it on/off, that would be marvellous. It would only need to remove the default request validator IF there was nothing referencing it.

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

No branches or pull requests

2 participants