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

Schema with pattern re-compute regexp on each validate call #416

Closed
ermakov-oleg opened this issue Feb 9, 2023 · 7 comments
Closed

Schema with pattern re-compute regexp on each validate call #416

ermakov-oleg opened this issue Feb 9, 2023 · 7 comments

Comments

@ermakov-oleg
Copy link
Contributor

Example schema:

{'pattern': '^(foo|bar)$', 'format': 'regex', 'type': 'string'}

https://github.com/Stranger6667/jsonschema-rs/blob/master/jsonschema/src/keywords/format.rs#L284-L294

@Stranger6667
Copy link
Owner

The ‘pattern’ keyword is not relevant here as the mentioned code is only for ‘format’, but indeed it verifies correctness of the input regex by trying to compile it. Not sure whether we can do anything about it besides adding some cache for inputs (but it is a a more broad issue for any validator)

@Stranger6667
Copy link
Owner

Is caching for input strings something that you were thinking about?

@Stranger6667
Copy link
Owner

I guess it could be nice to have a global cache for it - as format is universal and all ‘regex’ format validators could utilise it

@ermakov-oleg
Copy link
Contributor Author

Hmm, really, if you don't specify "format", regexp caches fine.
Then it's just not very expected behavior...

@Stranger6667
Copy link
Owner

I don’t think there is something we can clarify from this library side as the JSON Schema spec describes this - these are two separate keywords that do not affect each others behaviour and target different things. ‘pattern’ keyword is about a pattern defined in the schema, ‘format: pattern’ is about a pattern in the input data

@ermakov-oleg
Copy link
Contributor Author

Oh, really, I misunderstood the specification...
Sorry if I distracted you. I will close this issue.

@Stranger6667
Copy link
Owner

No worries at all! On the contrary - I think it actually an interesting opportunity to explore caching possibilities for the “pattern” format

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants