Function: apiObject()
function apiObject<Shape>(shape): ZodObject<{ -readonly [P in string | number | symbol]: Shape[P] }, $loose>;Defined in: src/core/apiObject.ts:19
Builds an object schema for an API response.
Loose by default: keys the API sends but the spec does not document pass straight through, so a field added upstream never breaks a consumer between releases.
Under AUDIT_SCHEMAS=true it builds strict objects instead, which is how the audit run learns where an undocumented key sits — zod reports unrecognized_keys with a path, and nothing else in the pipeline knows the shape well enough to say. Those failures do not reach the caller: createClient records them and hands back the response anyway, so one stale schema cannot cut the audit short. Loose validation cannot report drift at all, since accepting anything extra is precisely what it is for.
The declared return type stays the loose one in both modes, deliberately. The switch is read at runtime, so the compiler cannot follow it, and the published declarations must not shift with an environment variable.
Type Parameters
| Type Parameter |
|---|
Shape extends Readonly<{ [k: string]: $ZodType<unknown, unknown, $ZodTypeInternals<unknown, unknown>>; }> |
Parameters
| Parameter | Type |
|---|---|
shape | Shape |
Returns
ZodObject<{ -readonly [P in string | number | symbol]: Shape[P] }, $loose>