Skip to content

Feat/validation#13

Merged
GroophyLifefor merged 5 commits intomainfrom
feat/validation
Mar 29, 2025
Merged

Feat/validation#13
GroophyLifefor merged 5 commits intomainfrom
feat/validation

Conversation

@GroophyLifefor
Copy link
Copy Markdown
Member

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:

Middleware Updates:

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

export const validation: ValidationType = {
  query: {
    page: inp().number().integer().min(1).optional(),
    limit: inp().number().integer().range(1, 100),
    isActive: inp().boolean().transform()  // Accepts "true", "1", true, etc.
  },
  body: inp().object({
    username: inp().string().min(3).max(255),
    email: inp().string().email(),
    age: inp().number().range(18, 99),
    acceptTerms: inp().boolean().true(), 
    profile: inp().object({
      bio: inp().string().max(1000).optional(),
      interests: inp().array().every(inp().string()).max(10),
      isPublic: inp().boolean().optional()
    }),
    avatar: inp().file().maxSize(5 * 1024 * 1024).mimeType(['image/jpeg', 'image/png'])
  }),
  formData: {
    files: inp().file()
      .multipleFiles()
      .maxFilesCount(5)
      .maxSize(10 * 1024 * 1024)
      .mimeType(['application/pdf'])
  }
};

@GroophyLifefor GroophyLifefor self-assigned this Mar 28, 2025
@GroophyLifefor GroophyLifefor added the enhancement New feature or request label Mar 28, 2025
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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,

@GroophyLifefor GroophyLifefor linked an issue Mar 28, 2025 that may be closed by this pull request
@GroophyLifefor GroophyLifefor requested a review from Copilot March 28, 2025 17:40
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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) {

Comment thread src/validation/FileZod.ts
@GroophyLifefor GroophyLifefor requested a review from Copilot March 28, 2025 17:45
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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, })),

@GroophyLifefor GroophyLifefor merged commit 8209a54 into main Mar 29, 2025
4 checks passed
@GroophyLifefor GroophyLifefor deleted the feat/validation branch April 15, 2025 09:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Advanced validation for file inputs

2 participants