json-schema
json-schema copied to clipboard
AdditionalProperties does not work as expected
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
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?
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