Repository navigation
Conversation
…s and documentation accordingly
There was a problem hiding this comment.
Pull request overview
This PR migrates request schema validation from Joi to Zod across route/auth schemas, and updates TypeScript build configuration, tests, and docs to reflect the new validation behavior and build output structure.
Changes:
- Replace Joi-based schemas with Zod schemas and update the shared validation middleware to use
safeParse. - Split TypeScript configuration into
tsconfig.build.json(emit) andtsconfig.json(typecheck/noEmit), and update build/start/debug scripts accordingly. - Update unit/integration tests and README to reflect Zod validation messages and the new validator behavior.
Reviewed changes
Copilot reviewed 17 out of 19 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| tsconfig.json | Switch to extending build config; set noEmit for typecheck-only config. |
| tsconfig.build.json | New build-focused TS config defining emit/rootDir/outDir. |
| package.json | Update build/check scripts to use build tsconfig; adjust runtime entrypoint path; swap Joi for Zod dependency. |
| package-lock.json | Remove Joi dependency tree; add Zod dependency tree. |
| src/helpers/validator.ts | Replace Joi validation middleware with Zod safeParse; add Zod helper schemas. |
| src/routes/access/schema.ts | Migrate access route schemas from Joi to Zod. |
| src/auth/schema.ts | Migrate auth header schemas from Joi to Zod. |
| src/routes/blog/schema.ts | Migrate blog create/update/url/id schemas from Joi to Zod. |
| src/routes/blogs/schema.ts | Migrate blogs route schemas (pagination/tag/id) from Joi to Zod. |
| src/routes/profile/schema.ts | Migrate profile route schemas from Joi to Zod. |
| tests/routes/blog/writer/unit.test.ts | Update writer blog create route tests to match Zod validation messaging. |
| tests/routes/blog/index/unit.test.ts | Update blog detail-by-url tests to match Zod validation messaging. |
| tests/routes/access/signup/unit.test.ts | Update signup validation tests to match Zod validation messaging. |
| tests/routes/access/login/unit.test.ts | Update login validation tests to match Zod validation messaging. |
| tests/routes/access/login/integration.test.ts | Update login integration validation tests to match Zod validation messaging. |
| tests/auth/authentication/unit.test.ts | Update auth validation test to match new bearer-token validation messaging. |
| README.md | Replace Joi mention with Zod. |
| .vscode/launch.json | Update preLaunch task to build using tsconfig.build.json. |
| .templates/route/schema.ts | Update route schema template from Joi to Zod. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+1
to
+5
| import z from 'zod'; | ||
| import { zAuthBearer } from '../../helpers/validator'; | ||
|
|
||
| export default { | ||
| credential: Joi.object().keys({ | ||
| email: Joi.string().required().email(), | ||
| password: Joi.string().required().min(6), | ||
| credential: z.object({ |
Comment on lines
+1
to
+8
| import z from 'zod'; | ||
| import { Header } from '../core/utils'; | ||
| import { JoiAuthBearer } from '../helpers/validator'; | ||
| import { zAuthBearer } from '../helpers/validator'; | ||
|
|
||
| export default { | ||
| apiKey: Joi.object() | ||
| .keys({ | ||
| [Header.API_KEY]: Joi.string().required(), | ||
| }) | ||
| .unknown(true), | ||
| auth: Joi.object() | ||
| .keys({ | ||
| authorization: JoiAuthBearer().required(), | ||
| }) | ||
| .unknown(true), | ||
| apiKey: z.looseObject({ [Header.API_KEY]: z.string() }), | ||
| auth: z.looseObject({ | ||
| authorization: zAuthBearer(), |
| @@ -1,29 +1,29 @@ | |||
| import Joi from 'joi'; | |||
| import { JoiObjectId, JoiUrlEndpoint } from '../../helpers/validator'; | |||
| import z from 'zod'; | |||
Comment on lines
+15
to
+18
| blogUrl: zUrlEndpoint(200), | ||
| imgUrl: z.url().max(200).optional(), | ||
| score: z.number().min(0).max(1).optional(), | ||
| tags: z.array(z.string().toUpperCase()).min(1).optional(), |
Comment on lines
+24
to
+27
| blogUrl: zUrlEndpoint(200).optional(), | ||
| imgUrl: z.url().max(200).optional(), | ||
| score: z.number().min(0).max(1).optional(), | ||
| tags: z.array(z.string().toUpperCase()).min(1).optional(), |
Comment on lines
+1
to
+10
| import z from 'zod'; | ||
| import { zObjectId } from '../../helpers/validator'; | ||
|
|
||
| export default { | ||
| userId: Joi.object().keys({ | ||
| id: JoiObjectId().required(), | ||
| userId: z.object({ | ||
| id: zObjectId(), | ||
| }), | ||
| profile: Joi.object().keys({ | ||
| name: Joi.string().min(1).max(200).optional(), | ||
| profilePicUrl: Joi.string().uri().optional(), | ||
| profile: z.object({ | ||
| name: z.string().min(1).max(200).optional(), | ||
| profilePicUrl: z.url().optional(), |
| @@ -1,18 +1,18 @@ | |||
| import Joi from 'joi'; | |||
| import { JoiObjectId } from '../../helpers/validator'; | |||
| import z from 'zod'; | |||
Comment on lines
+25
to
32
| /** | ||
| * | ||
| * @param schema Any z.ZodType (z.object, z.email, z.string, etc.) | ||
| * @param source Part of the request to validate (default: 'body') | ||
| */ | ||
| export default ( | ||
| schema: Joi.AnySchema, | ||
| schema: z.ZodType, | ||
| source: ValidationSource = ValidationSource.BODY, |
Comment on lines
132
to
134
| expect(response.body.message).toMatch(/imgUrl/i); | ||
| expect(response.body.message).toMatch(/valid uri/i); | ||
| expect(response.body.message).toMatch(/valid url/i); | ||
| expect(mockBlogFindUrlIfExists).not.toHaveBeenCalled(); |
Comment on lines
+16
to
+18
| /** Validates an "Authorization: Bearer <token>" header value */ | ||
| export const zAuthBearer = () => | ||
| z.string().regex(/^Bearer\s.+$/, 'invalid bearer token'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…s and documentation accordingly