Skip to content
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

Use latest json-schema draft in tests by default #359

Merged
merged 1 commit into from
Sep 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion test/extended_schema_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def test_extended_schema_validation
def test_unextended_schema
# Verify that using the original schema disregards the `bitwise-and` property
schema = {
"$schema" => "http://json-schema.org/draft-03/schema#",
"properties" => {
"a" => {
"bitwise-and" => 1
Expand Down
55 changes: 25 additions & 30 deletions test/full_validation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ class FullValidationTest < Minitest::Test
def test_full_validation
data = {"b" => {"a" => 5}}
schema = {
"$schema" => "http://json-schema.org/draft-03/schema#",
"type" => "object",
"required" => ["b"],
"properties" => {
"b" => {
"required" => true
}
}
}
Expand All @@ -19,11 +18,10 @@ def test_full_validation

data = {"c" => 5}
schema = {
"$schema" => "http://json-schema.org/draft-03/schema#",
"type" => "object",
"required" => ["b"],
"properties" => {
"b" => {
"required" => true
},
"c" => {
"type" => "string"
Expand All @@ -38,7 +36,6 @@ def test_full_validation
def test_full_validation_with_union_types
data = {"b" => 5}
schema = {
"$schema" => "http://json-schema.org/draft-03/schema#",
"type" => "object",
"properties" => {
"b" => {
Expand All @@ -51,7 +48,6 @@ def test_full_validation_with_union_types
assert(errors.empty?)

schema = {
"$schema" => "http://json-schema.org/draft-03/schema#",
"type" => "object",
"properties" => {
"b" => {
Expand Down Expand Up @@ -111,11 +107,10 @@ def test_full_validation_with_union_types
def test_full_validation_with_object_errors
data = {"b" => {"a" => 5}}
schema = {
"$schema" => "http://json-schema.org/draft-03/schema#",
"type" => "object",
"required" => ["b"],
"properties" => {
"b" => {
"required" => true
}
}
}
Expand All @@ -125,11 +120,10 @@ def test_full_validation_with_object_errors

data = {"c" => 5}
schema = {
"$schema" => "http://json-schema.org/draft-03/schema#",
"type" => "object",
"required" => ["b"],
"properties" => {
"b" => {
"required" => true
},
"c" => {
"type" => "string"
Expand All @@ -138,27 +132,28 @@ def test_full_validation_with_object_errors
}

errors = JSON::Validator.fully_validate(schema,data,:errors_as_objects => true)

assert(errors.length == 2)
assert(errors[0][:failed_attribute] == "Properties")
assert(errors[0][:failed_attribute] == "Required")
assert(errors[0][:fragment] == "#/")
assert(errors[1][:failed_attribute] == "Type")
assert(errors[1][:failed_attribute] == "TypeV4")
assert(errors[1][:fragment] == "#/c")
end

def test_full_validation_with_nested_required_properties
schema = {
"$schema" => "http://json-schema.org/draft-03/schema#",
"type" => "object",
"required" => ["x"],
"properties" => {
"x" => {
"required" => true,
"type" => "object",
"required" => ["a", "b"],
"properties" => {
"a" => {"type"=>"integer","required"=>true},
"b" => {"type"=>"integer","required"=>true},
"c" => {"type"=>"integer","required"=>false},
"d" => {"type"=>"integer","required"=>false},
"e" => {"type"=>"integer","required"=>false},
"a" => {"type"=>"integer"},
"b" => {"type"=>"integer"},
"c" => {"type"=>"integer"},
"d" => {"type"=>"integer"},
"e" => {"type"=>"integer"},
}
}
}
Expand All @@ -168,27 +163,27 @@ def test_full_validation_with_nested_required_properties
errors = JSON::Validator.fully_validate(schema,data,:errors_as_objects => true)
assert_equal 2, errors.length
assert_equal '#/x', errors[0][:fragment]
assert_equal 'Properties', errors[0][:failed_attribute]
assert_equal 'Required', errors[0][:failed_attribute]
assert_equal '#/x/e', errors[1][:fragment]
assert_equal 'Type', errors[1][:failed_attribute]
assert_equal 'TypeV4', errors[1][:failed_attribute]
end

def test_full_validation_with_nested_required_propertiesin_array
schema = {
"$schema" => "http://json-schema.org/draft-03/schema#",
"type" => "object",
"required" => ["x"],
"properties" => {
"x" => {
"required" => true,
"type" => "array",
"items" => {
"type" => "object",
"required" => ["a", "b"],
"properties" => {
"a" => {"type"=>"integer","required"=>true},
"b" => {"type"=>"integer","required"=>true},
"c" => {"type"=>"integer","required"=>false},
"d" => {"type"=>"integer","required"=>false},
"e" => {"type"=>"integer","required"=>false},
"a" => {"type"=>"integer"},
"b" => {"type"=>"integer"},
"c" => {"type"=>"integer"},
"d" => {"type"=>"integer"},
"e" => {"type"=>"integer"},
}
}
}
Expand All @@ -201,8 +196,8 @@ def test_full_validation_with_nested_required_propertiesin_array
errors = JSON::Validator.fully_validate(schema,data,:errors_as_objects => true)
assert_equal 2, errors.length
assert_equal '#/x/0', errors[0][:fragment]
assert_equal 'Properties', errors[0][:failed_attribute]
assert_equal 'Required', errors[0][:failed_attribute]
assert_equal '#/x/1/e', errors[1][:fragment]
assert_equal 'Type', errors[1][:failed_attribute]
assert_equal 'TypeV4', errors[1][:failed_attribute]
end
end
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
{
"$schema": "http://json-schema.org/draft-03/schema#",
"type": "object",
"extends": {"$ref":"inner_schema.json#"},
"properties": {
"outerA": {
"description": "blah",
"required": false,
"additionalProperties": false,
"properties": {
"outerA1": {
"type":"boolean",
"required": false
"type":"boolean"
}
}
},
"outerB": {
"required": false,
"type": "array",
"minItems": 1,
"maxItems": 50,
Expand All @@ -26,8 +22,7 @@
},
"outerC": {
"description": "blah",
"type":"boolean",
"required": false
"type":"boolean"
}
},
"additionalProperties": false
Expand Down
9 changes: 2 additions & 7 deletions test/schemas/extends_and_patternProperties_schema.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
{
"$schema": "http://json-schema.org/draft-03/schema#",
"type": "object",
"extends": {"$ref":"inner_schema.json#"},
"patternProperties": {
"outerA": {
"description": "blah",
"required": false,
"additionalProperties": false,
"properties": {
"outerA1": {
"type":"boolean",
"required": false
"type":"boolean"
}
}
},
"outerB": {
"required": false,
"type": "array",
"minItems": 1,
"maxItems": 50,
Expand All @@ -26,8 +22,7 @@
},
"outerC": {
"description": "blah",
"type":"boolean",
"required": false
"type":"boolean"
}
}
}
9 changes: 4 additions & 5 deletions test/schemas/good_schema_1.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"$schema" : "http://json-schema.org/draft-03/schema#",
"type" : "object",
"properties" : {
"a" : {
"type" : "integer",
"required" : true
"type" : "integer"
}
}
}
},
"required": ["a"]
}
5 changes: 2 additions & 3 deletions test/schemas/good_schema_2.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
{
"$schema" : "http://json-schema.org/draft-03/schema#",
"type" : "object",
"properties" : {
"b" : {
"required" : true,
"$ref" : "good_schema_1.json"
}
}
},
"required": ["b"]
}
2 changes: 0 additions & 2 deletions test/schemas/good_schema_extends1.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
{
"$schema" : "http://json-schema.org/draft-03/schema#",
"type" : "object",
"extends": {"$ref": "good_schema_1.json"},
"properties" : {
"c" : {
"required" : false
}
}
}
2 changes: 0 additions & 2 deletions test/schemas/good_schema_extends2.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{
"$schema" : "http://json-schema.org/draft-03/schema#",
"type" : "object",
"extends": [
{"$ref": "good_schema_1.json"},
{"$ref": "good_schema_2.json"}
],
"properties" : {
"c" : {
"required" : false
}
}
}
8 changes: 2 additions & 6 deletions test/schemas/inner_schema.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
{
"$schema": "http://json-schema.org/draft-03/schema#",
"type": "object",
"properties": {
"innerA": {
"description": "blah",
"type":"boolean",
"required": false
"type":"boolean"
},
"innerB": {
"description": "blah",
"type":"boolean",
"required": false
"type":"boolean"
},
"innerC": {
"description": "blah",
"required": false,
"type": "boolean"
}
}
Expand Down
1 change: 0 additions & 1 deletion test/support/strict_validation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ def test_strict_properties_additional_props

def test_strict_properties_pattern_props
schema = {
"$schema" => "http://json-schema.org/draft-03/schema#",
"properties" => {
"a" => {"type" => "string"},
"b" => {"type" => "string"}
Expand Down