voxpupuli / json-schema

Ruby JSON Schema Validator
MIT License
1.53k stars 242 forks source link

AdditionalProperties does not work as expected #280

Open llopez opened 8 years ago

llopez commented 8 years ago

Hi everyone,

Given:

schema = {
  properties: {
    prop_1: { type: 'string' },
    prop_2: { type: 'string' }
  },
  additionalProperties: false
}

I want the below to be valid

data = {prop_1: 'xxx'}
data = {prop_2: 'xxx'}
data = {prop_1: 'xxx', prop_2: 'xxx'}

I want the below to not be valid

data = {prop_x: 'xxx'}

But it does not work that way :)

My code:

JSON::Validator.new(schema, data).validate
RST-J commented 8 years ago

I cannot reproduce your issue. Using json-schema 2.5.2 and MRI 2.2.3 all data is validated as expected, the first three pass, the last one causes a validation error complaining about the disallowed property prop_x. What version of json-schema and which Ruby are you using?

wangchj commented 1 year ago

additionalProperties also doesn't work for me. I'm using version

json-schema  4.0.0
Ruby ruby 3.2.2 (2023-03-30 revision e51014f9c0) [x86_64-darwin21]
Rails 7.0.5