-
Notifications
You must be signed in to change notification settings - Fork 79
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
InteractionOutput - no schema/schema.type and the expectations of the value() function #1243
Comments
That is a big question, maybe, but anything that validates the JSON Schema meta schema is valid: https://github.com/json-schema-org/json-schema-spec/blob/draft-handrews-json-schema-validation-00/schema.json My bigger question is why we are looking inside a data schema, it should be just "passed over". If it is validation, the whole property is a schema, with action input or output etc. |
Because we are not using the schema just to validate the payload but also to guide the decoding of the payload. Basically, having the schema allows us to convert non-JSON content types to Javascript objects that can be later validated with the schema.
Given what is said above I think that for us a valid schema (to be used in the function validSchema(schema) {
return schema.type != null || schema.const != null || schema.enum != null || schema.oneOf?.reduce((acc, val)=> acc || validSchema(val), true)
} with P.s. I'd probably prefer that |
Hi, I have following use case:
For example, I have the following property definition "state": {
"title": "state",
"description": "current state machine state if state machine present",
"const": false,
"readOnly": true,
"writeOnly": false,
"type": "string",
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"forms": [
{
"href": https://laptop-f60cu35d:8083/spectrometer/ocean-optics/USB2000-plus/state,
"op": "readproperty",
"htv:methodName": "GET",
"contentType": "application/json"
}
],
"observable": false
}, state is a string property, but it can be optionally wot-bundle.min.js:69468 Uncaught (in promise) Error: Invalid value according to DataSchema
at InteractionOutput.<anonymous> (wot-bundle.min.js:69468:23)
at Generator.next (<anonymous>)
at fulfilled (wot-bundle.min.js:69369:58) Since oneOf claims that the type can be more than one, if I skip the type field altogether, "state": {
"title": "state",
"description": "current state machine state if state machine present",
"const": false,
"readOnly": true,
"writeOnly": false,
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"forms": [
{
"href": https://laptop-f60cu35d:8083/spectrometer/ocean-optics/USB2000-plus/state,
"op": "readproperty",
"htv:methodName": "GET",
"contentType": "application/json"
}
],
"observable": false
} I get another error: wot-bundle.min.js:69453 Uncaught (in promise) Error: No schema type defined
at InteractionOutput.<anonymous> (wot-bundle.min.js:69453:23)
at Generator.next (<anonymous>)
at wot-bundle.min.js:69372:71
at new Promise (<anonymous>)
at __awaiter (wot-bundle.min.js:69368:12)
at InteractionOutput.value (wot-bundle.min.js:69438:16)
at updateState (App.svelte:44:89) So I am unable to use oneOf at all.
background_correction": {
"title": "background_correction",
"description": "set \"AUTO\" for Seabreeze internal black level correction, \"CUSTOM\" to load your own background, or None for no background correction",
"const": false,
"default": null,
"readOnly": false,
"writeOnly": false,
"oneOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"enum": [
"AUTO",
"CUSTOM",
null
],
"forms": [
{
"href": "https://LAPTOP-F60CU35D:8083/spectrometer/ocean-optics/USB2000-plus/background-correction",
"op": "readproperty",
"htv:methodName": "GET",
"contentType": "application/json"
},
{
"href": "https://LAPTOP-F60CU35D:8083/spectrometer/ocean-optics/USB2000-plus/background-correction",
"op": "writeproperty",
"htv:methodName": "PUT",
"contentType": "application/json"
}
],
"observable": false Since my allowed values are "AUTO", "CUSTOM" and None, the type should be one of string or null. In this case, the type field and enum field contradict one-another for me. For both the above examples, the python side of my code is sensible in a pythonic fashion, I generate the above from following code: class MyObject(Thing):
state = String(default=None, allow_None=True, URL_path='/state', readonly=True,
fget= lambda self : self.state_machine.current_state if hasattr(self, 'state_machine') else None,
doc='current state machine state if state machine present') #type: type.Optional[str]
background_correction = Selector(objects=['AUTO', 'CUSTOM', None], default=None, allow_None=True,
URL_path='/background-correction',
doc="set 'AUTO' for Seabreeze internal black level correction, 'CUSTOM' to load your own background, or None for no background correction") #type: typing.Union[str, None] The String and Selector objects are to be taken as meaningful python objects. Since it makes "pythonic sense", I really cannot change it and would like to account for 'allow_None' in the TD that I generate instead. |
I did not look into it more closely but I think you assume that Maybe w3c/wot-thing-description#1234 is relevant. |
That would make sense why it does not validate correctly. However what if I want The NullSchema is written as follows in TD:
What I really do is serializing None type of python which turns out to be null and it is exactly the suggested use case as per doc above for my python code you can see in previous comment. I still think I am missing something conceptually and if someone can explain that would help. Thanks in advance. |
Also serializing None to "null" instead of null does not make sense. |
This issue got diverted a bit but @VigneshVSV 's problem is not about null. null should not be represented as |
a plain null also raises an issue: "state": {
"title": "state",
"description": "current state machine state if state machine present",
"const": false,
"readOnly": true,
"writeOnly": false,
"oneOf": [
{
"type": "string"
},
{
"type": null
}
],
"forms": [
{
"href": "https://LAPTOP-F60CU35D:8083/spectrometer/ocean-optics/USB2000-plus/state",
"op": "readproperty",
"htv:methodName": "GET",
"contentType": "application/json"
}
],
"observable": false
}
the TD playground says:
both with and without the type field |
Yes the value of type must be a string, I meant the payloads which are delivered. Those have to be |
By the way, this issue shows up even for our test thing: http://plugfest.thingweb.io:8083/testthing -> The void actions simply do not work |
I see, POST http://plugfest.thingweb.io:8083/testthing/actions/void-void reports I tried it locally and it works fine EDIT: I pulled the node-wot updates to plugfest.thingweb.io. |
PR #1230 reports/fixes/adjusts the case for
schema == null
(no expected value) forvalue()
function reportingundefined
.Anyhow, there is a much broader issue:
schema.type == null
since we useoneof
Relates also to:
The text was updated successfully, but these errors were encountered: