@voznov/zod-dto-nestjs 0.1.3 → 0.2.1
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 +30 -1
- package/dist/index.cjs +25 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +25 -2
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ import { Body, Controller, Post } from '@nestjs/common';
|
|
|
23
23
|
import { ZodDto } from '@voznov/zod-dto';
|
|
24
24
|
import { z } from 'zod';
|
|
25
25
|
|
|
26
|
-
|
|
26
|
+
class CreateUserDto extends ZodDto(z.object({ name: z.string(), email: z.email() })) {}
|
|
27
27
|
|
|
28
28
|
@Controller('users')
|
|
29
29
|
export class UsersController {
|
|
@@ -44,6 +44,35 @@ Importing this package side-effect-registers an `onCreate` hook that decorates e
|
|
|
44
44
|
|
|
45
45
|
Supported shapes: scalars, objects (nested), arrays, tuples, records, enums, literals, unions (including discriminated), intersections, optional/nullable/default wrappers, and nested DTO references (via `oneOf` + `ApiExtraModels`).
|
|
46
46
|
|
|
47
|
+
`.default(value)` is forwarded to the OpenAPI `default` keyword.
|
|
48
|
+
|
|
49
|
+
> ⚠️ **Lazy defaults are frozen at decoration time.** For `.default(() => ...)`, the thunk is invoked **once** when the swagger metadata is generated, and the resolved value is baked into the spec. Anything non-stable — `Date.now()`, `randomUUID()`, `new Date()` — will freeze at the value the server happened to produce on startup, and every endpoint's example in your docs will show that one stale value. Use a stable thunk, or a literal default.
|
|
50
|
+
|
|
51
|
+
`.describe(text)` is forwarded to the OpenAPI `description` keyword. Works on the wrapper or on the inner type — `z.string().describe('Login email').optional()` and `z.string().optional().describe('Login email')` both end up with `description: 'Login email'` in the spec.
|
|
52
|
+
|
|
53
|
+
`.refine(...)` validators run at request-validation time but are **not** reflected in the spec — JSON Schema can't express custom predicates, and a single `description` for a chain of refines (`.refine(...).refine(...).refine(...)`) would be ambiguous. Put human-readable docs in `.describe(...)` instead.
|
|
54
|
+
|
|
55
|
+
### Recursive schemas (`z.lazy` / `lazyDto`)
|
|
56
|
+
|
|
57
|
+
For self-referential shapes (comment trees, file trees, ...) wrap the recursion in a DTO and reference it back via `lazyDto` — the Swagger walker emits a proper `$ref` at the cycle, and `lazyDto` keeps TypeScript from tripping over the circular self-reference:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { lazyDto, ZodDto } from '@voznov/zod-dto';
|
|
61
|
+
|
|
62
|
+
class CategoryDto extends ZodDto(
|
|
63
|
+
z.object({
|
|
64
|
+
name: z.string(),
|
|
65
|
+
children: z.array(lazyDto<CategoryDto>(() => CategoryDto)),
|
|
66
|
+
}),
|
|
67
|
+
) {}
|
|
68
|
+
// → children items become `$ref: '#/components/schemas/CategoryDto'`
|
|
69
|
+
// → at the type level, `instance.children[0].name` is `string`, not `unknown`.
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
`lazyDto<T>(thunk)` is a thin wrapper over `z.lazy` with two type-level tweaks: the explicit generic carries the *instance type* `T`, and the thunk argument is typed `() => any` so TS skips body return-type inference (the source of the circular-class error). Plain `z.lazy(...)` works at runtime too, but you'd need a separate `type Category = {...}` + `(): z.ZodType<Category>` annotation to keep the inferred field types non-`unknown`.
|
|
73
|
+
|
|
74
|
+
If the recursive position resolves to an anonymous `ZodObject` (no DTO wrap), the walker emits an empty `{}` placeholder there — it won't crash, but Swagger UI will show `any` instead of the recursive structure. Wrap it in `ZodDto` if you want the cycle visible in your docs.
|
|
75
|
+
|
|
47
76
|
## Custom error response
|
|
48
77
|
|
|
49
78
|
`ZodValidationPipe` accepts `{ createError }`. Default throws `BadRequestException` with the issues list as its response body.
|
package/dist/index.cjs
CHANGED
|
@@ -56,7 +56,15 @@ var leaf = (so) => ({
|
|
|
56
56
|
innerSchemas: /* @__PURE__ */ new Set()
|
|
57
57
|
});
|
|
58
58
|
var decoratedDtoClasses = /* @__PURE__ */ new Set();
|
|
59
|
+
var defaultValueCache = /* @__PURE__ */ new WeakMap();
|
|
60
|
+
var lazyInProgress = /* @__PURE__ */ new Set();
|
|
59
61
|
var applySwaggerDecorators = (schema) => {
|
|
62
|
+
const result = applyDecoratorsImpl(schema);
|
|
63
|
+
const description = schema.description;
|
|
64
|
+
if (description) result.so = { ...result.so, description };
|
|
65
|
+
return result;
|
|
66
|
+
};
|
|
67
|
+
var applyDecoratorsImpl = (schema) => {
|
|
60
68
|
if (schema instanceof import_zod.z.ZodObject) {
|
|
61
69
|
if ((0, import_zod_dto.isZodDtoClass)(schema) && decoratedDtoClasses.has(schema)) {
|
|
62
70
|
return { so: { oneOf: (0, import_swagger.refs)(schema) }, selfRequired: true, innerSchemas: /* @__PURE__ */ new Set([schema]) };
|
|
@@ -90,9 +98,24 @@ var applySwaggerDecorators = (schema) => {
|
|
|
90
98
|
return { ...applySwaggerDecorators(schema.unwrap()), selfRequired: false };
|
|
91
99
|
}
|
|
92
100
|
if (schema instanceof import_zod.z.ZodDefault) {
|
|
93
|
-
|
|
101
|
+
const inner = applySwaggerDecorators(schema.unwrap());
|
|
102
|
+
if (!defaultValueCache.has(schema)) defaultValueCache.set(schema, schema._zod.def.defaultValue);
|
|
103
|
+
return { ...inner, so: { ...inner.so, default: defaultValueCache.get(schema) }, selfRequired: false };
|
|
104
|
+
}
|
|
105
|
+
if (schema instanceof import_zod.z.ZodLazy) {
|
|
106
|
+
if (lazyInProgress.has(schema)) {
|
|
107
|
+
const inner = schema.unwrap();
|
|
108
|
+
if ((0, import_zod_dto.isZodDtoClass)(inner)) return { so: { oneOf: (0, import_swagger.refs)(inner) }, selfRequired: true, innerSchemas: /* @__PURE__ */ new Set([inner]) };
|
|
109
|
+
return leaf({});
|
|
110
|
+
}
|
|
111
|
+
lazyInProgress.add(schema);
|
|
112
|
+
try {
|
|
113
|
+
return applySwaggerDecorators(schema.unwrap());
|
|
114
|
+
} finally {
|
|
115
|
+
lazyInProgress.delete(schema);
|
|
116
|
+
}
|
|
94
117
|
}
|
|
95
|
-
if (schema instanceof import_zod.z.ZodReadonly || schema instanceof import_zod.z.
|
|
118
|
+
if (schema instanceof import_zod.z.ZodReadonly || schema instanceof import_zod.z.ZodCatch) {
|
|
96
119
|
return applySwaggerDecorators(schema.unwrap());
|
|
97
120
|
}
|
|
98
121
|
if (schema instanceof import_zod.z.ZodNonOptional) {
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/swagger.ts","../src/utils.ts","../src/pipe.ts"],"sourcesContent":["import { registerOnCreate } from '@voznov/zod-dto';\nimport { applySwaggerDecorators } from './swagger';\n\n// Auto-register swagger decoration on every ZodDto() creation when this package is imported.\nregisterOnCreate(applySwaggerDecorators);\n\nexport { ZodValidationPipe } from './pipe';\nexport type { ZodValidationPipeOptions } from './pipe';\nexport { applySwaggerDecorators } from './swagger';\n","import { ApiExtraModels, ApiProperty, type ApiPropertyOptions, refs } from '@nestjs/swagger';\nimport { type SchemaObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';\nimport { isZodDtoClass, type ZodDtoClass } from '@voznov/zod-dto';\nimport { z } from 'zod';\nimport { mapValues } from './utils';\n\nconst schemaObjectToApiPropertyOptions = (so: SchemaObject, selfRequired: boolean): ApiPropertyOptions => {\n if ('oneOf' in so || 'anyOf' in so || 'allOf' in so) {\n return { ...so, type: Array, required: selfRequired };\n }\n\n return { ...so, required: selfRequired } as ApiPropertyOptions;\n};\n\nconst leaf = (so: SchemaObject): { so: SchemaObject; selfRequired: boolean; innerSchemas: Set<ZodDtoClass> } => ({\n so,\n selfRequired: true,\n innerSchemas: new Set(),\n});\n\nconst decoratedDtoClasses = new Set<ZodDtoClass>();\n\nexport const applySwaggerDecorators = (schema: z.core.$ZodType): { so: SchemaObject; selfRequired: boolean; innerSchemas: Set<ZodDtoClass> } => {\n // --- Objects ---\n\n if (schema instanceof z.ZodObject) {\n if (isZodDtoClass(schema) && decoratedDtoClasses.has(schema)) {\n return { so: { oneOf: refs(schema) }, selfRequired: true, innerSchemas: new Set([schema]) };\n }\n\n const properties: Record<string, SchemaObject> = {};\n const required: string[] = [];\n const innerSchemas = new Set<ZodDtoClass>();\n Object.entries(schema.shape).forEach(([key, fieldSchema]) => {\n const { so, selfRequired, innerSchemas: innerSchemas_ } = applySwaggerDecorators(fieldSchema as z.ZodType);\n properties[key] = so;\n innerSchemas_.forEach((innerSchema) => innerSchemas.add(innerSchema));\n if (selfRequired) {\n required.push(key);\n }\n });\n\n if (isZodDtoClass(schema)) {\n decoratedDtoClasses.add(schema);\n for (const [key, propertySo] of Object.entries(properties)) {\n ApiProperty(schemaObjectToApiPropertyOptions(propertySo, required.includes(key)))(schema.prototype, key);\n }\n ApiExtraModels(...[...innerSchemas.values()].filter((innerSchema) => innerSchema !== schema))(schema);\n\n return { so: { oneOf: refs(schema) }, selfRequired: true, innerSchemas: new Set([schema]) };\n }\n\n return { so: { type: 'object', properties: mapValues(properties, (so) => (so.oneOf?.length === 1 ? so.oneOf[0] : so)), required }, selfRequired: true, innerSchemas };\n }\n\n if (schema instanceof z.ZodRecord) {\n const { so } = applySwaggerDecorators(schema._zod.def.valueType as z.ZodType);\n\n return leaf({ type: 'object', additionalProperties: so.oneOf?.length === 1 ? so.oneOf[0] : so });\n }\n\n // --- Wrappers (unwrap to inner type) ---\n\n if (schema instanceof z.ZodOptional || schema instanceof z.ZodExactOptional) {\n return { ...applySwaggerDecorators(schema.unwrap()), selfRequired: false };\n }\n\n if (schema instanceof z.ZodDefault) {\n return { ...applySwaggerDecorators(schema.unwrap()), selfRequired: false };\n }\n\n if (schema instanceof z.ZodReadonly || schema instanceof z.ZodLazy || schema instanceof z.ZodCatch) {\n return applySwaggerDecorators(schema.unwrap());\n }\n\n if (schema instanceof z.ZodNonOptional) {\n return { ...applySwaggerDecorators(schema.unwrap()), selfRequired: true };\n }\n\n if (schema instanceof z.ZodNullable) {\n const result = applySwaggerDecorators(schema.unwrap());\n\n return { ...result, so: { ...result.so, nullable: true } };\n }\n\n if (schema instanceof z.ZodPipe) {\n // z.preprocess() creates a Pipe(in: ZodTransform, out: schema).\n // For swagger, skip the transform and process the output schema directly.\n const inner = schema.in instanceof z.ZodTransform ? schema.out : schema.in;\n\n return applySwaggerDecorators(inner);\n }\n\n if (schema instanceof z.ZodTransform) {\n return leaf({});\n }\n\n // --- Arrays & tuples ---\n\n if (schema instanceof z.ZodArray) {\n const element = schema.unwrap();\n const { so, selfRequired: selfRequiredElement, innerSchemas } = applySwaggerDecorators(element);\n if (!selfRequiredElement) {\n throw new Error('Not required array item is not supported in Swagger. Use nullable instead.');\n }\n\n return { so: { type: 'array', items: so.oneOf?.length === 1 ? so.oneOf[0] : so }, selfRequired: true, innerSchemas };\n }\n\n if (schema instanceof z.ZodTuple) {\n const itemSchemas = schema._zod.def.items.map((item) => {\n const { so } = applySwaggerDecorators(item);\n\n return so.oneOf?.length === 1 ? so.oneOf[0] : so;\n });\n\n // Deduplicate by JSON representation to collapse identical types\n const unique = [...new Map(itemSchemas.map((s) => [JSON.stringify(s), s])).values()];\n const items = unique.length === 1 ? unique[0] : { oneOf: unique };\n\n return leaf({ type: 'array', items, minItems: itemSchemas.length, maxItems: itemSchemas.length });\n }\n\n // --- Scalars ---\n\n // ZodString: plain z.string(). ZodStringFormat: z.email(), z.uuid(), z.url(), z.ipv4(), etc.\n // Both share the same properties (minLength, maxLength, format).\n if (schema instanceof z.ZodString || schema instanceof z.ZodStringFormat) {\n const so: SchemaObject = { type: 'string' };\n if (schema.minLength !== null) so.minLength = schema.minLength;\n if (schema.maxLength !== null) so.maxLength = schema.maxLength;\n const fmt = schema.format;\n if (fmt !== null) {\n if (fmt === 'regex') {\n // Grab the first regex pattern from the internal bag.\n const patterns = schema._zod.bag.patterns;\n const first = patterns ? [...patterns][0] : undefined;\n if (first) so.pattern = first.source;\n } else {\n so.format = fmt;\n }\n }\n\n return { so, selfRequired: true, innerSchemas: new Set() };\n }\n\n // Number and integer subtypes (ZodInt, ZodNumberFormat, etc.) — all instanceof ZodNumber.\n if (schema instanceof z.ZodNumber) {\n const fmt = schema.format;\n const isInt = fmt === 'int32' || fmt === 'uint32' || fmt === 'safeint';\n const so: SchemaObject = { type: isInt ? 'integer' : 'number' };\n if (schema.minValue !== null && schema.minValue !== Number.MIN_SAFE_INTEGER && Number.isFinite(schema.minValue)) so.minimum = schema.minValue;\n if (schema.maxValue !== null && schema.maxValue !== Number.MAX_SAFE_INTEGER && Number.isFinite(schema.maxValue)) so.maximum = schema.maxValue;\n\n return { so, selfRequired: true, innerSchemas: new Set() };\n }\n\n if (schema instanceof z.ZodBigInt) {\n return leaf({ type: 'integer', format: 'int64' });\n }\n\n if (schema instanceof z.ZodBoolean) {\n return leaf({ type: 'boolean' });\n }\n\n if (schema instanceof z.ZodDate) {\n return leaf({ type: 'string', format: 'date-time' });\n }\n\n if (schema instanceof z.ZodNull) {\n return { so: { nullable: true }, selfRequired: true, innerSchemas: new Set() };\n }\n\n // --- Enums & literals ---\n\n if (schema instanceof z.ZodEnum) {\n return leaf({ enum: schema.options });\n }\n\n if (schema instanceof z.ZodLiteral) {\n return leaf({ enum: [...schema.values] });\n }\n\n // --- Unions & intersections ---\n\n if (schema instanceof z.ZodUnion || schema instanceof z.ZodDiscriminatedUnion) {\n const innerSchemas = new Set<ZodDtoClass>();\n const oneOf = schema.options.map((option) => {\n const { so, selfRequired, innerSchemas: innerSchemas_ } = applySwaggerDecorators(option);\n\n if (!selfRequired) {\n throw new Error('Not required option in oneOf is not supported in Swagger. Use nullable instead.');\n }\n\n innerSchemas_.forEach((innerSchema) => innerSchemas.add(innerSchema));\n\n // Flatten { oneOf: [single_ref] } → just the ref, so union of DTO refs stays clean.\n return so.oneOf?.length === 1 ? so.oneOf[0] : so;\n });\n\n return { so: { oneOf }, selfRequired: true, innerSchemas };\n }\n\n if (schema instanceof z.ZodIntersection) {\n const left = applySwaggerDecorators(schema._zod.def.left as z.ZodType);\n const right = applySwaggerDecorators(schema._zod.def.right as z.ZodType);\n const innerSchemas = new Set([...left.innerSchemas, ...right.innerSchemas]);\n const leftSo = left.so.oneOf?.length === 1 ? left.so.oneOf[0] : left.so;\n const rightSo = right.so.oneOf?.length === 1 ? right.so.oneOf[0] : right.so;\n\n return { so: { allOf: [leftSo, rightSo] }, selfRequired: true, innerSchemas };\n }\n\n // --- Catch-all ---\n\n if (schema instanceof z.ZodAny || schema instanceof z.ZodUnknown) {\n return leaf({});\n }\n\n if (schema instanceof z.ZodUndefined || schema instanceof z.ZodVoid || schema instanceof z.ZodNever) {\n throw new Error(`applySwaggerDecorators: ${(schema as z.ZodType).def.type} cannot be represented in JSON`);\n }\n\n throw new Error(`applySwaggerDecorators: unsupported Zod type \"${(schema as z.ZodType).def.type}\"`);\n};\n","export const mapValues = <K extends string, V, R>(obj: Record<K, V>, fn: (value: V, key: K) => R): Record<K, R> =>\n Object.fromEntries(Object.entries<V>(obj).map(([key, value]) => [key, fn(value, key as K)])) as Record<K, R>;\n","import { BadRequestException, Injectable, type PipeTransform } from '@nestjs/common';\nimport { type ArgumentMetadata } from '@nestjs/common/interfaces';\nimport { isZodDtoClass, toDto, ZodDtoValidationError } from '@voznov/zod-dto';\n\nexport interface ZodValidationPipeOptions {\n createError?: (issues: string[]) => Error;\n}\n\n@Injectable()\nexport class ZodValidationPipe implements PipeTransform {\n private readonly createError: (issues: string[]) => Error;\n\n constructor(options?: ZodValidationPipeOptions) {\n this.createError = options?.createError ?? ((issues) => new BadRequestException(issues));\n }\n\n transform(value: unknown, { metatype }: ArgumentMetadata): unknown {\n if (!metatype || !isZodDtoClass(metatype)) {\n return value;\n }\n\n try {\n return toDto(metatype, value);\n } catch (error) {\n if (error instanceof ZodDtoValidationError) {\n throw this.createError(error.issues);\n }\n throw error;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,kBAAiC;;;ACAjC,qBAA2E;AAC3E,2BAAkC;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,UAAU,MAAM,GAAG,OAAO,WAAW,IAAI,MAAM,GAAG,MAAM,CAAC,IAAI,MAAM;AAEzE,WAAO,EAAE,IAAI,EAAE,OAAO,CAAC,QAAQ,OAAO,EAAE,GAAG,cAAc,MAAM,aAAa;AAAA,EAC9E;AAIA,MAAI,kBAAkB,aAAE,UAAU,kBAAkB,aAAE,YAAY;AAChE,WAAO,KAAK,CAAC,CAAC;AAAA,EAChB;AAEA,MAAI,kBAAkB,aAAE,gBAAgB,kBAAkB,aAAE,WAAW,kBAAkB,aAAE,UAAU;AACnG,UAAM,IAAI,MAAM,2BAA4B,OAAqB,IAAI,IAAI,gCAAgC;AAAA,EAC3G;AAEA,QAAM,IAAI,MAAM,iDAAkD,OAAqB,IAAI,IAAI,GAAG;AACpG;;;AEhOA,oBAAoE;AACpE,wBAAsC;AACtC,IAAAC,kBAA4D;AAOrD,IAAM,oBAAN,MAAiD;AAAA,EACrC;AAAA,EAEjB,YAAY,SAAoC;AAC9C,SAAK,cAAc,SAAS,gBAAgB,CAAC,WAAW,IAAI,kCAAoB,MAAM;AAAA,EACxF;AAAA,EAEA,UAAU,OAAgB,EAAE,SAAS,GAA8B;AACjE,QAAI,CAAC,YAAY,KAAC,+BAAc,QAAQ,GAAG;AACzC,aAAO;AAAA,IACT;AAEA,QAAI;AACF,iBAAO,uBAAM,UAAU,KAAK;AAAA,IAC9B,SAAS,OAAO;AACd,UAAI,iBAAiB,uCAAuB;AAC1C,cAAM,KAAK,YAAY,MAAM,MAAM;AAAA,MACrC;AACA,YAAM;AAAA,IACR;AAAA,EACF;AACF;AArBa,oBAAN;AAAA,MADN,0BAAW;AAAA,GACC;;;IHLb,kCAAiB,sBAAsB;","names":["import_zod_dto","import_zod_dto"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/swagger.ts","../src/utils.ts","../src/pipe.ts"],"sourcesContent":["import { registerOnCreate } from '@voznov/zod-dto';\nimport { applySwaggerDecorators } from './swagger';\n\n// Auto-register swagger decoration on every ZodDto() creation when this package is imported.\nregisterOnCreate(applySwaggerDecorators);\n\nexport { ZodValidationPipe } from './pipe';\nexport type { ZodValidationPipeOptions } from './pipe';\nexport { applySwaggerDecorators } from './swagger';\n","import { ApiExtraModels, ApiProperty, type ApiPropertyOptions, refs } from '@nestjs/swagger';\nimport { type SchemaObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';\nimport { isZodDtoClass, type ZodDtoClass } from '@voznov/zod-dto';\nimport { z } from 'zod';\nimport { mapValues } from './utils';\n\nconst schemaObjectToApiPropertyOptions = (so: SchemaObject, selfRequired: boolean): ApiPropertyOptions => {\n if ('oneOf' in so || 'anyOf' in so || 'allOf' in so) {\n return { ...so, type: Array, required: selfRequired };\n }\n\n return { ...so, required: selfRequired } as ApiPropertyOptions;\n};\n\nconst leaf = (so: SchemaObject): { so: SchemaObject; selfRequired: boolean; innerSchemas: Set<ZodDtoClass> } => ({\n so,\n selfRequired: true,\n innerSchemas: new Set(),\n});\n\nconst decoratedDtoClasses = new Set<ZodDtoClass>();\n\n// Snapshot resolved default per schema instance — Zod's `defaultValue` is a getter that\n// re-invokes the thunk on every access. Without this cache, the same `ZodDefault` schema\n// surfaced through two paths (JS subclass, `.extend/.pick/.omit`, shared field reuse, ...)\n// would emit a different value into each occurrence in the spec.\nconst defaultValueCache = new WeakMap<z.ZodDefault, unknown>();\n\n// `z.lazy(() => self)` is the only way to introduce a real cycle in a Zod schema graph.\n// Track each ZodLazy currently being walked so we can break re-entry without overflowing.\nconst lazyInProgress = new Set<z.ZodLazy>();\n\nexport const applySwaggerDecorators = (schema: z.core.$ZodType): { so: SchemaObject; selfRequired: boolean; innerSchemas: Set<ZodDtoClass> } => {\n const result = applyDecoratorsImpl(schema);\n // `.describe(text)` → OpenAPI `description`. Read at every recursion level so the text\n // lands in the spec whether it's set on a wrapper (`.optional().describe(...)`) or on\n // the inner type (`.describe(...).optional()`).\n const description = (schema as z.ZodType).description;\n if (description) result.so = { ...result.so, description };\n\n return result;\n};\n\nconst applyDecoratorsImpl = (schema: z.core.$ZodType): { so: SchemaObject; selfRequired: boolean; innerSchemas: Set<ZodDtoClass> } => {\n // --- Objects ---\n\n if (schema instanceof z.ZodObject) {\n if (isZodDtoClass(schema) && decoratedDtoClasses.has(schema)) {\n return { so: { oneOf: refs(schema) }, selfRequired: true, innerSchemas: new Set([schema]) };\n }\n\n const properties: Record<string, SchemaObject> = {};\n const required: string[] = [];\n const innerSchemas = new Set<ZodDtoClass>();\n Object.entries<z.core.$ZodType>(schema.shape).forEach(([key, fieldSchema]) => {\n const { so, selfRequired, innerSchemas: innerSchemas_ } = applySwaggerDecorators(fieldSchema);\n properties[key] = so;\n innerSchemas_.forEach((innerSchema) => innerSchemas.add(innerSchema));\n if (selfRequired) {\n required.push(key);\n }\n });\n\n if (isZodDtoClass(schema)) {\n decoratedDtoClasses.add(schema);\n for (const [key, propertySo] of Object.entries(properties)) {\n ApiProperty(schemaObjectToApiPropertyOptions(propertySo, required.includes(key)))(schema.prototype, key);\n }\n ApiExtraModels(...[...innerSchemas.values()].filter((innerSchema) => innerSchema !== schema))(schema);\n\n return { so: { oneOf: refs(schema) }, selfRequired: true, innerSchemas: new Set([schema]) };\n }\n\n return { so: { type: 'object', properties: mapValues(properties, (so) => (so.oneOf?.length === 1 ? so.oneOf[0] : so)), required }, selfRequired: true, innerSchemas };\n }\n\n if (schema instanceof z.ZodRecord) {\n const { so } = applySwaggerDecorators(schema._zod.def.valueType);\n\n return leaf({ type: 'object', additionalProperties: so.oneOf?.length === 1 ? so.oneOf[0] : so });\n }\n\n // --- Wrappers (unwrap to inner type) ---\n\n if (schema instanceof z.ZodOptional || schema instanceof z.ZodExactOptional) {\n return { ...applySwaggerDecorators(schema.unwrap()), selfRequired: false };\n }\n\n if (schema instanceof z.ZodDefault) {\n const inner = applySwaggerDecorators(schema.unwrap());\n if (!defaultValueCache.has(schema)) defaultValueCache.set(schema, schema._zod.def.defaultValue);\n\n return { ...inner, so: { ...inner.so, default: defaultValueCache.get(schema) }, selfRequired: false };\n }\n\n if (schema instanceof z.ZodLazy) {\n // `z.lazy(() => self)` is the only way Zod schemas can carry an actual cycle.\n // Track each ZodLazy instance currently being walked; on re-entry, emit a $ref\n // back to the DTO that the lazy resolves to (if any), or a permissive `{}` as a\n // last resort for anonymous self-referential trees.\n if (lazyInProgress.has(schema)) {\n const inner = schema.unwrap();\n if (isZodDtoClass(inner)) return { so: { oneOf: refs(inner) }, selfRequired: true, innerSchemas: new Set([inner]) };\n\n return leaf({});\n }\n lazyInProgress.add(schema);\n try {\n return applySwaggerDecorators(schema.unwrap());\n } finally {\n lazyInProgress.delete(schema);\n }\n }\n\n if (schema instanceof z.ZodReadonly || schema instanceof z.ZodCatch) {\n return applySwaggerDecorators(schema.unwrap());\n }\n\n if (schema instanceof z.ZodNonOptional) {\n return { ...applySwaggerDecorators(schema.unwrap()), selfRequired: true };\n }\n\n if (schema instanceof z.ZodNullable) {\n const result = applySwaggerDecorators(schema.unwrap());\n\n return { ...result, so: { ...result.so, nullable: true } };\n }\n\n if (schema instanceof z.ZodPipe) {\n // z.preprocess() creates a Pipe(in: ZodTransform, out: schema).\n // For swagger, skip the transform and process the output schema directly.\n const inner = schema.in instanceof z.ZodTransform ? schema.out : schema.in;\n\n return applySwaggerDecorators(inner);\n }\n\n if (schema instanceof z.ZodTransform) {\n return leaf({});\n }\n\n // --- Arrays & tuples ---\n\n if (schema instanceof z.ZodArray) {\n const element = schema.unwrap();\n const { so, selfRequired: selfRequiredElement, innerSchemas } = applySwaggerDecorators(element);\n if (!selfRequiredElement) {\n throw new Error('Not required array item is not supported in Swagger. Use nullable instead.');\n }\n\n return { so: { type: 'array', items: so.oneOf?.length === 1 ? so.oneOf[0] : so }, selfRequired: true, innerSchemas };\n }\n\n if (schema instanceof z.ZodTuple) {\n const itemSchemas = schema._zod.def.items.map((item) => {\n const { so } = applySwaggerDecorators(item);\n\n return so.oneOf?.length === 1 ? so.oneOf[0] : so;\n });\n\n // Deduplicate by JSON representation to collapse identical types\n const unique = [...new Map(itemSchemas.map((s) => [JSON.stringify(s), s])).values()];\n const items = unique.length === 1 ? unique[0] : { oneOf: unique };\n\n return leaf({ type: 'array', items, minItems: itemSchemas.length, maxItems: itemSchemas.length });\n }\n\n // --- Scalars ---\n\n // ZodString: plain z.string(). ZodStringFormat: z.email(), z.uuid(), z.url(), z.ipv4(), etc.\n // Both share the same properties (minLength, maxLength, format).\n if (schema instanceof z.ZodString || schema instanceof z.ZodStringFormat) {\n const so: SchemaObject = { type: 'string' };\n if (schema.minLength !== null) so.minLength = schema.minLength;\n if (schema.maxLength !== null) so.maxLength = schema.maxLength;\n const fmt = schema.format;\n if (fmt !== null) {\n if (fmt === 'regex') {\n // Grab the first regex pattern from the internal bag.\n const patterns = schema._zod.bag.patterns;\n const first = patterns ? [...patterns][0] : undefined;\n if (first) so.pattern = first.source;\n } else {\n so.format = fmt;\n }\n }\n\n return { so, selfRequired: true, innerSchemas: new Set() };\n }\n\n // Number and integer subtypes (ZodInt, ZodNumberFormat, etc.) — all instanceof ZodNumber.\n if (schema instanceof z.ZodNumber) {\n const fmt = schema.format;\n const isInt = fmt === 'int32' || fmt === 'uint32' || fmt === 'safeint';\n const so: SchemaObject = { type: isInt ? 'integer' : 'number' };\n if (schema.minValue !== null && schema.minValue !== Number.MIN_SAFE_INTEGER && Number.isFinite(schema.minValue)) so.minimum = schema.minValue;\n if (schema.maxValue !== null && schema.maxValue !== Number.MAX_SAFE_INTEGER && Number.isFinite(schema.maxValue)) so.maximum = schema.maxValue;\n\n return { so, selfRequired: true, innerSchemas: new Set() };\n }\n\n if (schema instanceof z.ZodBigInt) {\n return leaf({ type: 'integer', format: 'int64' });\n }\n\n if (schema instanceof z.ZodBoolean) {\n return leaf({ type: 'boolean' });\n }\n\n if (schema instanceof z.ZodDate) {\n return leaf({ type: 'string', format: 'date-time' });\n }\n\n if (schema instanceof z.ZodNull) {\n return { so: { nullable: true }, selfRequired: true, innerSchemas: new Set() };\n }\n\n // --- Enums & literals ---\n\n if (schema instanceof z.ZodEnum) {\n return leaf({ enum: schema.options });\n }\n\n if (schema instanceof z.ZodLiteral) {\n return leaf({ enum: [...schema.values] });\n }\n\n // --- Unions & intersections ---\n\n if (schema instanceof z.ZodUnion || schema instanceof z.ZodDiscriminatedUnion) {\n const innerSchemas = new Set<ZodDtoClass>();\n const oneOf = schema.options.map((option) => {\n const { so, selfRequired, innerSchemas: innerSchemas_ } = applySwaggerDecorators(option);\n\n if (!selfRequired) {\n throw new Error('Not required option in oneOf is not supported in Swagger. Use nullable instead.');\n }\n\n innerSchemas_.forEach((innerSchema) => innerSchemas.add(innerSchema));\n\n // Flatten { oneOf: [single_ref] } → just the ref, so union of DTO refs stays clean.\n return so.oneOf?.length === 1 ? so.oneOf[0] : so;\n });\n\n return { so: { oneOf }, selfRequired: true, innerSchemas };\n }\n\n if (schema instanceof z.ZodIntersection) {\n const left = applySwaggerDecorators(schema._zod.def.left as z.ZodType);\n const right = applySwaggerDecorators(schema._zod.def.right as z.ZodType);\n const innerSchemas = new Set([...left.innerSchemas, ...right.innerSchemas]);\n const leftSo = left.so.oneOf?.length === 1 ? left.so.oneOf[0] : left.so;\n const rightSo = right.so.oneOf?.length === 1 ? right.so.oneOf[0] : right.so;\n\n return { so: { allOf: [leftSo, rightSo] }, selfRequired: true, innerSchemas };\n }\n\n // --- Catch-all ---\n\n if (schema instanceof z.ZodAny || schema instanceof z.ZodUnknown) {\n return leaf({});\n }\n\n if (schema instanceof z.ZodUndefined || schema instanceof z.ZodVoid || schema instanceof z.ZodNever) {\n throw new Error(`applySwaggerDecorators: ${(schema as z.ZodType).def.type} cannot be represented in JSON`);\n }\n\n throw new Error(`applySwaggerDecorators: unsupported Zod type \"${(schema as z.ZodType).def.type}\"`);\n};\n","export const mapValues = <K extends string, V, R>(obj: Record<K, V>, fn: (value: V, key: K) => R): Record<K, R> =>\n Object.fromEntries(Object.entries<V>(obj).map(([key, value]) => [key, fn(value, key as K)])) as Record<K, R>;\n","import { BadRequestException, Injectable, type PipeTransform } from '@nestjs/common';\nimport { type ArgumentMetadata } from '@nestjs/common/interfaces';\nimport { isZodDtoClass, toDto, ZodDtoValidationError } from '@voznov/zod-dto';\n\nexport interface ZodValidationPipeOptions {\n createError?: (issues: string[]) => Error;\n}\n\n@Injectable()\nexport class ZodValidationPipe implements PipeTransform {\n private readonly createError: (issues: string[]) => Error;\n\n constructor(options?: ZodValidationPipeOptions) {\n this.createError = options?.createError ?? ((issues) => new BadRequestException(issues));\n }\n\n transform(value: unknown, { metatype }: ArgumentMetadata): unknown {\n if (!metatype || !isZodDtoClass(metatype)) {\n return value;\n }\n\n try {\n return toDto(metatype, value);\n } catch (error) {\n if (error instanceof ZodDtoValidationError) {\n throw this.createError(error.issues);\n }\n throw error;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,kBAAiC;;;ACAjC,qBAA2E;AAC3E,2BAAkC;AAClC,qBAAgD;AAChD,iBAAkB;;;ACHX,IAAM,YAAY,CAAyB,KAAmB,OACnE,OAAO,YAAY,OAAO,QAAW,GAAG,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,KAAK,GAAG,OAAO,GAAQ,CAAC,CAAC,CAAC;;;ADK7F,IAAM,mCAAmC,CAAC,IAAkB,iBAA8C;AACxG,MAAI,WAAW,MAAM,WAAW,MAAM,WAAW,IAAI;AACnD,WAAO,EAAE,GAAG,IAAI,MAAM,OAAO,UAAU,aAAa;AAAA,EACtD;AAEA,SAAO,EAAE,GAAG,IAAI,UAAU,aAAa;AACzC;AAEA,IAAM,OAAO,CAAC,QAAmG;AAAA,EAC/G;AAAA,EACA,cAAc;AAAA,EACd,cAAc,oBAAI,IAAI;AACxB;AAEA,IAAM,sBAAsB,oBAAI,IAAiB;AAMjD,IAAM,oBAAoB,oBAAI,QAA+B;AAI7D,IAAM,iBAAiB,oBAAI,IAAe;AAEn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;AAAA,GACC;;;IHLb,kCAAiB,sBAAsB;","names":["import_zod_dto","import_zod_dto"]}
|
package/dist/index.js
CHANGED
|
@@ -34,7 +34,15 @@ var leaf = (so) => ({
|
|
|
34
34
|
innerSchemas: /* @__PURE__ */ new Set()
|
|
35
35
|
});
|
|
36
36
|
var decoratedDtoClasses = /* @__PURE__ */ new Set();
|
|
37
|
+
var defaultValueCache = /* @__PURE__ */ new WeakMap();
|
|
38
|
+
var lazyInProgress = /* @__PURE__ */ new Set();
|
|
37
39
|
var applySwaggerDecorators = (schema) => {
|
|
40
|
+
const result = applyDecoratorsImpl(schema);
|
|
41
|
+
const description = schema.description;
|
|
42
|
+
if (description) result.so = { ...result.so, description };
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
var applyDecoratorsImpl = (schema) => {
|
|
38
46
|
if (schema instanceof z.ZodObject) {
|
|
39
47
|
if (isZodDtoClass(schema) && decoratedDtoClasses.has(schema)) {
|
|
40
48
|
return { so: { oneOf: refs(schema) }, selfRequired: true, innerSchemas: /* @__PURE__ */ new Set([schema]) };
|
|
@@ -68,9 +76,24 @@ var applySwaggerDecorators = (schema) => {
|
|
|
68
76
|
return { ...applySwaggerDecorators(schema.unwrap()), selfRequired: false };
|
|
69
77
|
}
|
|
70
78
|
if (schema instanceof z.ZodDefault) {
|
|
71
|
-
|
|
79
|
+
const inner = applySwaggerDecorators(schema.unwrap());
|
|
80
|
+
if (!defaultValueCache.has(schema)) defaultValueCache.set(schema, schema._zod.def.defaultValue);
|
|
81
|
+
return { ...inner, so: { ...inner.so, default: defaultValueCache.get(schema) }, selfRequired: false };
|
|
82
|
+
}
|
|
83
|
+
if (schema instanceof z.ZodLazy) {
|
|
84
|
+
if (lazyInProgress.has(schema)) {
|
|
85
|
+
const inner = schema.unwrap();
|
|
86
|
+
if (isZodDtoClass(inner)) return { so: { oneOf: refs(inner) }, selfRequired: true, innerSchemas: /* @__PURE__ */ new Set([inner]) };
|
|
87
|
+
return leaf({});
|
|
88
|
+
}
|
|
89
|
+
lazyInProgress.add(schema);
|
|
90
|
+
try {
|
|
91
|
+
return applySwaggerDecorators(schema.unwrap());
|
|
92
|
+
} finally {
|
|
93
|
+
lazyInProgress.delete(schema);
|
|
94
|
+
}
|
|
72
95
|
}
|
|
73
|
-
if (schema instanceof z.ZodReadonly || schema instanceof z.
|
|
96
|
+
if (schema instanceof z.ZodReadonly || schema instanceof z.ZodCatch) {
|
|
74
97
|
return applySwaggerDecorators(schema.unwrap());
|
|
75
98
|
}
|
|
76
99
|
if (schema instanceof z.ZodNonOptional) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/swagger.ts","../src/utils.ts","../src/pipe.ts"],"sourcesContent":["import { registerOnCreate } from '@voznov/zod-dto';\nimport { applySwaggerDecorators } from './swagger';\n\n// Auto-register swagger decoration on every ZodDto() creation when this package is imported.\nregisterOnCreate(applySwaggerDecorators);\n\nexport { ZodValidationPipe } from './pipe';\nexport type { ZodValidationPipeOptions } from './pipe';\nexport { applySwaggerDecorators } from './swagger';\n","import { ApiExtraModels, ApiProperty, type ApiPropertyOptions, refs } from '@nestjs/swagger';\nimport { type SchemaObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';\nimport { isZodDtoClass, type ZodDtoClass } from '@voznov/zod-dto';\nimport { z } from 'zod';\nimport { mapValues } from './utils';\n\nconst schemaObjectToApiPropertyOptions = (so: SchemaObject, selfRequired: boolean): ApiPropertyOptions => {\n if ('oneOf' in so || 'anyOf' in so || 'allOf' in so) {\n return { ...so, type: Array, required: selfRequired };\n }\n\n return { ...so, required: selfRequired } as ApiPropertyOptions;\n};\n\nconst leaf = (so: SchemaObject): { so: SchemaObject; selfRequired: boolean; innerSchemas: Set<ZodDtoClass> } => ({\n so,\n selfRequired: true,\n innerSchemas: new Set(),\n});\n\nconst decoratedDtoClasses = new Set<ZodDtoClass>();\n\nexport const applySwaggerDecorators = (schema: z.core.$ZodType): { so: SchemaObject; selfRequired: boolean; innerSchemas: Set<ZodDtoClass> } => {\n // --- Objects ---\n\n if (schema instanceof z.ZodObject) {\n if (isZodDtoClass(schema) && decoratedDtoClasses.has(schema)) {\n return { so: { oneOf: refs(schema) }, selfRequired: true, innerSchemas: new Set([schema]) };\n }\n\n const properties: Record<string, SchemaObject> = {};\n const required: string[] = [];\n const innerSchemas = new Set<ZodDtoClass>();\n Object.entries(schema.shape).forEach(([key, fieldSchema]) => {\n const { so, selfRequired, innerSchemas: innerSchemas_ } = applySwaggerDecorators(fieldSchema as z.ZodType);\n properties[key] = so;\n innerSchemas_.forEach((innerSchema) => innerSchemas.add(innerSchema));\n if (selfRequired) {\n required.push(key);\n }\n });\n\n if (isZodDtoClass(schema)) {\n decoratedDtoClasses.add(schema);\n for (const [key, propertySo] of Object.entries(properties)) {\n ApiProperty(schemaObjectToApiPropertyOptions(propertySo, required.includes(key)))(schema.prototype, key);\n }\n ApiExtraModels(...[...innerSchemas.values()].filter((innerSchema) => innerSchema !== schema))(schema);\n\n return { so: { oneOf: refs(schema) }, selfRequired: true, innerSchemas: new Set([schema]) };\n }\n\n return { so: { type: 'object', properties: mapValues(properties, (so) => (so.oneOf?.length === 1 ? so.oneOf[0] : so)), required }, selfRequired: true, innerSchemas };\n }\n\n if (schema instanceof z.ZodRecord) {\n const { so } = applySwaggerDecorators(schema._zod.def.valueType as z.ZodType);\n\n return leaf({ type: 'object', additionalProperties: so.oneOf?.length === 1 ? so.oneOf[0] : so });\n }\n\n // --- Wrappers (unwrap to inner type) ---\n\n if (schema instanceof z.ZodOptional || schema instanceof z.ZodExactOptional) {\n return { ...applySwaggerDecorators(schema.unwrap()), selfRequired: false };\n }\n\n if (schema instanceof z.ZodDefault) {\n return { ...applySwaggerDecorators(schema.unwrap()), selfRequired: false };\n }\n\n if (schema instanceof z.ZodReadonly || schema instanceof z.ZodLazy || schema instanceof z.ZodCatch) {\n return applySwaggerDecorators(schema.unwrap());\n }\n\n if (schema instanceof z.ZodNonOptional) {\n return { ...applySwaggerDecorators(schema.unwrap()), selfRequired: true };\n }\n\n if (schema instanceof z.ZodNullable) {\n const result = applySwaggerDecorators(schema.unwrap());\n\n return { ...result, so: { ...result.so, nullable: true } };\n }\n\n if (schema instanceof z.ZodPipe) {\n // z.preprocess() creates a Pipe(in: ZodTransform, out: schema).\n // For swagger, skip the transform and process the output schema directly.\n const inner = schema.in instanceof z.ZodTransform ? schema.out : schema.in;\n\n return applySwaggerDecorators(inner);\n }\n\n if (schema instanceof z.ZodTransform) {\n return leaf({});\n }\n\n // --- Arrays & tuples ---\n\n if (schema instanceof z.ZodArray) {\n const element = schema.unwrap();\n const { so, selfRequired: selfRequiredElement, innerSchemas } = applySwaggerDecorators(element);\n if (!selfRequiredElement) {\n throw new Error('Not required array item is not supported in Swagger. Use nullable instead.');\n }\n\n return { so: { type: 'array', items: so.oneOf?.length === 1 ? so.oneOf[0] : so }, selfRequired: true, innerSchemas };\n }\n\n if (schema instanceof z.ZodTuple) {\n const itemSchemas = schema._zod.def.items.map((item) => {\n const { so } = applySwaggerDecorators(item);\n\n return so.oneOf?.length === 1 ? so.oneOf[0] : so;\n });\n\n // Deduplicate by JSON representation to collapse identical types\n const unique = [...new Map(itemSchemas.map((s) => [JSON.stringify(s), s])).values()];\n const items = unique.length === 1 ? unique[0] : { oneOf: unique };\n\n return leaf({ type: 'array', items, minItems: itemSchemas.length, maxItems: itemSchemas.length });\n }\n\n // --- Scalars ---\n\n // ZodString: plain z.string(). ZodStringFormat: z.email(), z.uuid(), z.url(), z.ipv4(), etc.\n // Both share the same properties (minLength, maxLength, format).\n if (schema instanceof z.ZodString || schema instanceof z.ZodStringFormat) {\n const so: SchemaObject = { type: 'string' };\n if (schema.minLength !== null) so.minLength = schema.minLength;\n if (schema.maxLength !== null) so.maxLength = schema.maxLength;\n const fmt = schema.format;\n if (fmt !== null) {\n if (fmt === 'regex') {\n // Grab the first regex pattern from the internal bag.\n const patterns = schema._zod.bag.patterns;\n const first = patterns ? [...patterns][0] : undefined;\n if (first) so.pattern = first.source;\n } else {\n so.format = fmt;\n }\n }\n\n return { so, selfRequired: true, innerSchemas: new Set() };\n }\n\n // Number and integer subtypes (ZodInt, ZodNumberFormat, etc.) — all instanceof ZodNumber.\n if (schema instanceof z.ZodNumber) {\n const fmt = schema.format;\n const isInt = fmt === 'int32' || fmt === 'uint32' || fmt === 'safeint';\n const so: SchemaObject = { type: isInt ? 'integer' : 'number' };\n if (schema.minValue !== null && schema.minValue !== Number.MIN_SAFE_INTEGER && Number.isFinite(schema.minValue)) so.minimum = schema.minValue;\n if (schema.maxValue !== null && schema.maxValue !== Number.MAX_SAFE_INTEGER && Number.isFinite(schema.maxValue)) so.maximum = schema.maxValue;\n\n return { so, selfRequired: true, innerSchemas: new Set() };\n }\n\n if (schema instanceof z.ZodBigInt) {\n return leaf({ type: 'integer', format: 'int64' });\n }\n\n if (schema instanceof z.ZodBoolean) {\n return leaf({ type: 'boolean' });\n }\n\n if (schema instanceof z.ZodDate) {\n return leaf({ type: 'string', format: 'date-time' });\n }\n\n if (schema instanceof z.ZodNull) {\n return { so: { nullable: true }, selfRequired: true, innerSchemas: new Set() };\n }\n\n // --- Enums & literals ---\n\n if (schema instanceof z.ZodEnum) {\n return leaf({ enum: schema.options });\n }\n\n if (schema instanceof z.ZodLiteral) {\n return leaf({ enum: [...schema.values] });\n }\n\n // --- Unions & intersections ---\n\n if (schema instanceof z.ZodUnion || schema instanceof z.ZodDiscriminatedUnion) {\n const innerSchemas = new Set<ZodDtoClass>();\n const oneOf = schema.options.map((option) => {\n const { so, selfRequired, innerSchemas: innerSchemas_ } = applySwaggerDecorators(option);\n\n if (!selfRequired) {\n throw new Error('Not required option in oneOf is not supported in Swagger. Use nullable instead.');\n }\n\n innerSchemas_.forEach((innerSchema) => innerSchemas.add(innerSchema));\n\n // Flatten { oneOf: [single_ref] } → just the ref, so union of DTO refs stays clean.\n return so.oneOf?.length === 1 ? so.oneOf[0] : so;\n });\n\n return { so: { oneOf }, selfRequired: true, innerSchemas };\n }\n\n if (schema instanceof z.ZodIntersection) {\n const left = applySwaggerDecorators(schema._zod.def.left as z.ZodType);\n const right = applySwaggerDecorators(schema._zod.def.right as z.ZodType);\n const innerSchemas = new Set([...left.innerSchemas, ...right.innerSchemas]);\n const leftSo = left.so.oneOf?.length === 1 ? left.so.oneOf[0] : left.so;\n const rightSo = right.so.oneOf?.length === 1 ? right.so.oneOf[0] : right.so;\n\n return { so: { allOf: [leftSo, rightSo] }, selfRequired: true, innerSchemas };\n }\n\n // --- Catch-all ---\n\n if (schema instanceof z.ZodAny || schema instanceof z.ZodUnknown) {\n return leaf({});\n }\n\n if (schema instanceof z.ZodUndefined || schema instanceof z.ZodVoid || schema instanceof z.ZodNever) {\n throw new Error(`applySwaggerDecorators: ${(schema as z.ZodType).def.type} cannot be represented in JSON`);\n }\n\n throw new Error(`applySwaggerDecorators: unsupported Zod type \"${(schema as z.ZodType).def.type}\"`);\n};\n","export const mapValues = <K extends string, V, R>(obj: Record<K, V>, fn: (value: V, key: K) => R): Record<K, R> =>\n Object.fromEntries(Object.entries<V>(obj).map(([key, value]) => [key, fn(value, key as K)])) as Record<K, R>;\n","import { BadRequestException, Injectable, type PipeTransform } from '@nestjs/common';\nimport { type ArgumentMetadata } from '@nestjs/common/interfaces';\nimport { isZodDtoClass, toDto, ZodDtoValidationError } from '@voznov/zod-dto';\n\nexport interface ZodValidationPipeOptions {\n createError?: (issues: string[]) => Error;\n}\n\n@Injectable()\nexport class ZodValidationPipe implements PipeTransform {\n private readonly createError: (issues: string[]) => Error;\n\n constructor(options?: ZodValidationPipeOptions) {\n this.createError = options?.createError ?? ((issues) => new BadRequestException(issues));\n }\n\n transform(value: unknown, { metatype }: ArgumentMetadata): unknown {\n if (!metatype || !isZodDtoClass(metatype)) {\n return value;\n }\n\n try {\n return toDto(metatype, value);\n } catch (error) {\n if (error instanceof ZodDtoValidationError) {\n throw this.createError(error.issues);\n }\n throw error;\n }\n }\n}\n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../src/index.ts","../src/swagger.ts","../src/utils.ts","../src/pipe.ts"],"sourcesContent":["import { registerOnCreate } from '@voznov/zod-dto';\nimport { applySwaggerDecorators } from './swagger';\n\n// Auto-register swagger decoration on every ZodDto() creation when this package is imported.\nregisterOnCreate(applySwaggerDecorators);\n\nexport { ZodValidationPipe } from './pipe';\nexport type { ZodValidationPipeOptions } from './pipe';\nexport { applySwaggerDecorators } from './swagger';\n","import { ApiExtraModels, ApiProperty, type ApiPropertyOptions, refs } from '@nestjs/swagger';\nimport { type SchemaObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface';\nimport { isZodDtoClass, type ZodDtoClass } from '@voznov/zod-dto';\nimport { z } from 'zod';\nimport { mapValues } from './utils';\n\nconst schemaObjectToApiPropertyOptions = (so: SchemaObject, selfRequired: boolean): ApiPropertyOptions => {\n if ('oneOf' in so || 'anyOf' in so || 'allOf' in so) {\n return { ...so, type: Array, required: selfRequired };\n }\n\n return { ...so, required: selfRequired } as ApiPropertyOptions;\n};\n\nconst leaf = (so: SchemaObject): { so: SchemaObject; selfRequired: boolean; innerSchemas: Set<ZodDtoClass> } => ({\n so,\n selfRequired: true,\n innerSchemas: new Set(),\n});\n\nconst decoratedDtoClasses = new Set<ZodDtoClass>();\n\n// Snapshot resolved default per schema instance — Zod's `defaultValue` is a getter that\n// re-invokes the thunk on every access. Without this cache, the same `ZodDefault` schema\n// surfaced through two paths (JS subclass, `.extend/.pick/.omit`, shared field reuse, ...)\n// would emit a different value into each occurrence in the spec.\nconst defaultValueCache = new WeakMap<z.ZodDefault, unknown>();\n\n// `z.lazy(() => self)` is the only way to introduce a real cycle in a Zod schema graph.\n// Track each ZodLazy currently being walked so we can break re-entry without overflowing.\nconst lazyInProgress = new Set<z.ZodLazy>();\n\nexport const applySwaggerDecorators = (schema: z.core.$ZodType): { so: SchemaObject; selfRequired: boolean; innerSchemas: Set<ZodDtoClass> } => {\n const result = applyDecoratorsImpl(schema);\n // `.describe(text)` → OpenAPI `description`. Read at every recursion level so the text\n // lands in the spec whether it's set on a wrapper (`.optional().describe(...)`) or on\n // the inner type (`.describe(...).optional()`).\n const description = (schema as z.ZodType).description;\n if (description) result.so = { ...result.so, description };\n\n return result;\n};\n\nconst applyDecoratorsImpl = (schema: z.core.$ZodType): { so: SchemaObject; selfRequired: boolean; innerSchemas: Set<ZodDtoClass> } => {\n // --- Objects ---\n\n if (schema instanceof z.ZodObject) {\n if (isZodDtoClass(schema) && decoratedDtoClasses.has(schema)) {\n return { so: { oneOf: refs(schema) }, selfRequired: true, innerSchemas: new Set([schema]) };\n }\n\n const properties: Record<string, SchemaObject> = {};\n const required: string[] = [];\n const innerSchemas = new Set<ZodDtoClass>();\n Object.entries<z.core.$ZodType>(schema.shape).forEach(([key, fieldSchema]) => {\n const { so, selfRequired, innerSchemas: innerSchemas_ } = applySwaggerDecorators(fieldSchema);\n properties[key] = so;\n innerSchemas_.forEach((innerSchema) => innerSchemas.add(innerSchema));\n if (selfRequired) {\n required.push(key);\n }\n });\n\n if (isZodDtoClass(schema)) {\n decoratedDtoClasses.add(schema);\n for (const [key, propertySo] of Object.entries(properties)) {\n ApiProperty(schemaObjectToApiPropertyOptions(propertySo, required.includes(key)))(schema.prototype, key);\n }\n ApiExtraModels(...[...innerSchemas.values()].filter((innerSchema) => innerSchema !== schema))(schema);\n\n return { so: { oneOf: refs(schema) }, selfRequired: true, innerSchemas: new Set([schema]) };\n }\n\n return { so: { type: 'object', properties: mapValues(properties, (so) => (so.oneOf?.length === 1 ? so.oneOf[0] : so)), required }, selfRequired: true, innerSchemas };\n }\n\n if (schema instanceof z.ZodRecord) {\n const { so } = applySwaggerDecorators(schema._zod.def.valueType);\n\n return leaf({ type: 'object', additionalProperties: so.oneOf?.length === 1 ? so.oneOf[0] : so });\n }\n\n // --- Wrappers (unwrap to inner type) ---\n\n if (schema instanceof z.ZodOptional || schema instanceof z.ZodExactOptional) {\n return { ...applySwaggerDecorators(schema.unwrap()), selfRequired: false };\n }\n\n if (schema instanceof z.ZodDefault) {\n const inner = applySwaggerDecorators(schema.unwrap());\n if (!defaultValueCache.has(schema)) defaultValueCache.set(schema, schema._zod.def.defaultValue);\n\n return { ...inner, so: { ...inner.so, default: defaultValueCache.get(schema) }, selfRequired: false };\n }\n\n if (schema instanceof z.ZodLazy) {\n // `z.lazy(() => self)` is the only way Zod schemas can carry an actual cycle.\n // Track each ZodLazy instance currently being walked; on re-entry, emit a $ref\n // back to the DTO that the lazy resolves to (if any), or a permissive `{}` as a\n // last resort for anonymous self-referential trees.\n if (lazyInProgress.has(schema)) {\n const inner = schema.unwrap();\n if (isZodDtoClass(inner)) return { so: { oneOf: refs(inner) }, selfRequired: true, innerSchemas: new Set([inner]) };\n\n return leaf({});\n }\n lazyInProgress.add(schema);\n try {\n return applySwaggerDecorators(schema.unwrap());\n } finally {\n lazyInProgress.delete(schema);\n }\n }\n\n if (schema instanceof z.ZodReadonly || schema instanceof z.ZodCatch) {\n return applySwaggerDecorators(schema.unwrap());\n }\n\n if (schema instanceof z.ZodNonOptional) {\n return { ...applySwaggerDecorators(schema.unwrap()), selfRequired: true };\n }\n\n if (schema instanceof z.ZodNullable) {\n const result = applySwaggerDecorators(schema.unwrap());\n\n return { ...result, so: { ...result.so, nullable: true } };\n }\n\n if (schema instanceof z.ZodPipe) {\n // z.preprocess() creates a Pipe(in: ZodTransform, out: schema).\n // For swagger, skip the transform and process the output schema directly.\n const inner = schema.in instanceof z.ZodTransform ? schema.out : schema.in;\n\n return applySwaggerDecorators(inner);\n }\n\n if (schema instanceof z.ZodTransform) {\n return leaf({});\n }\n\n // --- Arrays & tuples ---\n\n if (schema instanceof z.ZodArray) {\n const element = schema.unwrap();\n const { so, selfRequired: selfRequiredElement, innerSchemas } = applySwaggerDecorators(element);\n if (!selfRequiredElement) {\n throw new Error('Not required array item is not supported in Swagger. Use nullable instead.');\n }\n\n return { so: { type: 'array', items: so.oneOf?.length === 1 ? so.oneOf[0] : so }, selfRequired: true, innerSchemas };\n }\n\n if (schema instanceof z.ZodTuple) {\n const itemSchemas = schema._zod.def.items.map((item) => {\n const { so } = applySwaggerDecorators(item);\n\n return so.oneOf?.length === 1 ? so.oneOf[0] : so;\n });\n\n // Deduplicate by JSON representation to collapse identical types\n const unique = [...new Map(itemSchemas.map((s) => [JSON.stringify(s), s])).values()];\n const items = unique.length === 1 ? unique[0] : { oneOf: unique };\n\n return leaf({ type: 'array', items, minItems: itemSchemas.length, maxItems: itemSchemas.length });\n }\n\n // --- Scalars ---\n\n // ZodString: plain z.string(). ZodStringFormat: z.email(), z.uuid(), z.url(), z.ipv4(), etc.\n // Both share the same properties (minLength, maxLength, format).\n if (schema instanceof z.ZodString || schema instanceof z.ZodStringFormat) {\n const so: SchemaObject = { type: 'string' };\n if (schema.minLength !== null) so.minLength = schema.minLength;\n if (schema.maxLength !== null) so.maxLength = schema.maxLength;\n const fmt = schema.format;\n if (fmt !== null) {\n if (fmt === 'regex') {\n // Grab the first regex pattern from the internal bag.\n const patterns = schema._zod.bag.patterns;\n const first = patterns ? [...patterns][0] : undefined;\n if (first) so.pattern = first.source;\n } else {\n so.format = fmt;\n }\n }\n\n return { so, selfRequired: true, innerSchemas: new Set() };\n }\n\n // Number and integer subtypes (ZodInt, ZodNumberFormat, etc.) — all instanceof ZodNumber.\n if (schema instanceof z.ZodNumber) {\n const fmt = schema.format;\n const isInt = fmt === 'int32' || fmt === 'uint32' || fmt === 'safeint';\n const so: SchemaObject = { type: isInt ? 'integer' : 'number' };\n if (schema.minValue !== null && schema.minValue !== Number.MIN_SAFE_INTEGER && Number.isFinite(schema.minValue)) so.minimum = schema.minValue;\n if (schema.maxValue !== null && schema.maxValue !== Number.MAX_SAFE_INTEGER && Number.isFinite(schema.maxValue)) so.maximum = schema.maxValue;\n\n return { so, selfRequired: true, innerSchemas: new Set() };\n }\n\n if (schema instanceof z.ZodBigInt) {\n return leaf({ type: 'integer', format: 'int64' });\n }\n\n if (schema instanceof z.ZodBoolean) {\n return leaf({ type: 'boolean' });\n }\n\n if (schema instanceof z.ZodDate) {\n return leaf({ type: 'string', format: 'date-time' });\n }\n\n if (schema instanceof z.ZodNull) {\n return { so: { nullable: true }, selfRequired: true, innerSchemas: new Set() };\n }\n\n // --- Enums & literals ---\n\n if (schema instanceof z.ZodEnum) {\n return leaf({ enum: schema.options });\n }\n\n if (schema instanceof z.ZodLiteral) {\n return leaf({ enum: [...schema.values] });\n }\n\n // --- Unions & intersections ---\n\n if (schema instanceof z.ZodUnion || schema instanceof z.ZodDiscriminatedUnion) {\n const innerSchemas = new Set<ZodDtoClass>();\n const oneOf = schema.options.map((option) => {\n const { so, selfRequired, innerSchemas: innerSchemas_ } = applySwaggerDecorators(option);\n\n if (!selfRequired) {\n throw new Error('Not required option in oneOf is not supported in Swagger. Use nullable instead.');\n }\n\n innerSchemas_.forEach((innerSchema) => innerSchemas.add(innerSchema));\n\n // Flatten { oneOf: [single_ref] } → just the ref, so union of DTO refs stays clean.\n return so.oneOf?.length === 1 ? so.oneOf[0] : so;\n });\n\n return { so: { oneOf }, selfRequired: true, innerSchemas };\n }\n\n if (schema instanceof z.ZodIntersection) {\n const left = applySwaggerDecorators(schema._zod.def.left as z.ZodType);\n const right = applySwaggerDecorators(schema._zod.def.right as z.ZodType);\n const innerSchemas = new Set([...left.innerSchemas, ...right.innerSchemas]);\n const leftSo = left.so.oneOf?.length === 1 ? left.so.oneOf[0] : left.so;\n const rightSo = right.so.oneOf?.length === 1 ? right.so.oneOf[0] : right.so;\n\n return { so: { allOf: [leftSo, rightSo] }, selfRequired: true, innerSchemas };\n }\n\n // --- Catch-all ---\n\n if (schema instanceof z.ZodAny || schema instanceof z.ZodUnknown) {\n return leaf({});\n }\n\n if (schema instanceof z.ZodUndefined || schema instanceof z.ZodVoid || schema instanceof z.ZodNever) {\n throw new Error(`applySwaggerDecorators: ${(schema as z.ZodType).def.type} cannot be represented in JSON`);\n }\n\n throw new Error(`applySwaggerDecorators: unsupported Zod type \"${(schema as z.ZodType).def.type}\"`);\n};\n","export const mapValues = <K extends string, V, R>(obj: Record<K, V>, fn: (value: V, key: K) => R): Record<K, R> =>\n Object.fromEntries(Object.entries<V>(obj).map(([key, value]) => [key, fn(value, key as K)])) as Record<K, R>;\n","import { BadRequestException, Injectable, type PipeTransform } from '@nestjs/common';\nimport { type ArgumentMetadata } from '@nestjs/common/interfaces';\nimport { isZodDtoClass, toDto, ZodDtoValidationError } from '@voznov/zod-dto';\n\nexport interface ZodValidationPipeOptions {\n createError?: (issues: string[]) => Error;\n}\n\n@Injectable()\nexport class ZodValidationPipe implements PipeTransform {\n private readonly createError: (issues: string[]) => Error;\n\n constructor(options?: ZodValidationPipeOptions) {\n this.createError = options?.createError ?? ((issues) => new BadRequestException(issues));\n }\n\n transform(value: unknown, { metatype }: ArgumentMetadata): unknown {\n if (!metatype || !isZodDtoClass(metatype)) {\n return value;\n }\n\n try {\n return toDto(metatype, value);\n } catch (error) {\n if (error instanceof ZodDtoValidationError) {\n throw this.createError(error.issues);\n }\n throw error;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,wBAAwB;;;ACAjC,SAAS,gBAAgB,aAAsC,YAAY;AAC3E,OAAkC;AAClC,SAAS,qBAAuC;AAChD,SAAS,SAAS;;;ACHX,IAAM,YAAY,CAAyB,KAAmB,OACnE,OAAO,YAAY,OAAO,QAAW,GAAG,EAAE,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,KAAK,GAAG,OAAO,GAAQ,CAAC,CAAC,CAAC;;;ADK7F,IAAM,mCAAmC,CAAC,IAAkB,iBAA8C;AACxG,MAAI,WAAW,MAAM,WAAW,MAAM,WAAW,IAAI;AACnD,WAAO,EAAE,GAAG,IAAI,MAAM,OAAO,UAAU,aAAa;AAAA,EACtD;AAEA,SAAO,EAAE,GAAG,IAAI,UAAU,aAAa;AACzC;AAEA,IAAM,OAAO,CAAC,QAAmG;AAAA,EAC/G;AAAA,EACA,cAAc;AAAA,EACd,cAAc,oBAAI,IAAI;AACxB;AAEA,IA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uBAAuB;AAC1C,cAAM,KAAK,YAAY,MAAM,MAAM;AAAA,MACrC;AACA,YAAM;AAAA,IACR;AAAA,EACF;AACF;AArBa,oBAAN;AAAA,EADN,WAAW;AAAA,GACC;;;AHLb,iBAAiB,sBAAsB;","names":["isZodDtoClass","isZodDtoClass"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voznov/zod-dto-nestjs",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "NestJS adapter for @voznov/zod-dto — validation pipe, Swagger generation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"zod",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@nestjs/common": ">=10.0.0",
|
|
49
49
|
"@nestjs/swagger": ">=7.0.0",
|
|
50
50
|
"zod": ">=4.0.0",
|
|
51
|
-
"@voznov/zod-dto": "^0.1
|
|
51
|
+
"@voznov/zod-dto": "^0.2.1"
|
|
52
52
|
},
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|