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

build_regex_from_schema(): Incorrect behavior for oneOf and allOf #906

Open
lapp0 opened this issue May 19, 2024 · 0 comments
Open

build_regex_from_schema(): Incorrect behavior for oneOf and allOf #906

lapp0 opened this issue May 19, 2024 · 0 comments
Labels

Comments

@lapp0
Copy link
Collaborator

lapp0 commented May 19, 2024

Describe the issue as clearly as possible:

Pattern repetition cannot be used when one repetition is dependent on another repetition in and array or object
For example, when handling an array in json_schema.py we use

elif instance_type == "array":
    ...
    items_regex = to_regex(resolver, instance["items"], whitespace_pattern)
    return rf"\[{whitespace_pattern}(({items_regex})(,{whitespace_pattern}({items_regex})){num_repeats}){allow_empty}{whitespace_pattern}\]"

Repetition works with anyOf because the types of items are independent. This is not true for allOf or oneOf.

oneOf and allOf require knowledge of the types of other items in order to produce a valid item.

For example, if we want oneOf("string", "number") with length 2, we cannot use (STRING|NUMBER){2}, we must use STRING{2}|NUMBER{2}

@lapp0 lapp0 added the bug label May 19, 2024
@lapp0 lapp0 changed the title build_regex_from_schema(): Incorrect behavior for anyOf build_regex_from_schema(): Incorrect behavior for oneOf and allOf May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant