Skip to content

required with empty array causes validation failure #231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
BrunoBonacci opened this issue Jun 5, 2017 · 5 comments
Open

required with empty array causes validation failure #231

BrunoBonacci opened this issue Jun 5, 2017 · 5 comments

Comments

@BrunoBonacci
Copy link

BrunoBonacci commented Jun 5, 2017

using: json-schema-validator "2.2.6"

with this schema

{
  "type": "object",
  "properties": {
    "hello": { "type": "string" }
  },
  "required": []
}

I'm getting the following error:

[ {
  "level" : "fatal",
  "message" : "invalid JSON Schema, cannot continue\nSyntax errors:\n[ {\n  \"level\" : \"error\",\n  \"message\" : \"array must have at least one element\",\n  \"domain\" : \"syntax\",\n  \"schema\" : {\n    \"loadingURI\" : \"#\",\n    \"pointer\" : \"\"\n  },\n  \"keyword\" : \"required\"\n} ]",
  "info" : "other messages follow (if any)"
}, {
  "level" : "error",
  "message" : "array must have at least one element",
  "domain" : "syntax",
  "schema" : {
    "loadingURI" : "#",
    "pointer" : ""
  },
  "keyword" : "required"
} ]

in which it seems to consider invalid "required": [] while the specifications seems to suggest that this is a valid combination:
http://json-schema.org/latest/json-schema-validation.html#rfc.section.6.17

Omitting this keyword has the same behavior as an empty array.

@BrunoBonacci BrunoBonacci changed the title required with empty array caused validation failure required with empty array causes validation failure Jun 5, 2017
@huggsboson
Copy link
Member

My guess is that this changed in newer drafts, you can see in the change log:

Allow empty "required" and "dependencies" arrays

I'd hesitate to adjust this for clients with Draft4 conformance, but I'd love to support newer versions of json-schema draft and am happy to accept PR's.

@LukeDefeo
Copy link

yes this is the correct behaviour for v4

@huggsboson
Copy link
Member

huggsboson commented Jul 10, 2017

would love to get a pull request for v5 (and give the author push/owner access to the project).

@yongnote
Copy link

hi, this will be OK
{
"type": "object",
"properties": {
"hello": { "type": "string" }
}
}

@thedevd
Copy link

thedevd commented Jul 27, 2022

I am stuck in this same issue, not able to get through this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants