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
Need support of a local description of a property using $ref #239
Comments
@nitmws Can you describe a little bit how this compares to the canonical solution of using { "allOf": [
{"$ref": "#/definitions/aURI"},
{ "description": "Local description of the uriProperty1",
"title": "Local title of uriProperty1" }
] } |
@awwright this is almost identical to #98. The only difference is that #98 introduces the Honestly, I like this better. But if you want use cases, there is an enormous amount of discussion in #98 already. Including from other people outside of the usual suspects that comment on every issue here. |
Thanks for both suggestions, I'll have a look into #98. |
@nitmws "allOf" is not described to do what you want. If you have "description" and "title" both inside and outside of your referenced schema (the one at "#/definitions/aURI" in @awwright's example), the JSON Schema spec provides no guidance on whether one take precedence over the other, or whether both should be used. I don't know why @awwright considers this a solution to the problem. Of course a documentation-generating application could just pick one of those behaviors and go with it, but that takes the expression of intent out of the hands of schema authors which I believe is where it belongs. |
@nitmws It's been our solution before, and it follows from the definition of the keywords. Schemas always add restrictions to an instance, and keywords in a schema are typically independent of each other. Suppose we have a record that specifies the outcome of a game and which user won against who. A schema "identifier.json" specifies what a database identifier must look like. Suppose "identifier.json" looks like And suppose the match record looks like: { type: "object",
properties: {
winner:
{ allOf: [
{ $ref: "identifier.json" },
{ description: "The winner of the match", pattern: "^USER-" }
] },
loser:
{ allOf: [
{ $ref: "identifier.json" },
{ description: "The loser of the match", pattern: "^USER-" }
] },
}
} Which is the same as this: { type: "object",
properties: {
winner: { type: "string", maxLength: 20, description: "The winner of the match", pattern: "^USER-" }
loser: { type: "string", maxLength: 20, description: "The loser of the match", pattern: "^USER-" }
}
} The "description" is describing the semantics of the instance in prose -- and specifically saying it's not just a string, it's a string that identifies a winner (or a loser). You can't put a winner ID in the loser instance or vice-versa. So I think the use of "allOf" is warranted here. This doesn't change if we add a "description" keyword to "identifier.json" too, both of those keywords will still apply to describe the instance. It's just messy to describe because it can only be done with "allOf" (or with a hypothetical superset of JSON/JSON Schema where repeated keywords are allowed). |
I try to match comments above against the JSON Schema draft 5:
A quick practical check: I've created a JSON Schema with this allOf design with my JSON Schema editor: it shows both objects as separated objects, with their individual descriptions. A user of our JSON Schema might scratch his head what description is the right one. In general I feel this |
I think it's clear that we are getting multiple people calling for the same requirements, with several having identical use cases. I think that's a good call. The need has presented itself. As such, I'm going to increase priority of #98 to high. |
@handrews I'm not sure how I see this behavior is undesirable. @nitmws The definition for "allOf" should say everything you need to know:
So if multiple schemas under "allOf" have a "description" keyword, all of them apply. It is not a validation keyword, so it won't ever cause validation to fail, however it should be saying something true about the instance nonetheless.
Both should accurately describe what the instance is doing (one in general terms, one more specifically). Although it will pass validation, two "description" keywords shouldn't provide contradictory definitions. Which implementation are you testing this against? |
@Relequestual I know we're really eager to get these issues closed, but this is a design issue so we either need consensus, or the author needs to be satisfied that the issue is resolved in some fashion (i.e. covered under another issue). @nitmws Feel free to let us know and/or close the issue if your questions are answered, or otherwise resolved by another issue. |
@awwright it was closed because it's a duplicate of #98, which discusses a superset of this. The fact that you don't see why anyone else wants this is much less important than the numerous people (not even counting the usual suspects) who keep asking for this. Not just individuals on their own but individuals representing larger projects (public or private) as well.
I agree with @Relequestual that this should be consolidated with #98. @nitmws if you feel that #98 does not cover the necessary possibilities could you either add to that and close this one, or explain here why you feel they need to stay separate? (don't worry about examining every comment- if you end up duplicating something in a new comment that's fine). |
As commented earlier:
That's what I requested and this is covered. (... and I have to add that I'll be away from the internet communication in the next days ...) |
I'm sorry to revive this conversation, that surely everyone here is tired of and would like to resolve. After going down the rabbit hole of the very specific problem detailed in the title of this issue, I ended up running in circles through countless issues and then ended at a conclusion that doesn't seem to actually solve the issue referenced in the title. This is an extremely common documentation problem, and what I've walked away with is this "Don't reuse schemas if you want them to have local documentation." Can anybody point me somewhere specific where the issue of overriding/merging/using a simplefield (like description) is discussed, or something I can continually reference to monitor it's progress? Are any of the below true-ish?
Please note: I am pretty sure I've read every issue on this topic between OAS and JSON-Schema discussions |
I'm in the exact same boat, haha |
I'm working for the organisation IPTC creating and maintaining standards for metadata about media assets - and the metadata should be expressed using different formats, one of them JSON. That's the background for this use case:
Use of JSON-Schema: schema objects are defined for a reuse by properties under
definitions
. They represent generic things like a string with format uri or an object with (sub-)properties which are required by many properties. Then properties are specified with a$ref
pointing at the required schema object.Use of description for documentation: a key feature of these standards is to include a definition of all properties - expressed by a
description
in the JSON Schema. All properties must have their specific definition, all (sub-)properties in a referenced object must have their specific definition.The issue I encountered in JSON Schema v 5 is: The Core specification defines in section 7 All other properties in a "$ref" object MUST be ignored. First: this language is misleading as it apparently means that all local keywords of a property using $ref should be ignored - and nothing in the referenced object should be ignored.
But the key issue regarding documentation is: if a property using
$ref
has a localdescription
and/ortitle
they are ignored anddescription
and/ortitle
of the referenced objects replace them.This is implemented by vendors of JSON Schema editors.
Example:
Result regarding the definitions of properties:
Requested change of the JSON Schema specification section "Schema references with '$ref'":
Thanks for considering this change request.
Note on using
description
andtitle
in a JSON Schema:I've read #175. The IPTC experience of the use of JSON or XML Schemas by developers is that they look at what an JSON or XML editor provides as inline documentation and it is very hard to convince them having to look at an external documentation. To protect a key feature of a standard, the same use by all parties using it, it is a must for a standardisation body to include at least a basic definition of properties in any kind of file defining a schema. As W3C's XML Schema supports local descriptions of global elements or data types there is a need to be able to do the same for JSON Schema.
The text was updated successfully, but these errors were encountered: