Strapi Plugin Validator

screenshot of Strapi Plugin Validator
strapi

A strapi plugin to tunning strapi validations

Overview

The strapi-plugin-validator is a plugin created on top of the Indicative project, maintained by Adonis.js. Its purpose is to simplify the management of validations on Strapi projects and enhance the standard validation of Strapi content-types. It provides a better response structure to the frontend.

Features

  • Simplifies the management of validations on Strapi projects
  • Enhances the standard validation of Strapi content-types
  • Provides a better response structure to the frontend

The file validators.json

To integrate the plugin with your project, create a new file called validators.json inside your content-types, extensions, or plugins folders. Here is an example structure for the file:

{
  "validators": {
    "user": {
      "message": "Bad Request",
      "rules": {
        // Validation rules here
      }
    }
  }
}

The validators property is mandatory and serves to configure the plugin. You can have multiple validators inside it for different purposes. The user property in this example is an identifier for your validator, and it can be any name you want. It will be used to relate validators to each other if necessary.

Inside the user validator, you can provide a message property (optional) with a generic fail message for the request. If not provided, the default message is "Bad Request". The rules property should contain the validation rules for the validator.

Validation rules

The rules property supports three types of value structure: Array, Object, or String.

  • Array: Each item in the array represents a validation rule, identified by a string. You can find the list of available validation rules in the Indicative project's documentation or create custom validations.
  • Object: The object structure allows you to associate a customized message with a validation rule. The key of the object represents the validation rule, while the value is the customized message.
  • String: A string value represents a path to another validator.

For more information on available validation rules and customization, refer to the Indicative project documentation.

Summary

The strapi-plugin-validator is a plugin that simplifies the management of validations in Strapi projects. It enhances the standard validation of Strapi content-types and provides a better response structure to the frontend. By creating a validators.json file and configuring validators with the desired rules, developers can easily enforce validation in their Strapi applications.

strapi
Strapi

Strapi is an open source headless CMS that provides a customizable content management system and API for your projects. It allows you to manage content in a visual interface and use a REST or GraphQL API to retrieve the data.