【问题标题】:minLength not working with String in JSON SchemaminLength 不适用于 JSON 模式中的字符串
【发布时间】:2016-08-14 11:26:12
【问题描述】:

我对节点很陌生,所以可能是我没有正确使用 JSON Schema,如果我错了,请纠正我。

我一直在使用名为 jsonschema 的 npm 模块。

对于使用验证,我正在使用它:

var Validator = require('jsonschema').Validator;
var v = new Validator();
var instance = {
    "user_id"   :   "jesus",
    "password"  :   "password"
};
var schema = {
    "id" : "Login_login",
    "type" : "object",
    "additionalProperties" : false,
    "properties" : {
        "user_id": {
            "type" : "string",
            "required": true,
            "minLenth" : 8,
            "maxLength" : 10,
            "description": "User id to login."
        },
        "password" : {
            "type" : "string",
            "required": true,
            "minLength" : 8,
            "maxLength" : 10,
            "description" : "password to login."
        }
    }
};
var result = v.validate(instance, schema);
console.log('>>>>>> ' + result);

但关键是结果没有出错,虽然 user_idminLength 保持为 8,但我已经传递了 5 个字符,所以如果我没记错的话结果应该抛出相同的错误,为什么会这样 :(

【问题讨论】:

  • 请注意您将minLength 拼写为minLenth...
  • #facepalm,我浪费了将近 1 个小时,然后你来救命了……哈哈,非常感谢……我删除了这个问题,不能面对那么多的屈辱…… .. :D

标签: json node.js jsonschema


【解决方案1】:

架构本身需要验证。它的“user_id”条件“minLength”拼写没有“g”。

【讨论】:

    猜你喜欢
    • 2017-10-07
    • 2012-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多