Compile-time types first
Generated DTOs, search types, page types, and operation response/error types are re-exported fromkomga-sdk:
content, totalElements, and totalPages may be optional, so narrow or default them even when validation is not enabled.
Add an application-owned schema
You can use Zod or another validator in your application. The schema and its package dependency are yours; they are not exports fromkomga-sdk:
parse when invalid data should throw, or safeParse when the application should keep the validation result alongside the response. Validate only the fields your feature consumes unless you deliberately need a full API contract.
Validate page boundaries
For a page, validate the envelope and the fields your feature consumes. A complete schema is an application policy, not an SDK requirement:PageBookDto fields are optional because that is the generated contract. Keep the schema aligned with fields the application actually requires and avoid claiming that a partial validation schema proves the entire response is valid.
Validate at the application boundary
Validate at the boundary where data enters your application, such as a repository function, server-side data loader, queue consumer, or cache read. This keeps generated operations reusable and makes failures observable:data. For a 204 No Content mutation, there is no response body to validate; success is indicated by error === undefined.
Validation and Fetch hooks
The generated client can observe response data through low-level options or interceptors, but it does not provide Komga DTO schemas. If a validator is registered as an application-owned response hook, keep its scope explicit and preserve the originalResponse or error contract:
result.data in a repository is easier to reason about than consuming response streams in a global hook. See Request customization.
What the SDK does not provide
- No SDK-exported runtime schemas or validation helper functions.
- No automatic response validation for JSON, text, blobs, or streams.
- No validation errors in the SDK error handling contract.
result.error with a response) and from a network failure (often no response). For HTTP result branches and the explicit throwing helper, see Result handling.