-
Notifications
You must be signed in to change notification settings - Fork 54
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
Schema parsing - Permit opaque key-values in Property schema #44
Comments
@robfig That's not quite what that part of the spec means. The The problem here is that the spec is clear that implementations SHOULD ignore keywords they do not support. I had thought that there was a MUST NOT error, but I guess not. I might add that in the next draft. I think it is SHOULD be ignored rather than MUST because it would be perfectly valid for an implementation to treat such keywords as extra data like |
So you're saying that additional definitions are not required to be collected under a "definitions" keyword, but the example from the link:
could equivalently be
? I'm having trouble reconciling that meaning with the linked section on json-schema.org, but it seems like you know what you're talking about. In that case, I suppose the right way to allow opaque key/values at this level in the document would be to continue to attempt to parse the values as a definition, but ignore any errors that result instead of treating them as fatal. How does that sound? |
add a unit test to verify the behavior fixes qri-io#44
Well, I'm the "handrews" in draft-handrews-json-schema-01 😝 The example you gave saying that those things would be equivalent is not correct, though.
I'm not sure why you are focused on definitions here, to be honest. Adding a custom extension keyword such as |
Thanks for filing this @robfig. Totally agreed the error you've encountered is a bug that needs fixing. I think @handrews has articulated the we should try to tackle here:
I think you're totally right to point to the poor assumption this lib currently makes in assuming everything is a definition. We should be doing what the spec says and ignore unsupported keywords. However, one behavior I'd like to keep is not just ignoring unrecognized keywords, but also giving them back if a user were to ever Thanks so much for your PR, the unit test you've provided is great, but I agree the solution needs to be a little more robust. I think we should refactor the lib to carry deserialize unknown values to opaque values instead of "extra definitions", and re-add any opaque values on |
The mismatch in the second example between $ref and the location of the definition was unintentional. I meant it to be this:
I'm focused on definitions here because that's what this implementation is treating my opaque keyword as, instead of ignoring it as I would prefer. In your last comment, you said that it was allowed to do so.. that might be true, but it's also allowed to not fail to parse a schema with an opaque keyword, and that's arguably the more helpful behavior. |
@robfig I'd be happy to work with you on the change, I can write up a rough outline of a PR we'd accept if you're ok with implementing the change |
hahah looks like we came to the same conclusion @robfig 😄 |
Hey all,
The json schema should be fixed but to get something fast of the ground it would be handy to have some kind of relaxed syntax check option. Thanks for your work and the jsonschema lib in any case! |
I'm also blocked on this issue for a project. Can I help move things forward somehow?
Is it reasonable for a user to expect that json.Marshaling a parsed jsonschema.RootSchema would be lossless? Is there a well-defined use case that would require this behavior? The standard library, for example, offers no such guarantees, nor provides easy ways for users to implement it themselves. |
@b5 for some reason I didn't notice this part before:
Now that draft 2019-09 (formerly known as draft-08 but we switched to dates for meta-schema versioning) is out, you should take a look at the recommended output formats, specifically for collecting annotations (the output format is also for error reporting, and I think most of the examples focus on that- we should add more annotation examples). We considered saying that unknown keywords SHOULD be collected as annotations, but annotation-collecting is an optional feature (we didn't want to suddenly make all existing validators non-conforming by requiring a whole new concept to be implemented). But that's basically what it sounds like you want to do, so I'd recommend taking a look at how 2019-09 specifies that should work. |
Currently, this schema is valid according to https://www.jsonschemavalidator.net/
But it can not be unmarshaled, receiving this error:
That is due to this code, which assumes any extra key must be a Definition:
The relevant portion of the spec says that definitions must be collected under a "definitions" key
https://json-schema.org/latest/json-schema-validation.html#rfc.section.9
So, it seems like the the code should be updated to pull out just the "definitions" key, and then apply the "parse the values of each key under that as a Schema".
If you agree, I will add unit tests for this case and make a pull request.
The text was updated successfully, but these errors were encountered: