zod-nest 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.d.mts +36 -13
- package/dist/index.d.ts +36 -13
- package/dist/index.js +29 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +29 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -431,7 +431,7 @@ A compact, link-out index. Type signatures and detailed semantics live in the co
|
|
|
431
431
|
- `ZodNestModule.forRoot(options?)`, `ZodNestModuleOptions`, `DEFAULT_REDACT_KEYS`, `DEFAULT_MAX_LOGGED_VALUE_BYTES`, `ZOD_NEST_OPTIONS`
|
|
432
432
|
|
|
433
433
|
**Schema engine** — single-schema mode and extension points
|
|
434
|
-
- `toOpenApi(schema, opts)`, `createRegistry()`, `defaultRegistry`, `ZodNestRegistry`, `Override`, `OverrideContext`, `overrideJSONSchema(schema, fragment)`, `ZodNestError`, `ZodNestUnrepresentableError`, `extend`, `getLineage`, `LineageEntry`
|
|
434
|
+
- `toOpenApi(schema, opts)`, `createRegistry()`, `defaultRegistry`, `ZodNestRegistry`, `Override`, `OverrideContext`, `overrideJSONSchema(schema, fragment | { input?, output? })`, `OverrideJSONSchemaArg`, `ZodNestError`, `ZodNestUnrepresentableError`, `extend`, `getLineage`, `LineageEntry`
|
|
435
435
|
|
|
436
436
|
## Documentation
|
|
437
437
|
|
package/dist/index.d.mts
CHANGED
|
@@ -79,27 +79,50 @@ declare const extend: <P extends z.ZodObject, S extends z.ZodObject>(parent: P,
|
|
|
79
79
|
*/
|
|
80
80
|
declare const getLineage: (schema: z.ZodType) => LineageEntry | undefined;
|
|
81
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Argument shape for {@link overrideJSONSchema}. Two forms:
|
|
84
|
+
*
|
|
85
|
+
* - A raw `SchemaObject` — applied to both input and output emission.
|
|
86
|
+
* - A `{ input?, output? }` wrapper — distinct fragments per emission side,
|
|
87
|
+
* for coercion shapes where input and output diverge (e.g.
|
|
88
|
+
* `z.union([z.array(item), item.transform((v) => [v])])` accepts
|
|
89
|
+
* `T | T[]` on input but always emits `T[]` on output).
|
|
90
|
+
*
|
|
91
|
+
* The wrapper form is detected by the presence of an `input` or `output`
|
|
92
|
+
* key. Neither is a JSON Schema / OpenAPI 3.1 keyword, so the discriminator
|
|
93
|
+
* is unambiguous in practice.
|
|
94
|
+
*/
|
|
95
|
+
type OverrideJSONSchemaArg = SchemaObject | {
|
|
96
|
+
input?: SchemaObject;
|
|
97
|
+
output?: SchemaObject;
|
|
98
|
+
};
|
|
82
99
|
/**
|
|
83
100
|
* Register a fixed JSON Schema fragment for a specific Zod schema instance.
|
|
84
101
|
*
|
|
85
102
|
* Designed for shapes JSON Schema can't model directly — `z.custom<T>()` and
|
|
86
103
|
* `z.instanceof(...)` (e.g. multipart `File` fields) — which Zod emits as `{}`,
|
|
87
|
-
* tripping `ZodNestUnrepresentableError` in strict mode.
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* inside `z.object({...})`, anywhere).
|
|
104
|
+
* tripping `ZodNestUnrepresentableError` in strict mode. Also useful for
|
|
105
|
+
* coercion shapes where input and output diverge (`singleOrArray`-style
|
|
106
|
+
* helpers).
|
|
91
107
|
*
|
|
92
|
-
*
|
|
93
|
-
* registration (last-write-wins).
|
|
108
|
+
* Two call shapes:
|
|
94
109
|
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
110
|
+
* ```ts
|
|
111
|
+
* // 1. Single fragment — applied verbatim to both input and output emission.
|
|
112
|
+
* overrideJSONSchema(FileSchema, { type: 'string', format: 'binary' });
|
|
113
|
+
*
|
|
114
|
+
* // 2. Divergent fragments — separate fragments per emission side. Omit a
|
|
115
|
+
* // side to leave Zod's default emission untouched on that side.
|
|
116
|
+
* overrideJSONSchema(arrayOrItem, {
|
|
117
|
+
* input: { anyOf: [arrFrag, itemFrag] },
|
|
118
|
+
* output: arrFrag,
|
|
119
|
+
* });
|
|
120
|
+
* ```
|
|
98
121
|
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
122
|
+
* Idempotent: subsequent calls for the same schema overwrite the prior
|
|
123
|
+
* registration (last-write-wins).
|
|
101
124
|
*/
|
|
102
|
-
declare const overrideJSONSchema: (schema: z.ZodType,
|
|
125
|
+
declare const overrideJSONSchema: (schema: z.ZodType, arg: OverrideJSONSchemaArg) => void;
|
|
103
126
|
|
|
104
127
|
interface ToOpenApiOptions {
|
|
105
128
|
io: 'input' | 'output';
|
|
@@ -549,4 +572,4 @@ declare class ZodNestDocumentError extends ZodNestError {
|
|
|
549
572
|
constructor(code: ZodNestDocumentErrorCode, message: string, details?: Record<string, unknown>);
|
|
550
573
|
}
|
|
551
574
|
|
|
552
|
-
export { type ApplyZodNestOptions, COMPONENTS_SCHEMAS_PREFIX, type CreateSerializationException, type CreateValidationException, type CreateZodDtoOptions, DEFAULT_MAX_LOGGED_VALUE_BYTES, DEFAULT_REDACT_KEYS, type Io, type LineageEntry, type NormalizedZodNestOptions, type Override, type OverrideContext, type ResponseStatusInput, type ResponseStatusWildcard, type ResponseVariant, type ResponseVariantKind, type SchemaObject, type ToOpenApiOptions, type ToOpenApiResult, ZOD_DTO_SYMBOL, ZOD_NEST_DTO_EXTENSION, ZOD_NEST_ERROR_DUPLICATE_ID, ZOD_NEST_ERROR_EXTENSION, ZOD_NEST_OPTIONS, ZOD_RESPONSES_METADATA_KEY, type ZodDto, type ZodDtoMarker, ZodNestDocumentError, type ZodNestDocumentErrorCode, ZodNestError, ZodNestModule, type ZodNestModuleOptions, type ZodNestRegistry, ZodNestUnrepresentableError, ZodResponse, type ZodResponseDescription, type ZodResponseOptions, type ZodResponseType, ZodSerializationException, ZodSerializerInterceptor, ZodValidationException, ZodValidationPipe, type ZodValidationPipeArg, type ZodValidationPipeOptions, applyZodNest, createRegistry, createZodDto, defaultRegistry, defaultStatusFor, extend, getLineage, isZodDto, isZodDtoMarker, makeZodDtoMarker, overrideJSONSchema, resolveEffectiveStatus, toOpenApi };
|
|
575
|
+
export { type ApplyZodNestOptions, COMPONENTS_SCHEMAS_PREFIX, type CreateSerializationException, type CreateValidationException, type CreateZodDtoOptions, DEFAULT_MAX_LOGGED_VALUE_BYTES, DEFAULT_REDACT_KEYS, type Io, type LineageEntry, type NormalizedZodNestOptions, type Override, type OverrideContext, type OverrideJSONSchemaArg, type ResponseStatusInput, type ResponseStatusWildcard, type ResponseVariant, type ResponseVariantKind, type SchemaObject, type ToOpenApiOptions, type ToOpenApiResult, ZOD_DTO_SYMBOL, ZOD_NEST_DTO_EXTENSION, ZOD_NEST_ERROR_DUPLICATE_ID, ZOD_NEST_ERROR_EXTENSION, ZOD_NEST_OPTIONS, ZOD_RESPONSES_METADATA_KEY, type ZodDto, type ZodDtoMarker, ZodNestDocumentError, type ZodNestDocumentErrorCode, ZodNestError, ZodNestModule, type ZodNestModuleOptions, type ZodNestRegistry, ZodNestUnrepresentableError, ZodResponse, type ZodResponseDescription, type ZodResponseOptions, type ZodResponseType, ZodSerializationException, ZodSerializerInterceptor, ZodValidationException, ZodValidationPipe, type ZodValidationPipeArg, type ZodValidationPipeOptions, applyZodNest, createRegistry, createZodDto, defaultRegistry, defaultStatusFor, extend, getLineage, isZodDto, isZodDtoMarker, makeZodDtoMarker, overrideJSONSchema, resolveEffectiveStatus, toOpenApi };
|
package/dist/index.d.ts
CHANGED
|
@@ -79,27 +79,50 @@ declare const extend: <P extends z.ZodObject, S extends z.ZodObject>(parent: P,
|
|
|
79
79
|
*/
|
|
80
80
|
declare const getLineage: (schema: z.ZodType) => LineageEntry | undefined;
|
|
81
81
|
|
|
82
|
+
/**
|
|
83
|
+
* Argument shape for {@link overrideJSONSchema}. Two forms:
|
|
84
|
+
*
|
|
85
|
+
* - A raw `SchemaObject` — applied to both input and output emission.
|
|
86
|
+
* - A `{ input?, output? }` wrapper — distinct fragments per emission side,
|
|
87
|
+
* for coercion shapes where input and output diverge (e.g.
|
|
88
|
+
* `z.union([z.array(item), item.transform((v) => [v])])` accepts
|
|
89
|
+
* `T | T[]` on input but always emits `T[]` on output).
|
|
90
|
+
*
|
|
91
|
+
* The wrapper form is detected by the presence of an `input` or `output`
|
|
92
|
+
* key. Neither is a JSON Schema / OpenAPI 3.1 keyword, so the discriminator
|
|
93
|
+
* is unambiguous in practice.
|
|
94
|
+
*/
|
|
95
|
+
type OverrideJSONSchemaArg = SchemaObject | {
|
|
96
|
+
input?: SchemaObject;
|
|
97
|
+
output?: SchemaObject;
|
|
98
|
+
};
|
|
82
99
|
/**
|
|
83
100
|
* Register a fixed JSON Schema fragment for a specific Zod schema instance.
|
|
84
101
|
*
|
|
85
102
|
* Designed for shapes JSON Schema can't model directly — `z.custom<T>()` and
|
|
86
103
|
* `z.instanceof(...)` (e.g. multipart `File` fields) — which Zod emits as `{}`,
|
|
87
|
-
* tripping `ZodNestUnrepresentableError` in strict mode.
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
* inside `z.object({...})`, anywhere).
|
|
104
|
+
* tripping `ZodNestUnrepresentableError` in strict mode. Also useful for
|
|
105
|
+
* coercion shapes where input and output diverge (`singleOrArray`-style
|
|
106
|
+
* helpers).
|
|
91
107
|
*
|
|
92
|
-
*
|
|
93
|
-
* registration (last-write-wins).
|
|
108
|
+
* Two call shapes:
|
|
94
109
|
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
110
|
+
* ```ts
|
|
111
|
+
* // 1. Single fragment — applied verbatim to both input and output emission.
|
|
112
|
+
* overrideJSONSchema(FileSchema, { type: 'string', format: 'binary' });
|
|
113
|
+
*
|
|
114
|
+
* // 2. Divergent fragments — separate fragments per emission side. Omit a
|
|
115
|
+
* // side to leave Zod's default emission untouched on that side.
|
|
116
|
+
* overrideJSONSchema(arrayOrItem, {
|
|
117
|
+
* input: { anyOf: [arrFrag, itemFrag] },
|
|
118
|
+
* output: arrFrag,
|
|
119
|
+
* });
|
|
120
|
+
* ```
|
|
98
121
|
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
122
|
+
* Idempotent: subsequent calls for the same schema overwrite the prior
|
|
123
|
+
* registration (last-write-wins).
|
|
101
124
|
*/
|
|
102
|
-
declare const overrideJSONSchema: (schema: z.ZodType,
|
|
125
|
+
declare const overrideJSONSchema: (schema: z.ZodType, arg: OverrideJSONSchemaArg) => void;
|
|
103
126
|
|
|
104
127
|
interface ToOpenApiOptions {
|
|
105
128
|
io: 'input' | 'output';
|
|
@@ -549,4 +572,4 @@ declare class ZodNestDocumentError extends ZodNestError {
|
|
|
549
572
|
constructor(code: ZodNestDocumentErrorCode, message: string, details?: Record<string, unknown>);
|
|
550
573
|
}
|
|
551
574
|
|
|
552
|
-
export { type ApplyZodNestOptions, COMPONENTS_SCHEMAS_PREFIX, type CreateSerializationException, type CreateValidationException, type CreateZodDtoOptions, DEFAULT_MAX_LOGGED_VALUE_BYTES, DEFAULT_REDACT_KEYS, type Io, type LineageEntry, type NormalizedZodNestOptions, type Override, type OverrideContext, type ResponseStatusInput, type ResponseStatusWildcard, type ResponseVariant, type ResponseVariantKind, type SchemaObject, type ToOpenApiOptions, type ToOpenApiResult, ZOD_DTO_SYMBOL, ZOD_NEST_DTO_EXTENSION, ZOD_NEST_ERROR_DUPLICATE_ID, ZOD_NEST_ERROR_EXTENSION, ZOD_NEST_OPTIONS, ZOD_RESPONSES_METADATA_KEY, type ZodDto, type ZodDtoMarker, ZodNestDocumentError, type ZodNestDocumentErrorCode, ZodNestError, ZodNestModule, type ZodNestModuleOptions, type ZodNestRegistry, ZodNestUnrepresentableError, ZodResponse, type ZodResponseDescription, type ZodResponseOptions, type ZodResponseType, ZodSerializationException, ZodSerializerInterceptor, ZodValidationException, ZodValidationPipe, type ZodValidationPipeArg, type ZodValidationPipeOptions, applyZodNest, createRegistry, createZodDto, defaultRegistry, defaultStatusFor, extend, getLineage, isZodDto, isZodDtoMarker, makeZodDtoMarker, overrideJSONSchema, resolveEffectiveStatus, toOpenApi };
|
|
575
|
+
export { type ApplyZodNestOptions, COMPONENTS_SCHEMAS_PREFIX, type CreateSerializationException, type CreateValidationException, type CreateZodDtoOptions, DEFAULT_MAX_LOGGED_VALUE_BYTES, DEFAULT_REDACT_KEYS, type Io, type LineageEntry, type NormalizedZodNestOptions, type Override, type OverrideContext, type OverrideJSONSchemaArg, type ResponseStatusInput, type ResponseStatusWildcard, type ResponseVariant, type ResponseVariantKind, type SchemaObject, type ToOpenApiOptions, type ToOpenApiResult, ZOD_DTO_SYMBOL, ZOD_NEST_DTO_EXTENSION, ZOD_NEST_ERROR_DUPLICATE_ID, ZOD_NEST_ERROR_EXTENSION, ZOD_NEST_OPTIONS, ZOD_RESPONSES_METADATA_KEY, type ZodDto, type ZodDtoMarker, ZodNestDocumentError, type ZodNestDocumentErrorCode, ZodNestError, ZodNestModule, type ZodNestModuleOptions, type ZodNestRegistry, ZodNestUnrepresentableError, ZodResponse, type ZodResponseDescription, type ZodResponseOptions, type ZodResponseType, ZodSerializationException, ZodSerializerInterceptor, ZodValidationException, ZodValidationPipe, type ZodValidationPipeArg, type ZodValidationPipeOptions, applyZodNest, createRegistry, createZodDto, defaultRegistry, defaultStatusFor, extend, getLineage, isZodDto, isZodDtoMarker, makeZodDtoMarker, overrideJSONSchema, resolveEffectiveStatus, toOpenApi };
|
package/dist/index.js
CHANGED
|
@@ -106,19 +106,36 @@ var createCompositionOverride = /* @__PURE__ */ __name((opts) => {
|
|
|
106
106
|
|
|
107
107
|
// src/schema/custom-override.ts
|
|
108
108
|
var customOverrideMap = /* @__PURE__ */ new WeakMap();
|
|
109
|
-
var
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
109
|
+
var isWrapper = /* @__PURE__ */ __name((arg) => "input" in arg || "output" in arg, "isWrapper");
|
|
110
|
+
var overrideJSONSchema = /* @__PURE__ */ __name((schema, arg) => {
|
|
111
|
+
if (isWrapper(arg)) {
|
|
112
|
+
customOverrideMap.set(schema, {
|
|
113
|
+
input: arg.input,
|
|
114
|
+
output: arg.output
|
|
115
|
+
});
|
|
115
116
|
return;
|
|
116
117
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}, "
|
|
118
|
+
customOverrideMap.set(schema, {
|
|
119
|
+
input: arg,
|
|
120
|
+
output: arg
|
|
121
|
+
});
|
|
122
|
+
}, "overrideJSONSchema");
|
|
123
|
+
var createCustomOverride = /* @__PURE__ */ __name((io) => {
|
|
124
|
+
return ({ zodSchema, jsonSchema }) => {
|
|
125
|
+
const record = customOverrideMap.get(zodSchema);
|
|
126
|
+
if (record === void 0) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const fragment = record[io];
|
|
130
|
+
if (fragment === void 0) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
for (const key of Object.keys(jsonSchema)) {
|
|
134
|
+
Reflect.deleteProperty(jsonSchema, key);
|
|
135
|
+
}
|
|
136
|
+
Object.assign(jsonSchema, fragment);
|
|
137
|
+
};
|
|
138
|
+
}, "createCustomOverride");
|
|
122
139
|
|
|
123
140
|
// src/schema/errors.ts
|
|
124
141
|
var ZodNestError = class extends Error {
|
|
@@ -248,6 +265,7 @@ var buildToJsonSchemaOptions = /* @__PURE__ */ __name((params) => {
|
|
|
248
265
|
buildRef: params.uri ?? DEFAULT_BUILD_REF,
|
|
249
266
|
registry: params.registry
|
|
250
267
|
});
|
|
268
|
+
const customOverride = createCustomOverride(params.io);
|
|
251
269
|
const merged = combine(primitiveOverride, compositionOverride, customOverride, params.override);
|
|
252
270
|
const unrepresentableHits = [];
|
|
253
271
|
const wrapped = /* @__PURE__ */ __name((ctx) => {
|