Extend validation schema for function properties
I was seeing a lot of warnings about my configuration that looked like unrecognized property 'optimize' because serverless now requests that plugins provide schema to validate configuration. It warns that serverless will default to throwing on these kinds of warnings in the future so I added a schema definition.
Not 100% sure about the schema for all options but this satisfied the config warnings from serverless for me. Hope this is a start.
I could use this PR, I think. Not sure if this PR contains complete change though. I'm using serverless 2.51.2. The following doesn't seem to work:
custom:
optimize: false
If I run sls invoke local --function redirects --path ./testdata.json, optimize still runs. And, if I define the above under a function, as shown below, I get the unrecognized property 'optimize' error.
functions:
redirects:
handler: handler.handler
optimize: false
Looking at the following doc, I think serverless.configSchemaHandler.defineCustomProperties is also needed for this plugin.
https://www.serverless.com/framework/docs/providers/aws/guide/plugins/#extending-validation-schema
@0ui - will you be able to include the custom properties schema in your change?
@amimas All the extended schema I think are good to add but I scoped this PR just to the function properties because I happened to be testing them. If you want to add the other ones as well, it should be an easy merge beside this one or I could close this one if another PR contains these function properties.
And, if I define the above under a function, as shown below, I get the unrecognized property 'optimize' error.
I just tried that locally and couldn't reproduce the problem. Are you sure this branch is being used? When I remove boolean from the type array for optimize, I get a different warning
'functions.xxxx.optimize': should be object
Are you sure this branch is being used?
I didn't use this branch. I'm using the current latest release.
Yeah, I can open a separate PR too but thought maybe it doesn't need to be separated. Guess it depends how maintainers of this plugin wants to process it.
@diogogvhenriques - Would it possible for you to review this PR and possibly merge if you don't see any issues? Even the functions schema by itself would be useful for me or others who started using newer version of serverless. I'm hoping I don't need to manage a local patch for this 😄 .