json - minLength 不适用于 JSON 架构中的字符串

标签 json node.js jsonschema

我对 Node 还很陌生,所以可能是我没有正确使用 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 个字符,所以如果我没有错,结果应该会抛出一个错误,为什么会这样 :(

最佳答案

架构本身需要验证。其“user_id”条件“minLength”拼写不带“g”。

关于json - minLength 不适用于 JSON 架构中的字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38941752/

相关文章:

mysql - 如何正确地将 uuid 转换为 BINARY(16)?

python - 将 JSON 模式转换为 python 类

远程枚举的 JSON Schema 语法

python - 如何在 django 模型实例中转换 json?

javascript - 构建一个简单的 Node.js 抓取功能

node.js - Meteor: Unexpected mongo exit code 14. Restarting.Can't start mongo server

javascript - 为什么JOI比AJV更受欢迎?

json - 无法解码golang回应

java - 通过json在python和java之间传递对象

json - 我该怎么做呢?将结构作为接口(interface)发送到函数并将其作为结构取回?