Add simple validation DSL#4
Open
jgaskins wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Following a conversation on The Practical Dev, I began thinking that maybe validations on the output aren't a terrible idea. If the contract between an API and a client says that some number will be a float in the range of
0.0...1.0, checking that it's an instance ofFloatis not good enough to comply with that contract.This PR (in its current state) is an example of how declaring that could look:
A few things I'm unsure of:
validate. It is a validation, but so are the type and structure checks. This is intended for the value of primitives, but that's really the only difference.The only thing I can think of to improve on these is to make it work something like this:
That means we have to define a bunch of special-case matchers, but it would let the error messages look good, we wouldn't have to have a different meaning for the block, and it's also another naming suggestion for the DSL method.