Skip to content

Commit 80a6eea

Browse files
AGENTS.md: Clarify validation and file handling conventions
- Recommended using `BeforeValidator` over `@field_validator` for declarative validation across schemas. - Documented guidelines for treating `PdfRestClient` and `AsyncPdfRestClient` as context managers for deterministic resource disposal. - Established consistent behavior for handling file uploads, multipart forms, and endpoint parameters, highlighting the use of `PdfRestFile` objects. - Specified rules for serialization and restricted public APIs from exposing internal resource identifiers like `PdfRestFileID`. Assisted-by: Codex
1 parent 277cfad commit 80a6eea

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

AGENTS.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,25 @@
3939
- When calling pdfRest, supply the API key via the `Api-Key` header (not
4040
`Authorization: Bearer`); keep tests and client defaults in sync with this
4141
convention.
42+
- Avoid `@field_validator` on payload models. Prefer existing `BeforeValidator`
43+
helpers (e.g., `_allowed_mime_types`) so validation remains declarative and
44+
consistent across schemas.
4245
- Treat `PdfRestClient` and `AsyncPdfRestClient` as context managers in both
4346
production code and tests so transports are disposed deterministically.
4447
- When uploading content, always send the multipart field name `file`; when
4548
uploading by URL, send a JSON payload using the `url` key with a list of
4649
http/https addresses (single values are promoted to lists internally).
50+
- Always upload local assets before invoking an endpoint helper. Public client
51+
APIs must accept `PdfRestFile` objects (or sequences) rather than raw paths or
52+
ids, including optional resources such as compression profiles. Never expose
53+
`PdfRestFileID` in the interface—callers should upload the profile JSON, get
54+
the resulting `PdfRestFile`, then pass that object into helpers like
55+
`compress_pdf`.
56+
- When an endpoint supports both an inline upload parameter and an `*_id`
57+
variant, ignore the upload form and expose only the base parameter (without
58+
`_id`) typed as `PdfRestFile`. Serialize via `_serialize_as_first_file_id`
59+
with `serialization_alias` pointing to the server’s `*_id` field so requests
60+
always reference already-uploaded resources.
4761
- `prepare_request` rejects mixed multipart (`files`) and JSON payloads; only
4862
URL uploads (`create_from_urls`) should combine JSON bodies with the request.
4963
- Replicate server-side safeguards when porting validation logic: the output

0 commit comments

Comments
 (0)