Feat/validation#13
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR migrates the project’s validation system from Zod to Yelix, updating validation schema definitions, middleware, and OpenAPI integration to align with the new approach.
- Replaces Zod with Yelix in validation files and tests
- Introduces new middleware (requestValidationYelix) and updates OpenAPI schema generation
- Removes old validation middleware and adjusts export paths accordingly
Reviewed Changes
Copilot reviewed 33 out of 35 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/validation/*.ts | New tests for date, boolean, and array validations |
| src/validation/* | New Yelix-based validation classes and rules |
| src/api/middlewares/requestValidationYelix.ts | New middleware for request validation using Yelix |
| src/OpenAPI/* | Updated OpenAPI schema generation to use Yelix schemas |
| mod.ts | Updated export paths and removed deprecated middleware |
Files not reviewed (2)
- deno.json: Language not supported
- jsr.json: Language not supported
Comments suppressed due to low confidence (2)
src/api/middlewares/requestValidationYelix.ts:12
- The error message concatenation is using a mix of '+' and '||' operators, which may lead to unexpected results due to operator precedence. Consider using template literals or adding parentheses to ensure the intended string is built correctly.
throw new Error("Validation schema is not defined for this endpoint. Please define a validation schema in the endpoint file." + request.endpoint?.path || "" + "." || "" + request.endpoint?.methods || "" + ".",);
src/validation/ValidationBase.ts:131
- [nitpick] Using the reserved keyword 'this' as a property name in the ValidateResult object can be confusing and ambiguous. Consider renaming it to something more descriptive, such as 'validatorInstance' or 'context'.
this: this,
There was a problem hiding this comment.
Pull Request Overview
This PR overhauls the validation system by replacing Zod with Yelix for schema validation and integrates the new mechanism into the OpenAPI schema generation and request validation middleware. Key changes include:
- Replacing Zod with Yelix in all validation modules and updating corresponding types.
- Adding new test files for date, boolean, and array validations.
- Updating OpenAPI endpoints and request validation middleware to use the Yelix-based validation system.
Reviewed Changes
Copilot reviewed 33 out of 35 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| test/validation/*.ts | New test cases added for date, boolean, and array validations to ensure Yelix validators function as expected. |
| src/validation/* | Conversion from Zod-based validators to Yelix-based implementation, including rule configuration updates and chaining. |
| src/OpenAPI/* | Updates in OpenAPI example generation and JSON schema conversion to support Yelix-based validators. |
| src/api/middlewares/* | The introduction of a new middleware (requestValidationYelix.ts) to leverage the updated validation system in requests. |
Files not reviewed (2)
- deno.json: Language not supported
- jsr.json: Language not supported
Comments suppressed due to low confidence (2)
src/OpenAPI/Core.ts:92
- When processing date types in the JSON schema, consider adding a 'format' property (e.g., 'date-time') so that consuming tools can properly interpret the data.
else if (type === "date") schema.type = "string";
src/api/middlewares/requestValidationYelix.ts:77
- The recursive function 'lookNewKey' assumes that error messages can be objects containing nested keys, which might lead to unexpected behavior if error messages are simple strings. Consider simplifying the error processing logic to avoid recursive assumptions.
function lookNewKey(msg: any) {
There was a problem hiding this comment.
Pull Request Overview
This PR overhauls the project’s validation system by replacing Zod with a custom Yelix-based validation system, updating the OpenAPI schema generation, and introducing a new request validation middleware. Key changes include:
- Replacing all Zod-based validators with Yelix equivalents in the validation folder.
- Updating middleware to use the new Yelix validation schema (removing legacy requestValidation middleware).
- Adjusting OpenAPI integration to generate examples and JSON schemas based on Yelix validation rules.
Reviewed Changes
Copilot reviewed 33 out of 35 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/validation/*.ts | New tests covering date, boolean, and array validations. |
| src/validation/* | Updated validation classes implementing Yelix logic. |
| src/api/middlewares/requestValidationYelix.ts | New middleware implementation using Yelix validation. |
| src/OpenAPI/* | Updates to use Yelix validators for schema generation. |
| mod.ts | Re-exports adjusted for new validation system and middleware. |
Files not reviewed (2)
- deno.json: Language not supported
- jsr.json: Language not supported
Comments suppressed due to low confidence (2)
src/validation/BooleanZod.ts:98
- The transform rule returns an 'errors' array instead of a simple error value format, which is inconsistent with other rules. Consider returning a consistent error object (e.g. just setting isOk to false and using the rule's failedMessage) to match the format expected by the validation base.
return { isOk: false, errors: [{ message: failedMessage || "Cannot transform value to boolean", key: "", title: "transform" }], };
src/validation/ArrayZod.ts:153
- The error object in the 'every' rule uses a 'path' property instead of 'key', which is inconsistent with the error format used in other validators. Consider renaming 'path' to 'key' for consistency with the rest of the validation system.
errors: isValid ? [] : failedValidations.map((r) => ({ path: `[${r.index}]`, value: r.value, errors: r.errors, })),
This pull request includes significant changes to the validation system and the OpenAPI integration. The most important changes involve replacing Zod with Yelix for validation, updating the OpenAPI schema generation, and adding new validation middleware.
Validation System Overhaul:
src/OpenAPI/Core.ts: Replaced Zod validation with Yelix validation, including methods for generating examples and converting Yelix schemas to JSON schemas. [1] [2] [3] [4]src/OpenAPI/OpenAPI.types.ts: Updated types to useYelixValidationBaseinstead of Zod schemas. [1] [2]Middleware Updates:
src/api/middlewares/requestValidation.ts: Removed the old Zod-based request validation middleware.src/api/middlewares/requestValidationYelix.ts: Added new middleware for request validation using Yelix.Other Changes:
mod.ts: Updated export paths and added new validation exports.deno.json: Added a new test task for validation and updated the version. [1] [2]These changes collectively enhance the validation capabilities of the project by leveraging Yelix, which provides a more flexible and powerful validation system compared to Zod.
Example usage