code: function (values, next) {
      const api = path.basename(__filename, '.js').toLowerCase();
  
      if (strapi.api.hasOwnProperty(api) && _.size(strapi.api[api].templates)) {
        const template = _.includes(strapi.api[api].templates, values.template) ? values.template : strapi.models[api].defaultTemplate;
  
        // Set template with correct value
        values.template = template;
  
        // Merge model type with template validations
        const templateAttributes = _.merge(_.pick(strapi.models[api].attributes, 'lang'), strapi.api[api].templates[template].attributes);
        const err = [];
  
        _.forEach(templateAttributes, function (rules, key) {
          if (values.hasOwnProperty(key) || key === 'lang') {
            if (key === 'lang') {
              // Set lang with correct value
              values[key] = _.includes(strapi.config.i18n.locales, values[key]) ? values[key] : strapi.config.i18n.defaultLocale;
            } else {
              // Check validations
              const rulesTest = anchor(values[key]).to(rules);
  
              if (rulesTest) {
                err.push(rulesTest[0]);
              }
            }
          } else {
            rules.required && err.push({
              rule: 'required',
              message: 'Missing attributes ' + key
            });
          }
        });
  
        // Go next step or not
        _.isEmpty(err) ? next() : next(err);
      } else {
        next(new Error('Unknow API or no template detected'));
      }
    }
docs: Lifecycle callbacks
   Before validate