Skip to content

Commit

Permalink
docs(robot-server): Fix labware router response bodies (#16444)
Browse files Browse the repository at this point in the history
## Overview

The `GET /runs/{id}/loaded_labware_definitions` and `POST
/runs/{id}/labware_definitions` endpoints were accidentally documented
in OpenAPI as returning the *run,* not the labware definition. This
fixes that.

## Review requests

* Documented return types match actual return types?
* OK with the `SimpleBody[list[...]]` thing?

## Risk assessment

Low.
  • Loading branch information
SyntaxColoring authored Oct 9, 2024
1 parent 1f50f1d commit 50d3208
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 15 deletions.
10 changes: 4 additions & 6 deletions robot-server/robot_server/runs/router/labware_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
RequestModel,
SimpleBody,
PydanticResponse,
ResponseList,
)

from ..run_models import Run, LabwareDefinitionSummary
Expand Down Expand Up @@ -86,7 +85,7 @@ async def add_labware_offset(
),
status_code=status.HTTP_201_CREATED,
responses={
status.HTTP_201_CREATED: {"model": SimpleBody[Run]},
status.HTTP_201_CREATED: {"model": SimpleBody[LabwareDefinitionSummary]},
status.HTTP_404_NOT_FOUND: {"model": ErrorBody[RunNotFound]},
status.HTTP_409_CONFLICT: {"model": ErrorBody[Union[RunStopped, RunNotIdle]]},
},
Expand Down Expand Up @@ -134,14 +133,14 @@ async def add_labware_definition(
" Repeated definitions will be deduplicated."
),
responses={
status.HTTP_200_OK: {"model": SimpleBody[Run]},
status.HTTP_200_OK: {"model": SimpleBody[list[SD_LabwareDefinition]]},
status.HTTP_409_CONFLICT: {"model": ErrorBody[RunStopped]},
},
)
async def get_run_loaded_labware_definitions(
runId: str,
run_data_manager: Annotated[RunDataManager, Depends(get_run_data_manager)],
) -> PydanticResponse[SimpleBody[ResponseList[SD_LabwareDefinition]]]:
) -> PydanticResponse[SimpleBody[list[SD_LabwareDefinition]]]:
"""Get a run's loaded labware definition by the run ID.
Args:
Expand All @@ -155,8 +154,7 @@ async def get_run_loaded_labware_definitions(
except RunNotCurrentError as e:
raise RunStopped(detail=str(e)).as_error(status.HTTP_409_CONFLICT) from e

labware_definitions_result = ResponseList.construct(__root__=labware_definitions)
return await PydanticResponse.create(
content=SimpleBody.construct(data=labware_definitions_result),
content=SimpleBody.construct(data=labware_definitions),
status_code=status.HTTP_200_OK,
)
2 changes: 0 additions & 2 deletions robot-server/robot_server/service/json_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
DeprecatedResponseDataModel,
ResourceModel,
PydanticResponse,
ResponseList,
NotifyRefetchBody,
NotifyUnsubscribeBody,
)
Expand Down Expand Up @@ -44,7 +43,6 @@
"DeprecatedResponseDataModel",
"DeprecatedResponseModel",
"DeprecatedMultiResponseModel",
"ResponseList",
# notify models
"NotifyRefetchBody",
"NotifyUnsubscribeBody",
Expand Down
6 changes: 0 additions & 6 deletions robot-server/robot_server/service/json_api/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,6 @@ class DeprecatedMultiResponseModel(
)


class ResponseList(BaseModel, Generic[ResponseDataT]):
"""A response that returns a list resource."""

__root__: List[ResponseDataT]


class NotifyRefetchBody(BaseResponseBody):
"""A notification response that returns a flag for refetching via HTTP."""

Expand Down
2 changes: 1 addition & 1 deletion robot-server/tests/runs/router/test_labware_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ async def test_get_run_labware_definition(
runId="run-id", run_data_manager=mock_run_data_manager
)

assert result.content.data.__root__ == [
assert result.content.data == [
SD_LabwareDefinition.construct(namespace="test_1"), # type: ignore[call-arg]
SD_LabwareDefinition.construct(namespace="test_2"), # type: ignore[call-arg]
]
Expand Down

0 comments on commit 50d3208

Please sign in to comment.