Hi, I tried to find how to extend a contract using inheritance to add a few more fields on top of the parent contract.
Say I have a send_email API endpoint (it’s a contrived example, so there can be some details that may look wrong), and the following contract for that
class SendEmailContract < Dry::Validation::Contract params do required(:from).filled(:string) required(:to).filled(:string) required(:text).filled(:string) end end
Then I want to support html email, and want a
:html parameter. I want to do something like
class SendHTMLEmailContract < SendEmailContract params do required(:html).filled(:string) end end
instead of defining it afresh.
I’ve looked at all the related posts, but a lot of them were for version 0.x, and even in the documentation, I could only find ones involving inheriting a dry-schema from another dry-schema. I want to avoid that because it looks like I have to define both
SendEmailContract (which uses the schema to validate), and
SendHTMLEmailContract. Basically two things for every contract.
Is there a support for inheritance for contracts?