Javascript NodeJS Ajv模块始终记录消息'$ref:在路径“处的架构中忽略关键字”#&引用';
我用ajv来验证身体请求。随着每个请求的到来,ajv工作正常,但它总是记录消息“$ref:在路径“#”的模式中忽略的关键字” 我有两个模式,login.json&login.defs.jsonJavascript NodeJS Ajv模块始终记录消息'$ref:在路径“处的架构中忽略关键字”#&引用';,javascript,node.js,jsonschema,ajv,Javascript,Node.js,Jsonschema,Ajv,我用ajv来验证身体请求。随着每个请求的到来,ajv工作正常,但它总是记录消息“$ref:在路径“#”的模式中忽略的关键字” 我有两个模式,login.json&login.defs.json { "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "$id": "http://blog-js.com/login.schema#", "$ref": "login.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"$id": "http://blog-js.com/login.schema#",
"$ref": "login.defs#/definitions/login"
}
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://blog-js.com/login.defs#",
"additionalProperties": false,
"definitions": {
"login": {
"type": "object",
"required": [
"account",
"password"
],
"properties": {
"account": {
"description": "The account or email of user",
"type": "string",
"minLength": 1,
"maxLength": 255
},
"password": {
"description": "The password of user",
"type": "string",
"minLength": 1,
"maxLength": 32
}
}
}
}
}
login.defs.json定义公共模式定义,并login.json引用它
login.json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"$id": "http://blog-js.com/login.schema#",
"$ref": "login.defs#/definitions/login"
}
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://blog-js.com/login.defs#",
"additionalProperties": false,
"definitions": {
"login": {
"type": "object",
"required": [
"account",
"password"
],
"properties": {
"account": {
"description": "The account or email of user",
"type": "string",
"minLength": 1,
"maxLength": 255
},
"password": {
"description": "The password of user",
"type": "string",
"minLength": 1,
"maxLength": 32
}
}
}
}
}
login.defs.json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"$id": "http://blog-js.com/login.schema#",
"$ref": "login.defs#/definitions/login"
}
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://blog-js.com/login.defs#",
"additionalProperties": false,
"definitions": {
"login": {
"type": "object",
"required": [
"account",
"password"
],
"properties": {
"account": {
"description": "The account or email of user",
"type": "string",
"minLength": 1,
"maxLength": 255
},
"password": {
"description": "The password of user",
"type": "string",
"minLength": 1,
"maxLength": 32
}
}
}
}
}
请告诉我我做错了什么?我想这是因为你在错误的地方设置了
additionalProperties
关键字,而Ajv只是告诉你而已
如果这是login.json
的模式,则不应该看到该消息
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://blog-js.com/login.schema#",
"$ref": "login.defs#/definitions/login"
}
对于login.defs.json
,该关键字应属于login
的模式:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://blog-js.com/login.defs#",
"definitions": {
"login": {
"type": "object",
"required": [
"account",
"password"
],
"properties": {
"account": {
"description": "The account or email of user",
"type": "string",
"minLength": 1,
"maxLength": 255
},
"password": {
"description": "The password of user",
"type": "string",
"minLength": 1,
"maxLength": 32
}
},
"additionalProperties": false
}
}
}
成功了。但我认为ajv的信息并不明确。谢谢