Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions zod.go
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,6 @@ forParts:
} else {
if valValue != "" {
switch valName {
case "required":
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was missed in the previous refactoring (it is not expected here as required tag doesn't have a value)

case "min":
validateStr.WriteString(fmt.Sprintf(".min(%s)", valValue))
case "max":
Expand Down Expand Up @@ -713,7 +712,6 @@ forParts:
switch valName {
case "omitempty":
case "required":
refines = append(refines, ".refine((val) => Object.keys(val).length > 0, 'Empty map')")
case "dive":
break forParts

Expand Down
4 changes: 2 additions & 2 deletions zod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1330,7 +1330,7 @@ func TestMapWithValidations(t *testing.T) {
}
assert.Equal(t,
`export const RequiredSchema = z.object({
Map: z.record(z.string(), z.string()).refine((val) => Object.keys(val).length > 0, 'Empty map'),
Map: z.record(z.string(), z.string()),
})
export type Required = z.infer<typeof RequiredSchema>

Expand Down Expand Up @@ -1720,7 +1720,7 @@ export const UserSchema = z.object({
PostOptional: PostSchema.optional(),
PostOptionalNullable: PostSchema.optional().nullable(),
Metadata: z.record(z.string(), z.string()).nullable(),
MetadataLength: z.record(z.string(), z.string()).refine((val) => Object.keys(val).length > 0, 'Empty map').refine((val) => Object.keys(val).length >= 1, 'Map too small').refine((val) => Object.keys(val).length <= 10, 'Map too large'),
MetadataLength: z.record(z.string(), z.string()).refine((val) => Object.keys(val).length >= 1, 'Map too small').refine((val) => Object.keys(val).length <= 10, 'Map too large'),
MetadataOptional: z.record(z.string(), z.string()).optional(),
MetadataOptionalNullable: z.record(z.string(), z.string()).optional().nullable(),
ExtendedProps: z.any(),
Expand Down
Loading