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

Question: Can custom format checker be implemented? #171

Open
stephb9959 opened this issue Jan 26, 2023 · 2 comments
Open

Question: Can custom format checker be implemented? #171

stephb9959 opened this issue Jan 26, 2023 · 2 comments

Comments

@stephb9959
Copy link

We have schemas where we need to validate the format of some values: IP Address, Hostname, CIDR, etc...

We had been using json_schema_validator which allows us to specify format validators. However, that library no longer works with our latest schemas.

valijson works flawlessly with our schemas and allows us to use PocoJSON.

Is it possible to replicate this format checking in valijson?

Thank you.

PS Apologies if this was not the right channel to ask a question. I could not find another way.

@tristanpenman
Copy link
Owner

Hi @stephb9959, this is 100% the correct channel for these kinds of questions. It makes sense to me to include the ability to plug in custom format validators. This is something I may not be able to get to right away, due to other commitments. However, if you happen to have anything that you've implemented yourself, I'm more than happy to review that and provide feedback.

@stephb9959
Copy link
Author

Thanks @tristanpenman.

I found the code in your lib and made a hack - like really bad - but it does the job. In validation_visitor.hpp, in visit FormatConstraint, I just added a call to an external function that gets called at the end instead of returning true. It's a hack that does not preserve the elegance of your code. Let me see if I can make it fit without an external function. I'll take some time this weekend and see if I can submit a PR with a real implementation.

Besides that, I love this validator. This saved us a lot of work.

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