From 8edfa689e810f2c39c9472c3f610b3cc01e5c846 Mon Sep 17 00:00:00 2001 From: Kenneth Yang Date: Wed, 20 Mar 2024 15:46:27 -0700 Subject: [PATCH] Add to_string to model, gave Ephys Link response models defaults --- src/vbl_aquarium/models/ephys_link.py | 28 ++++++++++++------------ src/vbl_aquarium/utils/vbl_base_model.py | 5 ++++- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/vbl_aquarium/models/ephys_link.py b/src/vbl_aquarium/models/ephys_link.py index f36ba7f..4330795 100644 --- a/src/vbl_aquarium/models/ephys_link.py +++ b/src/vbl_aquarium/models/ephys_link.py @@ -78,10 +78,10 @@ class GetManipulatorsResponse(VBLBaseModel): :type error: str """ - manipulators: list[str] - num_axes: int - dimensions: Vector3 - error: str + manipulators: list[str] = [] + num_axes: int = 0 + dimensions: Vector3 = Vector3() + error: str = "" class PositionalResponse(VBLBaseModel): @@ -91,8 +91,8 @@ class PositionalResponse(VBLBaseModel): :type position: Vector4 """ - position: Vector4 - error: str + position: Vector4 = Vector4() + error: str = "" class AngularResponse(VBLBaseModel): @@ -102,8 +102,8 @@ class AngularResponse(VBLBaseModel): :type angles: Vector3 """ - angles: Vector3 - error: str + angles: Vector3 = Vector3() + error: str = "" class ShankCountResponse(VBLBaseModel): @@ -115,8 +115,8 @@ class ShankCountResponse(VBLBaseModel): :type error: str """ - shank_count: int - error: str + shank_count: int = 0 + error: str = "" class DriveToDepthResponse(VBLBaseModel): @@ -128,8 +128,8 @@ class DriveToDepthResponse(VBLBaseModel): :type error: str """ - depth: float - error: str + depth: float = 0 + error: str = "" class BooleanStateResponse(VBLBaseModel): @@ -141,5 +141,5 @@ class BooleanStateResponse(VBLBaseModel): :type error: str """ - state: bool - error: str + state: bool = False + error: str = "" diff --git a/src/vbl_aquarium/utils/vbl_base_model.py b/src/vbl_aquarium/utils/vbl_base_model.py index e00eba7..20c6545 100644 --- a/src/vbl_aquarium/utils/vbl_base_model.py +++ b/src/vbl_aquarium/utils/vbl_base_model.py @@ -8,4 +8,7 @@ class VBLBaseModel(BaseModel): Configured to use PascalCase for field names and be immutable. """ - model_config = ConfigDict(alias_generator=to_pascal, frozen=True) + model_config = ConfigDict(alias_generator=to_pascal, frozen=True, populate_by_name=True) + + def to_string(self) -> str: + return self.model_dump_json(by_alias=True)