Skip to content

Commit ab02c6a

Browse files
Merge pull request #25 from datalogics-kam/pdfcloud-5583-agents-md
PDFCLOUD-5583 AGENTS.md improvements
2 parents 3d1c459 + 810d1c8 commit ab02c6a

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

AGENTS.md

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,14 @@
7171
- Avoid `@field_validator` on payload models. Prefer existing `BeforeValidator`
7272
helpers (e.g., `_allowed_mime_types`) so validation remains declarative and
7373
consistent across schemas.
74+
- Keep user-facing `PdfRestClient` and `AsyncPdfRestClient` endpoint helpers
75+
thin: they should primarily assemble payload dicts and delegate validation to
76+
payload models (`model_validate`). Avoid duplicating payload validation in
77+
client methods or raising configuration errors for payload-shape issues that
78+
Pydantic validators can enforce.
79+
- Prefer Pydantic-backed JSON serialization for performance: use
80+
`model_dump_json()` for Pydantic models, and use `pydantic_core.to_json()` for
81+
non-model payloads instead of `json.dumps()` where practical.
7482
- Treat `PdfRestClient` and `AsyncPdfRestClient` as context managers in both
7583
production code and tests so transports are disposed deterministically.
7684
- When uploading content, always send the multipart field name `file`; when
@@ -144,6 +152,23 @@
144152
`AfterValidator` for relational checks). Reserve standalone normalization
145153
functions for behaviour that cannot live on the schema—simpler models produce
146154
clearer errors and are easier for new contributors to understand.
155+
- When `Annotated` field constraints (for example tuple length and `ge`/`le`
156+
bounds) fully capture an input contract, prefer those native constraints over
157+
redundant custom validators that only restate the same rules.
158+
- Prefer the newer add-text color pattern over legacy helper-style validation:
159+
`_validate_rgb_values` / `_validate_cmyk_values` were replaced by tuple
160+
channel aliases (`RgbChannel`/`CmykChannel`) plus field constraints and should
161+
remain the default approach. Add custom validators only when they provide
162+
behavior native constraints cannot (for example, parsing alternate wire
163+
formats or enforcing cross-field dependencies).
164+
- Keep `BeforeValidator`/`AfterValidator` helpers and field serializers short
165+
and shape-focused. They should primarily adapt nonconforming inputs or handle
166+
pdfRest wire quirks (for example, splitting comma-separated values or
167+
serializing only the first uploaded file ID), not re-implement constraint
168+
logic already expressed by Pydantic field types/annotations.
169+
- Prefer reusable validator factories that take parameters (for example
170+
allowed-value/extension helpers with keyword-configured fallbacks) over
171+
bespoke one-off validator functions tied to a single field.
147172
- When adding new services, provide per-endpoint test modules mirroring PNG’s
148173
coverage: parameterized successes for every allowed literal value, request
149174
customization (sync + async), validation failures, and multi-file guards. Add
@@ -216,9 +241,10 @@
216241
- Avoid manual loops over test parameters; prefer `@pytest.mark.parametrize`
217242
with explicit `id=` values so each combination is visible and reproducible.
218243

219-
- Always couple `pytest.raises` with an explicit `match=` regex that reflects
220-
the intended validation error wording—mirror the human-readable text rather
221-
than relying on default exception formatting.
244+
- Always couple `pytest.raises` with an explicit `match=` regex. For SDK-owned
245+
validation messages, mirror the human-readable wording; for native Pydantic
246+
constraint errors, match stable fragments (field path + core bound/type
247+
phrase) rather than brittle full-text output.
222248

223249
- Mirror PNG’s request/response scenarios for each graphic conversion endpoint:
224250
maintain per-endpoint test modules (`test_convert_to_png.py`,

0 commit comments

Comments
 (0)