Skip to content

Commit c0ff1eb

Browse files
models: Add serializer for first URL in list
- Implemented `_serialize_as_first_url` to extract the first URL from a list. - Updated `url` in `ConvertToPdfPayload` to accept a list of `HttpUrl` with enforced length of 1. - Applied `PlainSerializer` to ensure only the first URL is serialized. Assisted-by: Codex
1 parent ee115b1 commit c0ff1eb

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

src/pdfrest/models/_internal.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,10 @@ def _serialize_as_first_file_id(value: list[PdfRestFile]) -> str:
118118
return str(value[0].id)
119119

120120

121+
def _serialize_as_first_url(value: list[HttpUrl]) -> str:
122+
return str(value[0])
123+
124+
121125
def _serialize_as_comma_separated_string(value: list[Any] | None) -> str | None:
122126
if value is None:
123127
return None
@@ -748,8 +752,10 @@ class ConvertUrlToPdfPayload(BaseModel):
748752
"""Adapt caller options into a pdfRest-ready convert-to-pdf payload for one URL."""
749753

750754
url: Annotated[
751-
HttpUrl,
752-
Field(serialization_alias="url"),
755+
list[HttpUrl],
756+
Field(serialization_alias="url", min_length=1, max_length=1),
757+
BeforeValidator(_ensure_list),
758+
PlainSerializer(_serialize_as_first_url),
753759
]
754760
output: Annotated[
755761
str | None,

0 commit comments

Comments
 (0)