Dry-validation to validation API endpoints

Hello, I’m looking for feedback on how to validate parameters for multiple endpoints for our very large rails application. For example, I have Controller A, Controller A has two methods MethodA, MethodB. Both have unique routes to each method and have different parameters that need to be validated, but all are related to Controller A.

If this is the case, how do I organize my contracts? I would like them to be under the same Controller (A) however, Doing something like AContract wouldn’t work. I’d have to create something like MethodAContract, MethodBContract? Then what happens if another controller has similarly named methods… I have to name them AMethodAContract, AMethodBContract?.

I guess what I’m looking for, is there a way to declare a single ‘Parent’ contract and then child contract / validations under that on? Something like, A.MethodAContract, A.MethodBContract?

Hey there

Maybe you could port or SafeParams Rails extension to use contracts instead and adjust it to your needs. This way you’d be able to define param contracts without the need to declare and instantiate contract classes.