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

How to convert joi-schema to json-schema? #2253

Closed
yeongjet opened this issue Dec 19, 2019 · 11 comments
Closed

How to convert joi-schema to json-schema? #2253

yeongjet opened this issue Dec 19, 2019 · 11 comments
Assignees
Labels
support Questions, discussions, and general support

Comments

@yeongjet
Copy link

No description provided.

@yeongjet yeongjet added the support Questions, discussions, and general support label Dec 19, 2019
@yeongjet yeongjet changed the title How to covert to json-schema? How to convert joi-schema to json-schema? Dec 19, 2019
@hueniverse
Copy link
Contributor

Unfortunately, no community resources were available to help resolve this issue after two weeks, and it is being closed. We close unresolved community issues to keep the issue tracker organized and effective. Please check https://hapi.dev/support for other support options.

@hueniverse hueniverse self-assigned this Jan 4, 2020
@simlu
Copy link

simlu commented Mar 31, 2020

Would love to see this is as well... Especially since json-schema validation is much faster than joi validation this would be a great way to allow for speed up where appropriate.

@Marsup
Copy link
Collaborator

Marsup commented Apr 1, 2020

json-schema is also less powerful, some things can't be converted to json-schema. Honestly this likely will never happen. Performance especially in the latest versions is not bad at all, if you're trying to squeeze microseconds, maybe it's not the right tool for you.

@simlu
Copy link

simlu commented Apr 1, 2020

@Marsup Makes sense that it's less powerful. Most things can however be converted.

It's not about microseconds, it's about percentage. If a single check takes only 10ms but you are doing 1k of them, shaving 9ms is a lot :)

Anyways, there is now a project https://www.npmjs.com/package/joi-to-json which seems to not rely on internals of joi. So that's really the way to do this going forward.

@Marsup
Copy link
Collaborator

Marsup commented Apr 1, 2020

What's important is the percentage per request, not how many you can do in a loop. If you lose 5ms on a request that takes 50ms, optimizing it to 2ms won't even be noticeable. I see your point but I don't think it matters, people care too much about joi performance when most of the time is wasted in your own code.

@simlu
Copy link

simlu commented Apr 1, 2020

@Marsup Well, I just replaced joi with custom validation to change overall time for a client request from ~1050ms to ~650ms. And yes, we want and need the validation. So call me biased :)

@Marsup
Copy link
Collaborator

Marsup commented Apr 1, 2020

Then that's a good bench case and we're open to that, can you somehow anonymize that and submit it to see if there's something specific going on?

@simlu
Copy link

simlu commented Apr 1, 2020

@Marsup Sure. Do you want me to open a new ticket?

@felipecrs
Copy link

felipecrs commented Sep 18, 2020

This would be very useful, since:

  1. joi can be used for validating configuration files, read by cosmiconfig so they can be in any format
  2. Defining a JSON schema you earn autocompletion for free for JSON and YAML files in modern editors (such as VSCode).
  3. There are tools over there which can automatically generate documentation from JSON Schemas.

@liesislukas
Copy link

i would find it useful too. export to JSON. this would allow to build some automation tools around joi. in my case - UI element to copy part of schema and drop it on another validator. just good joi-json-joi conversion is needed

@wll8
Copy link

wll8 commented Dec 6, 2022

This is useful feature since json-schema has many tools that depend on

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
support Questions, discussions, and general support
Projects
None yet
Development

No branches or pull requests

7 participants