在环回 model.json 文件中如何进行验证

in loopback model.json file how to give validations

在 model.json 文件中,我尝试按照文档中的说明对数组进行验证 属性,但它不起作用..(我只想通过验证属性进行验证) 如何给出验证数组?..

另请参阅我按照屏幕截图进行了尝试,但没有成功enter image description here

我是 Loopback 的新手,但当前 (v3) documentation 状态:

Warning: This is not yet implemented. You must currently validate in code; see Validating model data.

现在您必须将验证代码放入模型的 JS 文件中。

这是documentation中给出的例子:

common/models/user.js

module.exports = function(user) {
  user.validatesPresenceOf('name', 'email');
  user.validatesLengthOf('password', {min: 5, message: {min: 'Password is too short'}});
  user.validatesInclusionOf('gender', {in: ['male', 'female']});
  user.validatesExclusionOf('domain', {in: ['www', 'billing', 'admin']});
  user.validatesNumericalityOf('age', {int: true});
  user.validatesUniquenessOf('email', {message: 'email is not unique'});
};

这让人想起 Angular 的 Reactive form validation