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

Consider "API best practices" section #544

Open
awwright opened this issue Feb 3, 2018 · 4 comments
Open

Consider "API best practices" section #544

awwright opened this issue Feb 3, 2018 · 4 comments
Assignees
Labels

Comments

@awwright
Copy link
Member

awwright commented Feb 3, 2018

There should be a section with guidelines for how to write a validator API. The section would be informative (non-normative), on observations on how to best expose the functionality that JSON Schema offers for validation and forward-compatibility.

Topics would include (feel free to edit list/suggest edits):

  • How to import multiple schemas that refer to each other
    • Implementations should offer some sort of collection or registry that schemas are imported to, specifying the URI they were retrieved from.
  • How to report informative and localizable error messages
    • Validators should report the keyword that caused the validation failure, and software should rely on this for writing its own error messages. This might be a property associated with the error, or validators might subclass a ValidationError class, one for each JSON Schema keyword.
    • Validators should also report a full error message, intended for debugging.
  • How to report lists of errors
  • Consider supporting as many old features as possible, and report on deprecated feature usage
  • How to list non-fatal warnings while processing the schema
  • Offer different validation reporting modes, e.g. stop at first validation failure, or collect as many as possible
  • How to report errors for complex rules like "oneOf" or "not"
    • Try and find the smallest change that would cause validation to pass, and suggest making that.
  • How to handle custom vocabulary and add custom assertions/keywords
    • Allow software to register a callback that handles a given keyword
  • How to handle unknown keywords (offer option to report as fatal error, or warning, or ignore)
  • ... and how to handle custom vocabulary that requires asynchronous I/O
  • Offer options for relaxing rules, e.g.
    • precision of floating point numbers if numbers are cast to IEEE floating points
    • handling of null
  • Offering options to patch third-party schemas, e.g.
    • add maxLength properties to most strings because of local implementation memory constraints
  • Offering options to cast certain schemas to native objects at parse-time, e.g.
    • casting certain string properties to native Date objects
@awwright awwright added the core label Feb 3, 2018
@awwright awwright self-assigned this Feb 3, 2018
@carlosaq
Copy link

carlosaq commented Feb 6, 2018

Does any know if there are something ready or only will be start to define?

@awwright
Copy link
Member Author

awwright commented Feb 7, 2018

@carlosaq I'm not sure what you're asking.

@handrews
Copy link
Contributor

handrews commented Feb 7, 2018

@awwright a lot of these things are things that already have issues filed to be resolved as part of the spec work. There should not be an overlap between that and any best practices document work. Some covered by #314 and related issues, others by issues tagged with the "output" label.

Even considered as best practices, this is a large grab-bag of different things. Can we

a.) whittle this down to things that aren't being addressed, and should not be addressed, elsewhere
b.) organize this a bit- there are several different kinds of implementation advice
c.) figure out a heuristic for what really needs to be in a spec appendix and what should go on the web site

@gregsdennis
Copy link
Member

Try and find the smallest change that would cause validation to pass, and suggest making that.

That's some heavy-duty analysis.

Overall I like the idea of this. Manatee.Json already supports many of these. I'd be happy to provide examples of how it's implemented to give some direction.

As @handrews mentioned, I know we already have issues for some of these. #396 comes to mind immediately.

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

4 participants