-
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
JSON Schema for Thing Model #972
Comments
From what I understand, the TM will be rather flexible to point that only an |
The idea that was discussed was that it would be ideal having a patch (between the 2 schemas) or a base schema that is the same for both (TD and ThingModel) and that we can easily point to the differences. Not sure though if this is possible... |
I think that I at least don't have the knowledge on how to do a patch between two schemas. Sorry to ping you like this @handrews but is there way to have a schema that has
{
"properties": {
"id": {
"type": "string"
}
},
"required": ["id"],
"type": "object"
}
{
"properties": {
"id": {
"type": "string"
}
},
"type": "object"
} We would need a solution that reduces writing it twice. I have thought of doing a Here is the schema in question by the way: https://github.com/w3c/wot-thing-description/blob/master/validation/td-json-schema-validation.json |
@egekorkan JSON Schema is an additive constraint system, so once you've applied a constraint you can't remove it. Each subschema produces a validation result that depends on the instance and the subschema's keywords. That validation result doesn't "remember" how it was produced, so you can't negate any of the reasons. When you say "writing the whole structure twice" do you mean because you have What draft of JSON Schema are you working with now? (FYI, OpenAPI 3.1-rc0 is using draft 2019-09, and OpenAPI 3.1 final will used the next draft, due out before the end of the year so probably draft 2020-12, so we expect that next draft to be very broadly implemented for not just validation but also code generation and other use cases). 2019-09 and 2020-12 have better extensibility, and while a custom keyword vocabulary still can't remove constraints, you could have a custom keyword that applied |
Thank you for responding quickly!
We are in draft7 but I will update it to 2019-09. I didn't know about the release date of 2020-X and the changes it brings so I didn't consider it that much. What you are proposing seems to be exactly what we want, i.e. a custom keyword that applied required at depth.
Yes, I think :) Below would be a more concrete example as if the
{
"$schema ": "http://json-schema.org/draft-07/schema#",
"$id":"myid",
"type": "object",
"properties": {
"title": {
"type": "string"
},
"links": {
"type": "array",
"items": {
"type": "object",
"properties": {
"href": {"type": "string"},
"rel": {"type": "string"}
}
}
},
"security": {"type": "string"}
},
"required": ["title"]
}
{
"$schema ": "http://json-schema.org/draft-07/schema#",
"definitions":{
"simpleSchema":{
//schema above, this will be located in another file of course
}
},
"type": "object",
"$ref":"#/definitions/simpleSchema",
"properties": {
"links": {
"type": "array",
"items": {
"type": "object",
"required": ["href"]
}
}
},
"required": ["title","security","links"]
} So in here, to be able to say that |
@egekorkan yeah, the That means people can write plugin systems to load vocabulary handlers. We've been working on being more clear about what a keyword can and can't do, so there are reasonable bounds on the plugin interface. Hopefully 2020-12 will be more clear on that. Exactly what will be in 2020-12 is still in flux, but there are two proposed breaking changes:
While the |
Alright, even more motivation to properly understand meta-schemas and 2019-09 for me :) |
Good to know. And yeah, the {
"type": "array",
"items": [{"type": "boolean"}, {"type": "integer"}],
"additionalItems": {"type": "string"}
} style usage, which would become {
"type": "array",
"prefixItems": [{"type": "boolean"}, {"type": "integer"}],
"items": {"type": "string"}
} seems to have always been pretty rare. The most common example is if you're trying to describe something like a variable-length function argument signature, where the first few arguments have specific meaning and then you can tack on however many arguments of some general type as you want. But that's not a common use case. And everyone is tired of having to say "single-schema The ambiguity, just in case it's relevant, is this: {
"type": "array",
"additionalItems": {"type": "string"}
} at a glance, to most people that looks like it should behave the same as this: {
"type": "array",
"items": {"type": "string"}
} but technically |
In the scripting API task force we can produce an ExposedThing by initially passing in a TD fragment which can be then enhanced with handlers et cetera. Technically the TD fragment we have in scripting is very similar to a TD model (it is aligned with a TD but does not have the same strong requirements). Moreover we also want to have a proper way to validate the input (see w3c/wot-scripting-api#287). The validation we have in mind is to use the JSON schema we already have and remove all all I believe that this new JSON Schema may be also applicable to Thing Model but I also read the following in this thread
What means "most object fields are not required"? I think it would be beneficial to have just one other JSON schema besides the main JSON schema which can be used in multiple use-cases and not multiple JSON schemas. Please not that in discovery a similar input/validation is expected for executing queries. Note: I also found some mentioning of "td model" in the JSON schema provided. Is this mentioning of "td model still" correct? It is also the only appearance. |
From today's TD call:
|
From the scripting perspective (and the need for a partial TD) we need a JSON Schema that is essentially a copy of the JSON schema defined in TD + removing all required terms. The questions is whether this works for ThingModel as well or there are mandatory terms like title ... |
It may help the discussion to have a look at those two PRs about Partial TDs: w3c/wot-architecture#577 w3c/wot-scripting-api#289 (still a draft).
Like mathematicians wonder if P = NP, we have our question: PartialTD = ThingModel ? 🤣 |
By the way, once this is decided, I would like to provide small scripts that basically take the original schema and do the changes on it. This way, we would avoid discrepancy between different schemas when the TD vocabulary changes. |
@egekorkan if the schema isn't too complex in structure, you can just write it without the |
@handrews the schema is sadly a bit too complex at the moment. Nothing unusual or difficult to understand but big for sure: https://github.com/w3c/wot-thing-description/blob/master/validation/td-json-schema-validation.json Do you recommend actually manually removing the unwanted keywords? I would still store the differences but also provide a script to generate them from the main schema. |
@egekorkan yeah that looks like a reasonable but non-trivial schema. When you have a lot of references it's hard to layer in more constraints and have all of the references reach the layered definitions. Draft 2020-12's If you store the differences as JSON Patch or JSON Merge Patch (the media types I listed above), your entire script is basically |
Thanks for the suggestion it may help the definition of the algorithm that I am writing for partialTDs. |
After having some internal discussion about the placeholder concept in Thing Models, the TM JSON Schema needs some further definitions. To see the motivation lets have this TM snippet: "water": {
"type": "integer",
"minimum": {{WATER_MINIMUM}},
"maximum": 100
} However, this is not working since this is not a valid JSON. The workaround would be "water": {
"type": "integer",
"minimum": "{{WATER_MINIMUM}}",
"maximum": 100
} When it comes to substitution the string have to be converted to an number representation back by removing the '"' character. The proposal would be compliant to the json-placeholder-replacer lib: https://www.npmjs.com/package/json-placeholder-replacer This means that the JSON schema for the TM should provide for number-based terms such as for |
From today's TD call:
|
I think that this PR can be closed now. Swapping to propose closing label |
Closing since we have a TM schema and its generator now. However, there are some really informative comments in this issue. |
The Thing Model can be not used to do validation based on the TD JSON Schema. We need an own JSON Schema definition for Thing Model.
There can be diff file in the future to show the difference between TD and TM.
The text was updated successfully, but these errors were encountered: