|
71 | 71 | - Avoid `@field_validator` on payload models. Prefer existing `BeforeValidator` |
72 | 72 | helpers (e.g., `_allowed_mime_types`) so validation remains declarative and |
73 | 73 | 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. |
74 | 82 | - Treat `PdfRestClient` and `AsyncPdfRestClient` as context managers in both |
75 | 83 | production code and tests so transports are disposed deterministically. |
76 | 84 | - When uploading content, always send the multipart field name `file`; when |
|
144 | 152 | `AfterValidator` for relational checks). Reserve standalone normalization |
145 | 153 | functions for behaviour that cannot live on the schema—simpler models produce |
146 | 154 | 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. |
147 | 172 | - When adding new services, provide per-endpoint test modules mirroring PNG’s |
148 | 173 | coverage: parameterized successes for every allowed literal value, request |
149 | 174 | customization (sync + async), validation failures, and multi-file guards. Add |
|
216 | 241 | - Avoid manual loops over test parameters; prefer `@pytest.mark.parametrize` |
217 | 242 | with explicit `id=` values so each combination is visible and reproducible. |
218 | 243 |
|
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. |
222 | 248 |
|
223 | 249 | - Mirror PNG’s request/response scenarios for each graphic conversion endpoint: |
224 | 250 | maintain per-endpoint test modules (`test_convert_to_png.py`, |
|
0 commit comments