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

wip: support empty and recursive schemas #496

Closed
wants to merge 9 commits into from

Conversation

tscholak
Copy link
Contributor

@tscholak tscholak commented Jan 1, 2024

The main contribution of this PR is an enhanced to_regex function, which addresses both empty and recursive JSON schemas. I utilize the capabilities of the regex library, which notably supports recursion. Here's how this is achieved:

Handling Empty JSON Schemas

We identify empty schemas (i.e., {} or True) as those that should accept any valid JSON. To achieve this, a specific regex pattern for JSON values is implemented. This pattern is designed to be universally accepting.

Addressing Recursive JSON Schemas

The core of handling recursion lies in the use of named capture groups within the regex patterns. These groups are critical for creating references within the regex that can call back to themselves or to other groups.

The regex library's support for recursion is fundamental to this approach. It allows for patterns that can reference themselves, enabling the definition and validation of recursive and self-referential schemas. This is particularly important for complex schemas where elements may be nested within themselves or have mutual references.

Copy link
Member

@brandonwillard brandonwillard left a comment

Choose a reason for hiding this comment

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

Could you provide a high-level explanation of (or link to) the approach and how it will address empty and recursion JSON schemas?

@tscholak
Copy link
Contributor Author

tscholak commented Jan 2, 2024

@brandonwillard I added a description to the PR.

I realize now that my approach is not going to work, because interegular does not support calls to named groups (like (?&name)).

@brandonwillard
Copy link
Member

I'll close this for now, but feel free to reopen if you have questions specific to these changes that you would like us to answer.

@brandonwillard brandonwillard linked an issue May 9, 2024 that may be closed by this pull request
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.

Recursive JSON Schemas
2 participants