kiva / protocol-common

Shared code across the various protocol microservices
Apache License 2.0
10 stars 3 forks source link

PRO-2926: Add function parameter validation decorators. #29

Closed ghost closed 3 years ago

ghost commented 3 years ago

Signed-off-by: Jeff Kennedy jeffk@kiva.org

šŸ”„ šŸž šŸ™‹ šŸš« šŸš€

(Click here if you don't understand these emojis)

What issue is this targeting?

Changes proposed in this pull request We currently use class-validator in conjunction with NestJS to validate request objects. However, that doesn't really cover us. There are lots of places in the code where, for example, we accept any as a request object and then cast it to something else later, or we break the request object up into several simple types and then pass those on to other functions.

Now we can validate parameters that are passed to any function at runtime!

This is obviously a very limited set of validations that I've included up front. They are:

At a high level, to use one of these validations, decorate the appropriate parameter with the validation you care about, then decorate the function with the @ValidateParams decorator. I'd recommend looking into the test suites that I added to get a sense of how to use these. Each individual decorator has some documentation that should prove to be helpful too.

The existing functionality provided by NestJS + class-validator via the ProtocolValidationPipe remains in tact. Its underlying error formatting is re-used by this new parameter validation code.

šŸš€ Deployment changes šŸš€
(list added or removed env, db changes etc)

Other Notes