serverless-reqvalidator-plugin
serverless-reqvalidator-plugin copied to clipboard
Default validator being created
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
@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
@RafPe That is a reference to an externally created request validator created in another stack. As per your documentation. That works fine btw.
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.