zod-nest 0.12.0 → 0.13.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 +23 -1
- package/dist/index.d.ts +23 -1
- package/dist/index.js +18 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +18 -2
- 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`, `ZodNestError`, `ZodNestUnrepresentableError`, `extend`, `getLineage`, `LineageEntry`
|
|
434
|
+
- `toOpenApi(schema, opts)`, `createRegistry()`, `defaultRegistry`, `ZodNestRegistry`, `Override`, `OverrideContext`, `overrideJSONSchema(schema, fragment)`, `ZodNestError`, `ZodNestUnrepresentableError`, `extend`, `getLineage`, `LineageEntry`
|
|
435
435
|
|
|
436
436
|
## Documentation
|
|
437
437
|
|
package/dist/index.d.mts
CHANGED
|
@@ -79,6 +79,28 @@ 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
|
+
* Register a fixed JSON Schema fragment for a specific Zod schema instance.
|
|
84
|
+
*
|
|
85
|
+
* Designed for shapes JSON Schema can't model directly — `z.custom<T>()` and
|
|
86
|
+
* `z.instanceof(...)` (e.g. multipart `File` fields) — which Zod emits as `{}`,
|
|
87
|
+
* tripping `ZodNestUnrepresentableError` in strict mode. After registration
|
|
88
|
+
* the engine writes the supplied fragment in-place wherever that schema
|
|
89
|
+
* instance is emitted (single-schema `toOpenApi`, bulk emission, nested
|
|
90
|
+
* inside `z.object({...})`, anywhere).
|
|
91
|
+
*
|
|
92
|
+
* Idempotent: subsequent calls for the same schema overwrite the prior
|
|
93
|
+
* registration (last-write-wins).
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* const FileSchema = z.instanceof(File);
|
|
97
|
+
* overrideJSONSchema(FileSchema, { type: 'string', format: 'binary' });
|
|
98
|
+
*
|
|
99
|
+
* class UploadDto extends createZodDto(z.object({ file: FileSchema })) {}
|
|
100
|
+
* // OpenAPI doc emits `properties.file = { type: 'string', format: 'binary' }`
|
|
101
|
+
*/
|
|
102
|
+
declare const overrideJSONSchema: (schema: z.ZodType, jsonSchema: SchemaObject) => void;
|
|
103
|
+
|
|
82
104
|
interface ToOpenApiOptions {
|
|
83
105
|
io: 'input' | 'output';
|
|
84
106
|
registry: ZodNestRegistry;
|
|
@@ -527,4 +549,4 @@ declare class ZodNestDocumentError extends ZodNestError {
|
|
|
527
549
|
constructor(code: ZodNestDocumentErrorCode, message: string, details?: Record<string, unknown>);
|
|
528
550
|
}
|
|
529
551
|
|
|
530
|
-
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, resolveEffectiveStatus, toOpenApi };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -79,6 +79,28 @@ 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
|
+
* Register a fixed JSON Schema fragment for a specific Zod schema instance.
|
|
84
|
+
*
|
|
85
|
+
* Designed for shapes JSON Schema can't model directly — `z.custom<T>()` and
|
|
86
|
+
* `z.instanceof(...)` (e.g. multipart `File` fields) — which Zod emits as `{}`,
|
|
87
|
+
* tripping `ZodNestUnrepresentableError` in strict mode. After registration
|
|
88
|
+
* the engine writes the supplied fragment in-place wherever that schema
|
|
89
|
+
* instance is emitted (single-schema `toOpenApi`, bulk emission, nested
|
|
90
|
+
* inside `z.object({...})`, anywhere).
|
|
91
|
+
*
|
|
92
|
+
* Idempotent: subsequent calls for the same schema overwrite the prior
|
|
93
|
+
* registration (last-write-wins).
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* const FileSchema = z.instanceof(File);
|
|
97
|
+
* overrideJSONSchema(FileSchema, { type: 'string', format: 'binary' });
|
|
98
|
+
*
|
|
99
|
+
* class UploadDto extends createZodDto(z.object({ file: FileSchema })) {}
|
|
100
|
+
* // OpenAPI doc emits `properties.file = { type: 'string', format: 'binary' }`
|
|
101
|
+
*/
|
|
102
|
+
declare const overrideJSONSchema: (schema: z.ZodType, jsonSchema: SchemaObject) => void;
|
|
103
|
+
|
|
82
104
|
interface ToOpenApiOptions {
|
|
83
105
|
io: 'input' | 'output';
|
|
84
106
|
registry: ZodNestRegistry;
|
|
@@ -527,4 +549,4 @@ declare class ZodNestDocumentError extends ZodNestError {
|
|
|
527
549
|
constructor(code: ZodNestDocumentErrorCode, message: string, details?: Record<string, unknown>);
|
|
528
550
|
}
|
|
529
551
|
|
|
530
|
-
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, resolveEffectiveStatus, toOpenApi };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -104,6 +104,22 @@ var createCompositionOverride = /* @__PURE__ */ __name((opts) => {
|
|
|
104
104
|
};
|
|
105
105
|
}, "createCompositionOverride");
|
|
106
106
|
|
|
107
|
+
// src/schema/custom-override.ts
|
|
108
|
+
var customOverrideMap = /* @__PURE__ */ new WeakMap();
|
|
109
|
+
var overrideJSONSchema = /* @__PURE__ */ __name((schema, jsonSchema) => {
|
|
110
|
+
customOverrideMap.set(schema, jsonSchema);
|
|
111
|
+
}, "overrideJSONSchema");
|
|
112
|
+
var customOverride = /* @__PURE__ */ __name(({ zodSchema, jsonSchema }) => {
|
|
113
|
+
const fragment = customOverrideMap.get(zodSchema);
|
|
114
|
+
if (fragment === void 0) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
for (const key of Object.keys(jsonSchema)) {
|
|
118
|
+
Reflect.deleteProperty(jsonSchema, key);
|
|
119
|
+
}
|
|
120
|
+
Object.assign(jsonSchema, fragment);
|
|
121
|
+
}, "customOverride");
|
|
122
|
+
|
|
107
123
|
// src/schema/errors.ts
|
|
108
124
|
var ZodNestError = class extends Error {
|
|
109
125
|
static {
|
|
@@ -232,7 +248,7 @@ var buildToJsonSchemaOptions = /* @__PURE__ */ __name((params) => {
|
|
|
232
248
|
buildRef: params.uri ?? DEFAULT_BUILD_REF,
|
|
233
249
|
registry: params.registry
|
|
234
250
|
});
|
|
235
|
-
const merged = combine(primitiveOverride, compositionOverride, params.override);
|
|
251
|
+
const merged = combine(primitiveOverride, compositionOverride, customOverride, params.override);
|
|
236
252
|
const unrepresentableHits = [];
|
|
237
253
|
const wrapped = /* @__PURE__ */ __name((ctx) => {
|
|
238
254
|
merged(ctx);
|
|
@@ -1482,6 +1498,7 @@ exports.getLineage = getLineage;
|
|
|
1482
1498
|
exports.isZodDto = isZodDto;
|
|
1483
1499
|
exports.isZodDtoMarker = isZodDtoMarker;
|
|
1484
1500
|
exports.makeZodDtoMarker = makeZodDtoMarker;
|
|
1501
|
+
exports.overrideJSONSchema = overrideJSONSchema;
|
|
1485
1502
|
exports.resolveEffectiveStatus = resolveEffectiveStatus;
|
|
1486
1503
|
exports.toOpenApi = toOpenApi;
|
|
1487
1504
|
//# sourceMappingURL=index.js.map
|