From f0248fbe0045d12feb2f5760d15f0cfb1c96fbc2 Mon Sep 17 00:00:00 2001 From: Peter Holloway Date: Tue, 25 Jun 2024 12:21:45 +0100 Subject: [PATCH] Use FQCN for reference type schemas Instead of using the repr(cls) output. Gives bluesky.protocols.Readable instead of --- src/blueapi/core/context.py | 4 +++- tests/core/test_context.py | 2 +- tests/service/test_rest_api.py | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/blueapi/core/context.py b/src/blueapi/core/context.py index 8689c167b..1bd8e482e 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({"type": 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 2a01663e3..a1f6bdb1a 100644 --- a/tests/core/test_context.py +++ b/tests/core/test_context.py @@ -131,7 +131,7 @@ def demo_plan(foo: int, mov: Movable) -> MsgGenerator: # type: ignore schema = empty_context.plans["demo_plan"].model.schema() assert schema["properties"] == { "foo": {"title": "Foo", "type": "integer"}, - "mov": {"title": "Mov", "type": repr(Movable)}, + "mov": {"title": "Mov", "type": "bluesky.protocols.Movable"}, } diff --git a/tests/service/test_rest_api.py b/tests/service/test_rest_api.py index eda62b8b3..238a93e41 100644 --- a/tests/service/test_rest_api.py +++ b/tests/service/test_rest_api.py @@ -110,7 +110,7 @@ def test_get_plan_with_device_reference(handler: Handler, client: TestClient) -> "title": "Delay", }, "detectors": { - "items": {"type": ""}, + "items": {"type": "bluesky.protocols.Readable"}, "title": "Detectors", "type": "array", }, @@ -133,7 +133,7 @@ def test_get_plan_with_device_reference(handler: Handler, client: TestClient) -> "title": "Delay", }, "detectors": { - "items": {"type": ""}, + "items": {"type": "bluesky.protocols.Readable"}, "title": "Detectors", "type": "array", },