Skip to content

Commit

Permalink
Use FQCN for reference type schemas
Browse files Browse the repository at this point in the history
Instead of using the repr(cls) output. Gives

    bluesky.protocols.Readable

instead of

    <class 'bluesky.protocols.Readable'>
  • Loading branch information
tpoliaw committed Jun 25, 2024
1 parent 2f08d79 commit 46598b0
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/blueapi/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
}


Expand Down
4 changes: 2 additions & 2 deletions tests/service/test_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_get_plan_with_device_reference(handler: Handler, client: TestClient) ->
"title": "Delay",
},
"detectors": {
"items": {"type": "<class " "'bluesky.protocols.Readable'>"},
"items": {"type": "bluesky.protocols.Readable"},
"title": "Detectors",
"type": "array",
},
Expand All @@ -133,7 +133,7 @@ def test_get_plan_with_device_reference(handler: Handler, client: TestClient) ->
"title": "Delay",
},
"detectors": {
"items": {"type": "<class " "'bluesky.protocols.Readable'>"},
"items": {"type": "bluesky.protocols.Readable"},
"title": "Detectors",
"type": "array",
},
Expand Down

0 comments on commit 46598b0

Please sign in to comment.