-
-
Notifications
You must be signed in to change notification settings - Fork 308
Suggestion: String JSON Schemas as shortcut for $ref #1078
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
Comments
Thanks for the suggestion! I think it's a really interesting idea, and it shouldn't be very hard to implement. |
This would have complex consequences. For example, what are the annotation results now? I'm generally against making these complex things more complex and potentially more confusing. |
My thought was that the complexity and consequences of having such shortcuts already is taken care of by implementors because of the boolean schema. Can the same rules and arguments that lead to the boolean schema be used to support this feature or will it have different impact on things like additionalProperties and so on? |
So the boolean schemas don't have any annotations or provide any assertions. As a result, they have no impact on these other keywords, which rely upon those annotation and assertions. However, an implicit Another point is output. Currently there are two location indicators in the output format, |
I don't want to open this can of worms right now, and we have other issues we DO need to solve. It's not uncommon there seems to be something that could be made simpler or a shortcut added, but it's often it's that way for a reason. |
No it doesn't. In fact it fixes some of the complex consequences of allowing |
I'd have to read up on what was said, but I can't imagine how this would fix any issues, as it wouldn't be in stead of allowing $ref siblings. |
I've floated this idea before, myself. I don't think we permit strings anywhere that schemas may be found, and I'm not aware of any historical reasons that would conflict. |
I added support for this in Hyperjump JSC (the engine behind the validator implementation). That would allow someone to create a dialect that supports string references. I'm not providing such a dialect, just the tools to configure a dialect with that functionality. I did this as a proof of concept. I learned that it is indeed very easy to implement (3 lines of code) and there aren't any hidden complexities as far as I can see. |
I think there is no technical reason that this could not be supported and behave like a schema with only a $ref keyword, but I am against it as it negatively impacts readability. with the |
I doubt it will cause any more confusion than when we introduced boolean schemas. Basically, we said, "Here's draft 6! And BTW now you can use booleans everywhere you can use a schema: Yeah, maybe the learning curve is a bit steeper, but I don't think it's sufficiently steeper to cause worry. |
I think the complexity will come in trying to enforce URIs in the strings. Currently our only mechanism for that is by using However, we use |
FWIW, I was able to implement this in my library in about three minutes. |
A schema is either an object or a boolean. What if there was a third option (string) that is a shortcut for
$ref
?So instead of models like this
You get
The text was updated successfully, but these errors were encountered: