Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Pulling in changes to fix required vs optional issue

  • Loading branch information...
commit 35a3bd51e795c5c57d4de6c2d0979fa16ef379c8 1 parent 9f3c3ef
@NeMO84 authored
Showing with 9 additions and 18 deletions.
  1. +3 −4 lib/jsonschema.rb
  2. +6 −14 test/jsonschema_test.rb
View
7 lib/jsonschema.rb
@@ -45,8 +45,8 @@ def check_property value, schema, key, parent
end
if value == Undefined
- unless schema['optional']
- raise ValueError, "#{key_path}: is missing and it is not optional"
+ if schema['required']
+ raise ValueError, "#{key_path}: is missing and it is required"
end
# default
@@ -78,7 +78,7 @@ def check_property value, schema, key, parent
if schema['items']
if schema['items'].kind_of?(Array)
schema['items'].each_with_index {|val, index|
- check_property(undefined_check(value, index), schema['items'][index], index, value)
+ check_property(undefined_check(value, index), schema['items'][index].merge("required" => true), index, value)
}
if schema.include?('additionalProperties')
additional = schema['additionalProperties']
@@ -310,4 +310,3 @@ def validate data, schema=nil, interactive=true
end
end
end
-
View
20 test/jsonschema_test.rb
@@ -14,7 +14,6 @@ def test_self_schema
"age" => {
"type"=> "integer",
"maximum"=> 125,
- "optional"=> true
}
}
},
@@ -34,7 +33,6 @@ def test_self_schema
"age" => {
"type"=> "integer",
"maximum"=> 125,
- "optional"=> true
}
}
},
@@ -54,7 +52,6 @@ def test_self_schema
"age" => {
"type"=> "integer",
"maximum"=> 125,
- "optional"=> true
}
}
},
@@ -421,7 +418,7 @@ def test_properties
},
"prop02"=>{
"type"=>"number",
- "optional"=>true
+ "required"=>false
},
"prop03"=>{
"type"=>"integer",
@@ -431,14 +428,14 @@ def test_properties
},
"prop05"=>{
"type"=>"object",
- "optional"=>true,
+ "required"=>false,
"properties"=>{
"subprop01"=>{
"type"=>"string",
},
"subprop02"=>{
"type"=>"string",
- "optional"=>false
+ "required"=>true
}
}
}
@@ -499,11 +496,9 @@ def test_requires
"properties"=>{
"prop01"=>{
"type"=>"string",
- "optional"=>true
},
"prop02"=>{
"type"=>"number",
- "optional"=>true,
"requires"=>"prop01"
}
}
@@ -545,7 +540,7 @@ def test_pattern
}
end
- def test_optional
+ def test_required
schema = {
"type"=>"object",
"properties"=>{
@@ -554,14 +549,14 @@ def test_optional
},
"prop02"=>{
"type"=>"number",
- "optional"=>true
+ "required"=>false
},
"prop03"=>{
"type"=>"integer"
},
"prop04"=>{
"type"=>"boolean",
- "optional"=>false
+ "required"=>true
}
}
}
@@ -598,7 +593,6 @@ def test_default
schema1 = {
"properties"=>{
"test"=>{
- "optional"=>true,
"default"=>10
},
}
@@ -606,7 +600,6 @@ def test_default
schema2 = {
"properties"=>{
"test"=>{
- "optional"=>true,
"default"=>10,
"readonly"=>true
}
@@ -996,4 +989,3 @@ def test_disallow
end
end
end
-
Please sign in to comment.
Something went wrong with that request. Please try again.