GithubHelp home page GithubHelp logo

Union Types and errors about jsv HOT 8 CLOSED

garycourt avatar garycourt commented on July 21, 2024
Union Types and errors

from jsv.

Comments (8)

garycourt avatar garycourt commented on July 21, 2024

There is no way the validator could know which "system" type the user is intending to use. My suggestion is to examine the error message, look for errors caused by 'urn:multibody#/properties/system', then write some logic that crafts a custom error message for the user.

from jsv.

gasi avatar gasi commented on July 21, 2024

@garycourt First of all, I’m a big fan of JSV and we use it for a couple of projects at @zynga. Do you think it’d be valuable if the validator kept score of how deeply it can validate a given type from a union type and then report the error that occurs the deepest in the validation tree instead of at the top-level where none of the types from the union type match? I believe this would greatly improve the friendliness of JSV and usefulness for creating error messages in scenarios where user data is validated. If you generally like the idea, we could look into building a prototype implementation. Please let me know.

from jsv.

garycourt avatar garycourt commented on July 21, 2024

Thank you very much! I'm always happy to hear from people using my work. :)

I have thought about providing a better error message in this scenario, but at the time couldn't think of a way to make the message intuitive or correct. The solution you provide may work in some (or most) cases, but it still makes the assumption that the likely error is nested deeply. One solution I could implement would be to to include the sub-error reports for each union type. Then the user (you) could decide which sub-error report is the correct one.

from jsv.

gasi avatar gasi commented on July 21, 2024

Seriously, JSV is the best validator I have used and it’s been really fun formalizing our JSON protocol using it 😃

You’re right, using the depth of the error is not the right metric for measuring match. How about the number of errors per type? It’d be like the Levenstein distance between the schema and the input: How many errors away am I from a valid type? Alternatively, it’d probably be good to allow the user to choose getting full schema sub-error reports as you suggest. For the latter I’m just concerned it might be information overload for the user.

For JSON schema draft 03, this functionality would be implemented here, right? https://github.com/garycourt/JSV/blob/master/lib/json-schema-draft-03.js#L157

from jsv.

gasi avatar gasi commented on July 21, 2024

BTW, do you know any good tools for generating documentation from JSON schema? The best I found so far is mattyod/matic#1 but it doesn’t support references that JSV accepts.

from jsv.

garycourt avatar garycourt commented on July 21, 2024

Yes, that's the section that would implement this functionality. A distance equation is an interesting idea, and would likely be the best solution for providing a more precise error message. But the problem still remains that it is still an assumption at what union type the user was trying to use. Although this behaviour could be setup behind an environment option.

I'm afraid I have never researched any JSON Schema documentation tools before.

from jsv.

themihai avatar themihai commented on July 21, 2024

@gasi did you find any good tool for generating documentation from JSON schema ? matic doesn't support schema v4 . JSV seems dead.

from jsv.

gasi avatar gasi commented on July 21, 2024

@themihai I have not, sorry. I’ve moved projects since and don’t use JSON schemas in my day-to-day work anymore.

from jsv.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.