Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add modifier for strict schema validation #224

Merged
merged 4 commits into from
Mar 13, 2022
Merged

Conversation

sbarfurth
Copy link
Collaborator

Description

This adds a modifier strict that can be used with the schema rule. All it does it ensure that a validated schema has no additional properties. This makes a strict schema validation more locked down than comparable coding paradigms like interfaces.

Thank you @dbismut for the idea.

Part of #191, inspired by #179

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other (please, feel free to specify what kind of change it is)

Checklist:

  • I have created my branch from a recent version of master
  • The code is clean and easy to understand
  • I have written tests to guarantee that everything is working properly
  • I have made corresponding changes to the documentation
  • I have added changes to the Unreleased section of the CHANGELOG

@sbarfurth
Copy link
Collaborator Author

For you to note @imbrn: Every modifier function can now also use the rule it is being validated on. The rule is passed to the modifier as a second argument. This change is backward compatible. This allows modifiers to act based on the rule they are on and even to validate based on the arguments given to the rule. This is important for this modifier, because it needs to change the outcome of the validation based on the configuration of the schema rule.

@imbrn
Copy link
Owner

imbrn commented Feb 22, 2022

Thanks @barfurth. I'll take a look at that later.

Copy link
Owner

@imbrn imbrn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems really good to me.

I'd like to have some other tests using other modifiers together, for example:

.not.strict
.not.some.strict
.some.not.strict
// etc

It'd be nice to also have some test to check that strict is actually ignored by not-schema-based validations.

@sbarfurth
Copy link
Collaborator Author

@imbrn I have added more tests - what do you think?

Copy link
Owner

@imbrn imbrn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice! 🤩

@sbarfurth sbarfurth merged commit fa865ee into master Mar 13, 2022
@sbarfurth sbarfurth deleted the feature/strict-schema branch March 13, 2022 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants