labthings / python-labthings

Python implementation of LabThings, based on the Flask microframework
GNU General Public License v3.0
18 stars 2 forks source link

Invalid thing description for nullable fields #267

Closed rwb27 closed 3 years ago

rwb27 commented 3 years ago

Describe the bug If any properties/actions have schemas where any of the fields have allow_none=True, the thing description is invalid, because it will contain a schema that looks like:

{"type": ["string", "null"]}

Lists are valid in JSONSchema, but are not permitted in Thing Description DataSchema objects.

Expected behaviour List types should be converted to multiple schemas, and combined using oneOf. This is valid in both JSONSchema and Thing Description. For example, fields.String(allow_none=True) should render as:

{
    "oneOf": [
        {"type": "string"},
        {"type": "null"}
    ]
}