diff --git a/src/blueapi/core/context.py b/src/blueapi/core/context.py index 219e736b73..1bd8e482e5 100644 --- a/src/blueapi/core/context.py +++ b/src/blueapi/core/context.py @@ -202,7 +202,9 @@ def __modify_schema__( cls, field_schema: dict[str, Any], field: ModelField | None ): if field: - field_schema.update({field.name: repr(target)}) + field_schema.update( + {"type": f"{target.__module__}.{target.__qualname__}"} + ) self._reference_cache[target] = Reference diff --git a/tests/core/test_context.py b/tests/core/test_context.py index aeb68f31fb..a1f6bdb1a4 100644 --- a/tests/core/test_context.py +++ b/tests/core/test_context.py @@ -121,6 +121,20 @@ def test_add_plan(empty_context: BlueskyContext, plan: PlanGenerator) -> None: assert plan.__name__ in empty_context.plans +def test_generated_schema( + empty_context: BlueskyContext, +): + def demo_plan(foo: int, mov: Movable) -> MsgGenerator: # type: ignore + ... + + empty_context.plan(demo_plan) + schema = empty_context.plans["demo_plan"].model.schema() + assert schema["properties"] == { + "foo": {"title": "Foo", "type": "integer"}, + "mov": {"title": "Mov", "type": "bluesky.protocols.Movable"}, + } + + @pytest.mark.parametrize( "plan", [has_typeless_param, has_typed_and_typeless_params, has_typeless_params] ) diff --git a/tests/service/test_rest_api.py b/tests/service/test_rest_api.py index b40a44da43..238a93e41d 100644 --- a/tests/service/test_rest_api.py +++ b/tests/service/test_rest_api.py @@ -110,9 +110,7 @@ def test_get_plan_with_device_reference(handler: Handler, client: TestClient) -> "title": "Delay", }, "detectors": { - "items": { - "_detectors": "" - }, + "items": {"type": "bluesky.protocols.Readable"}, "title": "Detectors", "type": "array", }, @@ -135,7 +133,7 @@ def test_get_plan_with_device_reference(handler: Handler, client: TestClient) -> "title": "Delay", }, "detectors": { - "items": {"_detectors": ""}, + "items": {"type": "bluesky.protocols.Readable"}, "title": "Detectors", "type": "array", },