javascript - NodeJS Ajv 模块总是记录消息'$ref:路径“#”的架构中忽略的关键字'
问题描述
我正在使用 ajv 来验证正文请求。随着每一个请求的到来,ajv 工作正常,但它总是记录消息' $ref:在路径“#”的架构中忽略的关键字'
我有 2 个架构,login.json和login.defs.json
login.defs.json定义一个通用的模式定义,login.json引用它。
登录.json
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"$id": "http://blog-js.com/login.schema#",
"$ref": "login.defs#/definitions/login"
}
login.defs.json
{
"$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
}
}
}
推荐阅读
- java - 如何通过java获取本地IP地址
- php - json响应将int转换为字符串问题laravel
- jquery - 淘汰赛集视图模型字段值
- python - 从 URL Python Pandas 加载 JSON
- javascript - 如何删除反应中不需要的元素?
- reactjs - React useReducer hook,如何处理多个不相关类型的动作?
- next.js - 从 getServerSideProps 或 getStaticProps 获取 NextJs 中菜单项的全局位置
- xml - 使用 Linux perl 程序提取包含特定语言日期值的 Office Open XML 单元格
- java - Android:从 addTextChangedListener 更改为 setOnKeyListener 以使用 Backspace
- javascript - 修复 jQuery 可排序插件的高度和宽度