Wot-thing-description: Is there a way to set default values for uriVariables?

Created on 13 Apr 2021  路  5Comments  路  Source: w3c/wot-thing-description

Hi,

I was wondering if there is a way to set default values in TD for uriVariables?

The URI Template does not support it after draft v5 and I couldn't find anything in the TD's DataSchema either.

Example Property with non-standard default values:

{
    "uriVariables": {
        "offset": {
            "description": "The number of items to skip before the subset",
            "type": "number",
            "default": 0 
        },
        "limit": {
            "description": "The number of items in the subset",
            "type": "number",
            "default": 1 
        },
        "count": {
            "description": "Request the total number of items in the collection",
            "type": "boolean",
            "default": false
        },
        "sort_by": {
            "description": "The attribute used as comparator for sorting of the collection",
            "type": "string",
            "default": "id"
        },
        "sort_order": {
            "description": "Sorting order",
            "type": "string",
            "enum": ["ASC", "DESC"],
            "default": "ASC"
        }
    },
    "forms": [
        {
            "href": "/items{?offset,limit,count,sort_by,sort_order}",
            ...
        }
    ]
}

_Originally posted by @farshidtz in https://github.com/w3c/wot-discovery/pull/130#r590380965_

PR available JSON Schema

Most helpful comment

I would simply suggest adding default to the DataSchema. Let's decide this in tomorrow's TD meeting.

All 5 comments

JSON Schema allows setting default values in v7 onwards by the use of default keyword.

So is it going to become a part of DataSchema through the "very common subset of the terms defined by JSON Schema"?

Or I have to extend the TD context as Sebastian suggests? It isn't here so I'll have to find use https://schema.org/defaultValue.

@sebastiankb replied here:

TD allows to use terms which are not defined in data schema yet. Information can be found here https://w3c.github.io/wot-thing-description/#sec-data-schema-vocabulary-definition

Or I have to extend the TD context as Sebastian suggests? It isn't here so I'll have to find use https://schema.org/defaultValue.

I am not sure how one extends Data Schema terms but schema.org is not the correct one. This is the correct reference at least: https://json-schema.org/draft/2020-12/json-schema-validation.html#rfc.section.9.2

My personal opinion is that any JSON Schema term that is in the draft 7 can be simply used since you should use a JSON Schema library to do whatever JSON Schema related thing you are planning to do (UI generation, payload generation, payload validation) and they will automatically pick-up any JSON Schema related word, defined in the TD spec or not. As the link above says, it will be ignored by the semantic processors but that is it for me.

Edit: I am opening an issue about what I mean by not knowing how to extend Data Schema terms

I would simply suggest adding default to the DataSchema. Let's decide this in tomorrow's TD meeting.

done

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zolkis picture zolkis  路  5Comments

mkovatsc picture mkovatsc  路  9Comments

egekorkan picture egekorkan  路  6Comments

mlagally picture mlagally  路  5Comments

jmcanterafonseca picture jmcanterafonseca  路  8Comments