labthings / labthings/labthings-fastapi
Pass Python type information through the Thing Description
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 9
- Forks
- 4
- PR merge metrics
- No merged PRs in 30d
Description
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
objecttype as something with attributes (dataclassorpydantic.BaseModel) or something with items (dictorTypedDict). - special cases like
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.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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating thing_description._model.DataSchema and the schema-generation entry point that populates it. Define the minimal optional Python-type metadata described in the issue, preserve JSONSchema as the primary description, and verify that schema generation still works when the metadata is absent.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- fastapi, python
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100