voxpupuli / json-schema

Ruby JSON Schema Validator
MIT License
1.52k stars 241 forks source link

Accept nullable parameter #472

Open ronildosouzafb opened 2 years ago

ronildosouzafb commented 2 years ago

current behavior

schema = {
  "type": "object",
  "properties": {
      "github_url": { "type": "string", "nullable": true }
    }
}

# => The property '#/github_url' of type null did not match the following type: string
JSON::Validator.validate!(schema, { "github_url" => null })

expected behavior

schema = {
  "type": "object",
  "properties": {
      "github_url": { "type": "string", "nullable": true }
    }
}

# => true
JSON::Validator.validate!(schema, { "github_url" => null })

also, without nullable attribute

schema = {
  "type": "object",
  "properties": {
      "github_url": { "type": "string" }
    }
}

# => The property '#/github_url' of type null did not match the following type: string
JSON::Validator.validate!(schema, { "github_url" => null })
bastelfreak commented 2 years ago

Hi @ronildosouzafb , thanks for raising the issue. Are you able provide a PR for this? On which version of json-schema did you see this?

ronildosouzafb commented 1 year ago

Hi @bastelfreak, yeah. I will work on open up a PR for this.

TemaMix commented 1 year ago

@ronildosouzafb Hi I run into the same issue :) do you have any ideas on how to fix it?