Skip to content

Commit

Permalink
Use deepmerge instead of merge-deep (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
BenLorantfy authored Oct 20, 2024
1 parent 3aac48f commit fdc9d74
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 113 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
- `zodToOpenAPI` - generate highly accurate Swagger Schema
- Zod DTOs can be used in any `@nestjs/swagger` decorator
- Extended Zod schemas for NestJS (`@nest-zod/z`)
- **Note:** _`@nest-zod/z` is deprecated and will not be supported soon. It is recommended to use `zod` directly. See [MIGRATION.md](./MIGRATION.md) for more information._
- `dateString` for dates (supports casting to `Date`)
- `password` for passwords (more complex string rules + OpenAPI conversion)
- Customization - change exception format easily
Expand Down
3 changes: 2 additions & 1 deletion packages/nestjs-zod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"types": "./dist/index.d.ts",
"files": [
"dist",
"logo.svg",
"dto.d.ts"
],
"sideEffects": false,
Expand Down Expand Up @@ -81,7 +82,7 @@
}
},
"dependencies": {
"merge-deep": "^3.0.3",
"deepmerge": "^4.3.1",
"@nest-zod/z": "*"
}
}
12 changes: 9 additions & 3 deletions packages/nestjs-zod/src/openapi/zod-to-openapi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Type } from '@nestjs/common'
import { SchemaObject } from '@nestjs/swagger/dist/interfaces/open-api-spec.interface'
import mergeDeep from 'merge-deep'
import { z } from '@nest-zod/z'
import deepmerge from 'deepmerge'

interface ExtendedSchemaObject extends SchemaObject {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -225,9 +225,15 @@ export function zodToOpenAPI(

if (is(zodType, z.ZodIntersection)) {
const { left, right } = zodType._def
const merged = mergeDeep(
const merged = deepmerge(
zodToOpenAPI(left, visited),
zodToOpenAPI(right, visited)
zodToOpenAPI(right, visited),
{
arrayMerge: (target, source) => {
const mergedSet = new Set([...target, ...source]);
return Array.from(mergedSet);
}
}
)
Object.assign(object, merged)
}
Expand Down
112 changes: 3 additions & 109 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fdc9d74

Please sign in to comment.