From c7147861404bcfd1486c4cab2a5bda8f5c035fe7 Mon Sep 17 00:00:00 2001 From: Max Marrone Date: Mon, 16 Dec 2024 17:38:40 -0500 Subject: [PATCH] Diff minimization: .json() and .dict() overrides. --- .../robot_server/service/json_api/response.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/robot-server/robot_server/service/json_api/response.py b/robot-server/robot_server/service/json_api/response.py index 11c0f082793..e75dea17e64 100644 --- a/robot-server/robot_server/service/json_api/response.py +++ b/robot-server/robot_server/service/json_api/response.py @@ -41,21 +41,21 @@ class BaseResponseBody(BaseModel): """ @override - def json(self, **kwargs: Any) -> str: - """Always exclude `None` when serializing. + def dict(self, *args: Any, **kwargs: Any) -> Dict[str, Any]: + """Always exclude `None` when serializing to an object. The OpenAPI spec marks `Optional` BaseModel fields as omittable, but not nullable. This `dict` method override ensures that `null` is never returned in a response, which would violate the spec. """ kwargs["exclude_none"] = True - return super().json(**kwargs) + return super().dict(*args, **kwargs) @override - def dict(self, **kwargs: Any) -> Dict[str, Any]: - """See `json()`.""" + def json(self, *args: Any, **kwargs: Any) -> str: + """See notes in `.dict()`.""" kwargs["exclude_none"] = True - return super().dict(**kwargs) + return super().json(*args, **kwargs) class SimpleBody(BaseResponseBody, Generic[ResponseDataT]):