I believe both JSONSchema and Thing Description permit additional fields. This means we could add, for example a labthings_python_type field, which provides optional information about the Python type that generated the schema. This might include:
- module and qualified name, allowing the exact type to be imported. This would work really nicely for
pydantic-compatible types.
- a type hint as a string (if it uses builtins) - parsing that safely is likely to be quite hard!
- hints as to whether to reconstruct an
object type as something with attributes (dataclass or pydantic.BaseModel) or something with items (dict or TypedDict).
- special cases like
np.array which aren't pydantic compatible but should have a LabThings wrapper/annotation to make them work.
We'd need to add a field for this in the thing_description._model.DataSchema and populate it when generating the schema.
Just to be clear, I am very keen that this does not replace describing the types properly in JSONSchema. That is, and should remain, the primary way of describing types, as it's cross-language and cross-platform. I am proposing adding some minimal extra information, so that the Python types can match the server more closely. We should continue to test that everything works without this feature, if we choose to implement it.
I believe both JSONSchema and Thing Description permit additional fields. This means we could add, for example a
labthings_python_typefield, which provides optional information about the Python type that generated the schema. This might include:pydantic-compatible types.objecttype as something with attributes (dataclassorpydantic.BaseModel) or something with items (dictorTypedDict).np.arraywhich aren'tpydanticcompatible but should have a LabThings wrapper/annotation to make them work.We'd need to add a field for this in the
thing_description._model.DataSchemaand populate it when generating the schema.Just to be clear, I am very keen that this does not replace describing the types properly in JSONSchema. That is, and should remain, the primary way of describing types, as it's cross-language and cross-platform. I am proposing adding some minimal extra information, so that the Python types can match the server more closely. We should continue to test that everything works without this feature, if we choose to implement it.