Skip to content

Conversation

@martonvago
Copy link
Contributor

@martonvago martonvago commented Oct 13, 2025

Description

This PR handles the special case of requiring a field to be non-null by subclassing CustomCheck to create RequiredCheck.

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.

  • But marking an array item itself (e.g. $.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.
  • Same for "vague" JSON paths like $..title: selecting all title fields under the root node and then checking if they exist feels circular and unnecessary.

➡️ So I restricted RequiredCheck to sensible paths only, which also made the code simpler.

Closes #120

Needs an in-depth review.

Checklist

  • Formatted Markdown
  • Ran just run-all

@martonvago martonvago self-assigned this Oct 13, 2025
@martonvago martonvago moved this from Todo to In Progress in Iteration planning Oct 13, 2025
"""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)
Copy link
Contributor Author

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

@martonvago martonvago moved this from In Progress to In Review in Iteration planning Oct 14, 2025
@martonvago martonvago marked this pull request as ready for review October 14, 2025 12:05
@martonvago martonvago requested a review from a team as a code owner October 14, 2025 12:05
Copy link
Member

@lwjohnst86 lwjohnst86 left a 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 ☺️ Very neat though!

@github-project-automation github-project-automation bot moved this from In Review to In Progress in Iteration planning Oct 17, 2025
@signekb signekb changed the title feat: ✨ add RequiredRule feat: ✨ add RequiredRule Oct 17, 2025
@martonvago martonvago changed the title feat: ✨ add RequiredRule feat: ✨ add RequiredCheck Oct 17, 2025
@martonvago
Copy link
Contributor Author

I opened an alternative (PR #146), but I'll leave this here so you can compare ☺️

Copy link
Member

@lwjohnst86 lwjohnst86 left a comment

Choose a reason for hiding this comment

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

Some additional comments

Copy link
Member

@lwjohnst86 lwjohnst86 left a comment

Choose a reason for hiding this comment

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

Some additional comments

@martonvago martonvago moved this from In Progress to In Review in Iteration planning Oct 28, 2025
@martonvago martonvago requested a review from lwjohnst86 October 28, 2025 11:09
Copy link
Member

@lwjohnst86 lwjohnst86 left a 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 😁

@github-project-automation github-project-automation bot moved this from In Review to In Progress in Iteration planning Oct 28, 2025
Comment on lines +110 to +111
if not field_name_match:
return []
Copy link
Contributor Author

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.

@martonvago martonvago moved this from In Progress to In Review in Iteration planning Oct 29, 2025
@martonvago martonvago requested a review from lwjohnst86 October 29, 2025 10:28
Copy link
Member

@lwjohnst86 lwjohnst86 left a 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 😁 🦾

@github-project-automation github-project-automation bot moved this from In Review to In Progress in Iteration planning Oct 29, 2025
@lwjohnst86 lwjohnst86 merged commit df6bd68 into main Oct 29, 2025
6 checks passed
@lwjohnst86 lwjohnst86 deleted the feat/required-rule branch October 29, 2025 19:03
@github-project-automation github-project-automation bot moved this from In Progress to Done in Iteration planning Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Rules with type="required"

3 participants