-
Notifications
You must be signed in to change notification settings - Fork 0
feat: ✨ add RequiredCheck
#122
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
Conversation
| """Checks the descriptor against the rule and creates issues for fields that fail. | ||
| def __init__(self, jsonpath: str, message: str): | ||
| """Initializes the `RequiredRule`.""" | ||
| field_name_match = re.search(r"(?<!\.)(\.\w+)$", jsonpath) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Find field names not preceded by .. So, e.g., $.resources[*].name >> .name
lwjohnst86
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some initial thoughts before I do a deeper review
|
I opened an alternative (PR #146), but I'll leave this here so you can compare |
lwjohnst86
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some additional comments
lwjohnst86
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some additional comments
…k-datapackage into feat/required-rule
lwjohnst86
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice progress! Some more comments 😁
| if not field_name_match: | ||
| return [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This amounts to silently ignoring incompatible JSON paths for now.
lwjohnst86
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Supperrrr nice!! 🎉 Great job 😁 🦾
Description
This PR handles the special case of requiring a field to be non-null by subclassing
CustomCheckto createRequiredCheck.I thought this was a nice way of splitting out the logic for required rules and that required rules were special enough to warrant their own class.
I also thought it made sense to limit what kind of JSON paths the required rule can be applied to. It makes sense to mark a dict property (e.g.
$.resources[*].title) as required because it is very obvious what it means for this field to be missing.$.resources[*]or$.resources[2]) as required makes less sense to me. "I want the second resource to exist in particular" is a weird constraint. If someone cares about the number of resources, they should be checking the length of the array.$..title: selecting alltitlefields under the root node and then checking if they exist feels circular and unnecessary.➡️ So I restricted
RequiredCheckto sensible paths only, which also made the code simpler.Closes #120
Needs an in-depth review.
Checklist
just run-all