Skip to content

Custom data validation producing AJV-style errors #3072

Answered by Romakita
ilyutov asked this question in Q&A
Discussion options

You must be logged in to vote

Hello @ilyutov

You can use this code example:

import {nameOf} from "@tsed/core";
import {JsonParameterStore} from "@tsed/schema";

import {ValidationError} from "./ValidationError.js";

export class RequiredValidationError extends ValidationError {
  public name: string = "REQUIRED_VALIDATION_ERROR";

  static from(metadata: JsonParameterStore) {
    const name = nameOf(metadata.paramType);
    const expression = metadata.expression;
    const type = name.toLowerCase().replace(/parse|params|filter/gi, "");
    const message = `It should have required parameter '${expression}'`;

    const errors = [
      {
        dataPath: "",
        keyword: "required",
        message,
        modelName

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ilyutov
Comment options

Answer selected by ilyutov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants