3

I'm using ajv to validate body request. With each one request come, ajv working is ok but it always log message ' $ref: keywords ignored in schema at path "#" '

I have 2 schemas, login.json & login.defs.json

login.defs.json to define a common schema definition and login.json refer to it.

login.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
        }
      }
    }
  }
}

Please tell me what wrong I did ?

customcommander
  • 17,580
  • 5
  • 58
  • 84
Vũ Anh Dũng
  • 980
  • 3
  • 13
  • 32

1 Answers1

3

I think it's because you have the additionalProperties keyword set at the wrong place and Ajv is simply telling you about it.

You shouldn't see that message if that was the schema for login.json.

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "http://blog-js.com/login.schema#",
  "$ref": "login.defs#/definitions/login"
}

For login.defs.json that keyword should belong to the schema for 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
    }
  }
}
customcommander
  • 17,580
  • 5
  • 58
  • 84