-
-
Notifications
You must be signed in to change notification settings - Fork 290
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
Standard schema for results, including errors #396
Comments
EDIT: This is now tracking overall output formats, success or failure. See also #530 for more specifics about annotation output. @trajano could you elaborate on this a bit more? Are you talking about input to a specific validator? Or input/results from some other system that you want to use validation with? |
I was thinking that we should have something along the lines of a validation result structure akin to https://docs.oracle.com/javaee/7/api/javax/validation/ConstraintViolation.html For example:
|
That way each application need not develop their own validation error standard messages |
@trajano I like the idea, in some form or another. RFCs generally do not constrain implementations in this way, due to the wide variety of implementation languages, environments, and requirements such as performance vs usability. This idea helps interoperability among users of validators, rather than interoperability in schema processing and outcome. So I don't think this proposal belongs in the spec repo (at least not with its current scope). I see two possible approaches:
|
I really like this:
If it's attractive enough, I would certainly support it in the implementations I'm involved with. |
I think |
@trajano @erayd I'm glad to see multiple people taking interest. I do not have time to focus on this right now, but here is what I would recommend:
|
Closing this issue since it is out of scope of this project. |
I am interested in this. Subscribing for comments, even if only to know which other issue to track. |
There have been a few other issues around error reporting and/or formal definitions of validation results, so I have made an "output" label to track these. I will re-open this and label it, at least until we figure out where all of these concerns should really live. Somewhat related: I'm defining a "recommended" output format for Hyper-Schema, although it is not a strict requirement. It does seem useful, though, which is why I am re-considering whether a recommendation, if not requirement, might be in-scope. The situation in hyper-schema is a little different, though (the mandatory output of the process is much more complex than a boolean result, even ignoring error reporting). |
@handrews should validation results be a vocabulary? I think it would be awesome to have a consistent format/structure/schema for responses that validation implementations can work toward to ensure compatibility to make transferring from one validator to another more seamless. Just a week ago I posted this issue on djv to support a similar, more detailed, error message format to ajv. I think if ajv and djv the two fastest validators have a similar format then it could act as a starting point for a predictable validation result schema. |
@Anthropic I'm not sure I would consider output formats to be "vocabularies", as to me a vocabulary is a set of keywords to use in schemas to either annotate or assert conditions about an instance document. I think output documents are instances (and not also schemas). They can be described by a schema, but they do not constitute a schema as far as I can tell. Unless I am misunderstanding what you mean? I don't think we need a new vocabulary to write a schema describing the output format. When you look at the hyper-schema rewrite, you will see the definition of the output format there. Although it does not include an error reporting format. I have no particular point here, just acknowledging that there is something to this topic and I'm not sure where it fits. |
@handrews I see your non particular point 😉, what I meant was it just felt looking at the ajv error format with |
I'm already doing something similar in my implementation, though it's merely in an object model. I'd have to update that model and make it serializable, but it's not a stretch for me to support something like this. I like the idea of standardizing output. |
Important thing is that validation failures can be deeply nested by
I'm not sure standard way of error reporting is necessary (the only obvious use-case to me is to change one implementation to another and keep same error handling code), but I would implement it. |
@vearutop yeah, the This is off the top of my head and not a serious proposal: If I'm reading your example right you're working with a schema like the following: {
"type": "object",
"properties": {
"root": {
"type": "object",
"patternProperties": {
"^[a-zA-Z0-9_]+$": {
"oneOf": [
{"enum": ["a"]},
{"enum": ["b"]},
{"$ref": "#/cde"}
]
}
}
}
},
"cde": {
"anyOf": [
{"enum": ["c"]},
{"enum": ["d"]},
{"enum": ["e"]}
]
}
} with an instance of: {
"root": {
"zoo": "f"
}
} An error data structure could look something like: [
{
"instanceLocation": "/root/zoo",
"instanceData": "f",
"errors": [
{
"schemaLocation": ["#/properties/root/patternProperties/^[a-zA-Z0-9_]+$/oneOf"],
"validSubschemas": [],
"subschemaErrors": [
{
"schemaLocation": ["#/properties/root/patternProperties/^[a-zA-Z0-9_]+$/oneOf/0/enum"],
"schemaValue": ["a"]
},
{
"schemaLocation": ["#/properties/root/patternProperties/^[a-zA-Z0-9_]+$/oneOf/1/enum"],
"schemaValue": ["b"]
},
{
"schemaLocation": ["#/properties/root/patternProperties/^[a-zA-Z0-9_]+$/oneOf/2/$ref", "/cde/anyOf"],
"validSubschemas": [],
"subschemaErrors": [
{
"schemaLocation": ["#/properties/root/patternProperties/^[a-zA-Z0-9_]+$/oneOf/2/$ref", "#/cde/anyOf/0/enum"],
"schemaValue": ["c"]
},
{
"schemaLocation": ["#/properties/root/patternProperties/^[a-zA-Z0-9_]+$/oneOf/2/$ref", "#/cde/anyOf/1/enum"],
"schemaValue": ["d"]
},
{
"schemaLocation": ["#/properties/root/patternProperties/^[a-zA-Z0-9_]+$/oneOf/2/$ref", "#/cde/anyOf/2/enum"],
"schemaValue": ["e"]
}
]
}
]
}
]
}
] This organizes errors first by the location in the instance that is failing validation, then indicates each schema location against which it fails that may be the cause of the overall failure. Instance locations are plain (non-URI-fragment) JSON Pointers, while schema locations are arrays of URIs with JSON pointer fragments where a new pointer is added to the array whenever you cross a If any of the subschemas were valid, The goal here is to provide all of the key data in a standardized way, but not necessarily the natural language phrasing. So there's nothing here that says "Value not present in enum", because there are many ways that that phrasing might be chosen, not to mention I18N/L10N/A11Y issues. But this approach would let tools display something simple like "No valid |
Since draft-08 is intended to include annotation collection, which would involve a recommended output format, we should really handle a recommended error format at the same time. That would cover all of this issue, I believe, so I'm adding it to the milestone. |
I think it is worth adding |
Annotation Discussion on SlackThere was a good chat in Slack so I have added it if you click below. View annotation conversation@vearutop: @handrews: @vearutop: @handrews: @vearutop: @handrews: @vearutop: @handrews: @vearutop: @handrews: @vearutop: @handrews:
@vearutop: @handrews: @vearutop: @handrews: @vearutop: @handrews: @gregsdennis: @Anthropic: Henry, like Greg, I find this an illuminating conversation, in fact it has been more interesting to me than the bulk of the 90 comments on the error structure issue, perhaps some of it should be added there since Slack will delete this in future? |
I've tried to make a sample schema and response output, please check: Same schema and test cases with The idea is to provide a flat response (array of causes) for top level schema. A single cause is a structure of
For multiple schema keywords ( References create a new I don't like having all causes in a single flat list because non top level causes add noise but does not help you to analyze the root cause until you rebuild flat list into hierarchy. |
Hi guys, I am new to json schema, implementing a validation library in Erlang. Very interested in this discussion as a framework developer. As a suggestion to reach consensus I suggest we summarize the points made here into an Enhancement Proposal, eg in a project wiki page? I have read through this mega-thread and conclusions have already been made, which detailed concisely might align the community. |
@expelledboy that's a good idea, and it's been suggested before. I'll try to write up a new issue that summarizes where we are with this one. Then we can close this out. |
@vearutop I agree with the idea of the @gregsdennis @vearutop
Then for each level the Annotation/Error Description Object could be optionally alternated with an Enhanced Annotation/Error Description Object with more detail, message ids, data, embedded schemas, etc... to be decided... this gives implementations a lot of choice while not requiring anyone to go too far from their comfort zone until enough people request it of them. I feel an implementation: |
@gregsdennis Could I suggest rather just starting a wiki page, and continuing the discussion here? We may just end up with another mega-thread. |
@expelledboy I'm not sure that's in line with the organization of the repo. Also, this topic is still very much in discussion. I'll discuss it over on Slack with the powers that be here. |
FWIW, for the purposes of troubleshooting what went wrong and providing the right level of information to the developer (balancing simplicity with verbosity) we settled on this: https://github.com/retrosight/rest/blob/master/guidelines.md#errors-when-4xx and |
Let's also discuss how we can expose that My proposal based on previous structure is: {
"valid": false,
"causeContext": [
{"keyword": "required", "schemaPath": "#/required", "dataPath": "#", "valid": false, "causeContext": [
{"dataPath": "#/foo", "valid": false},
{"dataPath": "#/bar", "valid": false}
]}
]
} or this response {
"valid": false,
"causeContext": [
{"keyword":"required", "schemaPath": "#/required", "dataPath": "#/foo", "valid": false},
{"keyword":"required", "schemaPath": "#/required", "dataPath": "#/bar", "valid": false}
]
} Not sure which one would be better. |
I don't know why you'd treat This is about the structure, though, not standardized messaging. |
I think I just got a rubber duck epiphany,
|
Closing this issue in favor of the summary. ☝️ (Please read it.) |
Closed in favour of #643 as requested |
@gregsdennis Should the discussion continue here, or there? Will you continue to maintain the first comment with updated conclusions? We determined not to include the data because it could be arbitrarily large, and structure unknown. I think the error result fields should be configurable according to the use-cases, perhaps then we should detail also the use-cases? |
@expelledboy the preference is that the discussion continues on the new issue. |
The schema provides a way of validating the input, but there should be a standard for the validation results as well.
The text was updated successfully, but these errors were encountered: