Skip to content

SWAGGER - Date cannot be represented in JSON Schema - ZOD 4 #3672

@VigilioYonatan

Description

@VigilioYonatan

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

m\zod@4.2.1\node_modules\zod\v4\core\json-schema-processors.cjs:149
        throw new Error("Date cannot be represented in JSON Schema");
              ^

Error: Date cannot be represented in JSON Schema
    at Object.dateProcessor (C:\Users\user\Desktop\...\node_modules\.pnpm\zod@4.2.1\node_modules\zod\v4\core\json-schema-processors.cjs:149:15)
a
  • My zod schema
export const projectSchema = z.object({
	id: z.number().int().positive(),
	demo_url: z.url().nullable(),
	oficial_url: z.url().nullable(),
	repo_url: z.url().nullable(),
	is_repository_private: z.boolean(), 
	start_date: z.coerce.date(),
	end_date: z.coerce.date().nullable(), 
	portfolio_id: z.number().int().positive(),
}).strict();
import { createZodDto } from "nestjs-zod";
import { z } from "zod";
import { projectSchema } from "../schemas/project.schema";

export const projectStoreDto = projectSchema
	.omit({
		id: true,
		created_at: true,
		updated_at: true,
		
	})
	.extend({
		skill_ids: z.array(z.number()).optional(),
	});

export type ProjectStoreDto = z.infer<typeof projectStoreDto>;


export class ProjectStoreDtoClass extends createZodDto(projectStoreDto) {}


// controller
	@ApiOperation({ summary: "Create a new project" })
	@ApiBody({ type: ProjectStoreDtoClass, description: "Project creation data" })
	@ApiResponse({ status: 201, description: "Project created." })
	@UseGuards(AuthenticatedGuard)
	@UsePipes(new ZodPipe(projectStoreDto))
	@Post("/")
	store(@Body() body: ProjectStoreDto) {
		return this.projectService.store(body);
	}
  • When i comment this nest swagger main, no error in console
const config = new DocumentBuilder()
		.setTitle("Astro-Test API")
		.setDescription("API documentation for Astro-Test project")
		.setVersion("1.0")
		.addTag("users")
		.build();
	const document = SwaggerModule.createDocument(app, config);

	app.use(
		"/reference",
		apiReference({
			content: document,
		}),
	);

Minimum reproduction code

c

Steps to reproduce

No response

Expected behavior

"@nestjs/common": "^11.1.10",
"@nestjs/config": "^4.0.2",
"@nestjs/core": "^11.1.10",
"@nestjs/swagger": "^11.2.3",
"@scalar/nestjs-api-reference": "^1.0.13",

"typescript": "^5.9.3",
zod": "^4.3.2"

Package version

11.2.3

NestJS version

11.1.10

Node.js version

22.16.0

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions