Skip to content

Commit 4c937d7

Browse files
oxesoftclaude
andauthored
Prevent PydanticUserError in ApiClient.send for void endpoints (#90) (#94)
* Prevent PydanticUserError when ApiClient.send has no return type Short-circuit and return None before constructing TypeAdapter when type_ is None (e.g. 204 No Content endpoints). TypeAdapter(None) raises PydanticUserError, and returning None matches the existing overloads. Closes #90 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * Accept 204 No Content in ApiClient.send Add 204 to the success status codes and short-circuit to None for it so void endpoints stop raising UnexpectedResponse. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 1a0e1b5 commit 4c937d7

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

scripts/datamodel_generate_client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -802,13 +802,15 @@ def request_sync(self, *, type_: Any, **kwargs: Any) -> Any:
802802
803803
async def send(self, request: Request, type_: Type[T]) -> T | str:
804804
response = await self.middleware(request, self.send_inner)
805-
if response.status_code in [200, 201]:
805+
if response.status_code in [200, 201, 204]:
806806
try:
807807
# Use Pydantic v2 TypeAdapter for validation
808+
if type_ is None or response.status_code == 204:
809+
return None
808810
adapter = TypeAdapter(type_)
809811
if type_ == bytes:
810812
return adapter.validate_python(response.content)
811-
return adapter.validate_python(response.json()) if type_ else response.text
813+
return adapter.validate_python(response.json())
812814
except Exception as e:
813815
raise ResponseHandlingException(e)
814816
raise UnexpectedResponse.for_response(response)

0 commit comments

Comments
 (0)