-
Notifications
You must be signed in to change notification settings - Fork 63
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
Is the use of "$ref" and "definitions" allowed in TD ? #307
Comments
I had a similar problem before and this was sadly not the solution. This approach would require special parsing method. In other words, a JSON Schema parser/validator will not recognize the definitions key since it is outside the "JSON Schema" found in the properties. |
This reminds me that I want to put something in JSON Schema to facilitate embedding JSON Schema in other documents. It won't get done in this year's last draft (we're almost out of year), but should get some attention in the early 2019 draft. |
We’re almost out of time this cycle as well for the TD. So maybe we should incubate this for the next round, which means intercepting updates to JSON Schema is a possibility. It would be a good idea to understand what kinds of REST APIs a TD can’t model without this and whether they are common in practice in IoT contexts. |
@egekorkan @handrews @mmccool Thank you for your comments ! I understood that above approach is currently beyond JSON-Schema and consequently beyond Thing Description specification. For now, I would repeat schema definitions in each property. |
I'm agree. This seems to be an issue that cannot be solved quickly. I will mark it for a candidate for the next TD version. |
For the record: the JSON-LD mechansim of addressing objects (with In the docs of the RDF vocabulary for JSON schema, there is an example of schema reference done with |
@vcharpenay , if this is a practice already used by OCF, can't we safely assume it does work? |
You mean that |
I was looking at Example 4 in RDF vocabulary for JSON schema document. The example appears to be using something different from |
we should exchange also with WISHI since they have also some discussion about $ref and definitions for SDF |
@sebastiankb @danielpeintner will provide a proposal how this can introduce in TDs. It will also include requirements and use cases for the need. The proposal will be also syncronized with @ToruKawaguchi |
@sebastiankb and I have been tinkering around and would like to share our findings. Since a TD is compliant with the definition of JSON schema document the validation of properties works out-of-the box. Hence we suggest to introduce the new term "definitions" on the top level just like JSON schema does. Let's use the TD example below. You can feed it to any JSON schema validator and it will check whether the properties
Hence one can copy it for example to https://jsonschemalint.com/ and the following instance is properly validated.
So far so good. What is not checked is the To achieve proper checking for action/event DataSchema snippets the proposed approach is to copy the entire "definitions" snippet next to "$ref". Doing so once again any JSON schema validator can check the validation. Does this overhead of copying (if someone wants to prove validation) seem acceptable? Any other thoughts or improvements we could make. We are especially interested in ideas from @handrews since he mots likely has the most expertise in this area. |
based on the discussion during the vf2f meeting we should careful with the $ref usage such as circles. We may to think about to constrain the usage of that kind of features (especially for constrained devices). |
in vf2f meeting it was also requested to collecting more use cases and should be documented |
From today's TD call:
|
Note that |
Thank you for your feedback. I wonder whether this change is just syntactic sugar meaning that even in the past someone could have used |
@danielpeintner Yes, that's essentially true. The differences is that The formal definition of Here's an example using YAML for brevity, with the standard meta-schema plus a keyword $schema: "https://json-schema.org/draft/2020-12/schema"
$id: "https://example.com/foo"
type: object
properties:
foo:
$ref: "https://example.com/bar"
oof:
$ref: "https://example.com/rab"
$defs:
bar:
$id: "https://example.com/bar"
$comment: "pretend some cool schema keywords are here"
someUndeclaredKeyword:
rab:
$id: "https://example.com/rab" In this case, when the implementation loads the schema, it will know that things under This is rather advanced usage so in practice it's not a problem for many people. However, this You could, of course, define an extension vocabulary that specifies the semantics of A lot of what went into 2019-09 and 2020-12 with the keyword taxonomy (identifiers, references, assertions, annotations, applicators, and reserved locations) ensure that keyword behavior is sufficiently well-defined in general that folks can successfully design extensions that fit with the overall system, so things like "which parts of this document are a schema and how does the implementation know that" have been a focus. |
The $ref-based feature is introduced for Thing Models. I propose to evaluate the ref concept for TD in the TD 2.0 version again. |
Can anybody clarify whether it is possible to use "$ref" and "definitions" of JSON schema within a TD or not?
This is partly mentioned in #151 (comment), but was not clear to me what the conclusion is, so I am raising a new issue.
Some existing REST based API requires not only property value itself but also some predefined fields in request/response body, such as id and type of the thing. It is following a design practice to make developers easy to understand what that data is for. In addition, HATEOAS approach requires links field in every response body.
Considering such use case, it is helpful if we could define a data schema separately from each property definition, from both TD readability and size point of view.
In addition, above use case is not suitable for automatic construction of data field by "readall" discussed in #151, so if we want to read all property at once we need to manually define a special property which includes all other properties. In such case, referencing the definition out from that property could reduce the size of TD.
Below is an experimental TD applying $ref and definitions according to above use case just for discussion:
The text was updated successfully, but these errors were encountered: