yaml-schema 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -322,7 +322,10 @@ module YAMLSchema
322
322
  assert_raises UnexpectedTag do
323
323
  Validator.validate({
324
324
  "type" => "object",
325
- "tag" => "aaron"
325
+ "tag" => "aaron",
326
+ "properties" => {
327
+ "foo" => { "type" => "string" }
328
+ }
326
329
  }, ast.children.first)
327
330
  end
328
331
  end
@@ -332,7 +335,10 @@ module YAMLSchema
332
335
  ex = assert_raises UnexpectedTag do
333
336
  Validator.validate({
334
337
  "type" => "object",
335
- "tag" => "aaron"
338
+ "tag" => "aaron",
339
+ "properties" => {
340
+ "foo" => { "type" => "string" }
341
+ }
336
342
  }, ast.children.first)
337
343
  end
338
344
  assert_match(/lolol/, ex.message)
@@ -351,6 +357,9 @@ module YAMLSchema
351
357
  ex = assert_raises UnexpectedType do
352
358
  Validator.validate({
353
359
  "type" => "object",
360
+ "properties" => {
361
+ "foo" => { "type" => "string" }
362
+ }
354
363
  }, ast.children.first)
355
364
  end
356
365
  assert_match(/Mapping/, ex.message)
@@ -359,6 +368,7 @@ module YAMLSchema
359
368
  ex = assert_raises UnexpectedType do
360
369
  Validator.validate({
361
370
  "type" => "array",
371
+ "items" => { "type" => "string" }
362
372
  }, ast.children.first)
363
373
  end
364
374
  assert_match(/Sequence/, ex.message)
@@ -468,6 +478,17 @@ module YAMLSchema
468
478
  end
469
479
  end
470
480
 
481
+ def test_extra_prefix_items_are_allowed
482
+ ast = Psych.parse("- foo\n- 1\n- extra")
483
+ assert Validator.validate({
484
+ "type" => "array",
485
+ "prefixItems" => [
486
+ { "type" => "string" },
487
+ { "type" => "integer" },
488
+ ]
489
+ }, ast.children.first)
490
+ end
491
+
471
492
  def test_invalid_string
472
493
  ast = Psych.parse("1")
473
494
  assert_raises UnexpectedValue do
@@ -731,5 +752,134 @@ bar: *1
731
752
  }, ast.children.first)
732
753
  end
733
754
  end
755
+
756
+ class SchemaValidationTest < Minitest::Test
757
+ def test_missing_type
758
+ assert_raises InvalidSchema do
759
+ Validator.validate({}, Psych.parse("foo").children.first)
760
+ end
761
+ end
762
+
763
+ def test_invalid_type_value
764
+ assert_raises InvalidSchema do
765
+ Validator.validate({ "type" => 42 }, Psych.parse("foo").children.first)
766
+ end
767
+ end
768
+
769
+ def test_unknown_type
770
+ assert_raises InvalidSchema do
771
+ Validator.validate({ "type" => "map" }, Psych.parse("foo").children.first)
772
+ end
773
+ end
774
+
775
+ def test_object_without_properties_or_items
776
+ assert_raises InvalidSchema do
777
+ Validator.validate({
778
+ "type" => "object",
779
+ }, Psych.parse("foo: bar").children.first)
780
+ end
781
+ end
782
+
783
+ def test_array_without_items_or_prefix
784
+ assert_raises InvalidSchema do
785
+ Validator.validate({
786
+ "type" => "array",
787
+ }, Psych.parse("- foo").children.first)
788
+ end
789
+ end
790
+
791
+ def test_invalid_required_type
792
+ assert_raises InvalidSchema do
793
+ Validator.validate({
794
+ "type" => "object",
795
+ "properties" => { "foo" => { "type" => "string" } },
796
+ "required" => "foo",
797
+ }, Psych.parse("foo: bar").children.first)
798
+ end
799
+ end
800
+
801
+ def test_invalid_min_length_type
802
+ assert_raises InvalidSchema do
803
+ Validator.validate({
804
+ "type" => "string",
805
+ "minLength" => "5",
806
+ }, Psych.parse("foo").children.first)
807
+ end
808
+ end
809
+
810
+ def test_invalid_max_items_type
811
+ assert_raises InvalidSchema do
812
+ Validator.validate({
813
+ "type" => "array",
814
+ "items" => { "type" => "string" },
815
+ "maxItems" => "2",
816
+ }, Psych.parse("- foo").children.first)
817
+ end
818
+ end
819
+
820
+ def test_invalid_pattern_type
821
+ assert_raises InvalidSchema do
822
+ Validator.validate({
823
+ "type" => "string",
824
+ "pattern" => "foo",
825
+ }, Psych.parse("foo").children.first)
826
+ end
827
+ end
828
+
829
+ def test_invalid_tag_type
830
+ assert_raises InvalidSchema do
831
+ Validator.validate({
832
+ "type" => "object",
833
+ "tag" => 42,
834
+ "properties" => { "foo" => { "type" => "string" } },
835
+ }, Psych.parse("foo: bar").children.first)
836
+ end
837
+ end
838
+
839
+ def test_invalid_nested_schema
840
+ assert_raises InvalidSchema do
841
+ Validator.validate({
842
+ "type" => "object",
843
+ "properties" => {
844
+ "foo" => { "type" => "bogus" }
845
+ }
846
+ }, Psych.parse("foo: bar").children.first)
847
+ end
848
+ end
849
+
850
+ def test_invalid_prefix_items_type
851
+ assert_raises InvalidSchema do
852
+ Validator.validate({
853
+ "type" => "array",
854
+ "prefixItems" => { "type" => "string" },
855
+ }, Psych.parse("- foo").children.first)
856
+ end
857
+ end
858
+
859
+ def test_invalid_additional_properties_type
860
+ assert_raises InvalidSchema do
861
+ Validator.validate({
862
+ "type" => "object",
863
+ "properties" => { "foo" => { "type" => "string" } },
864
+ "additionalProperties" => "string",
865
+ }, Psych.parse("foo: bar").children.first)
866
+ end
867
+ end
868
+
869
+ def test_valid_union_types
870
+ ast = Psych.parse("foo")
871
+ assert Validator.validate({
872
+ "type" => ["null", "string"],
873
+ }, ast.children.first)
874
+ end
875
+
876
+ def test_invalid_union_type_entry
877
+ assert_raises InvalidSchema do
878
+ Validator.validate({
879
+ "type" => ["string", "bogus"],
880
+ }, Psych.parse("foo").children.first)
881
+ end
882
+ end
883
+ end
734
884
  end
735
885
  end
data/yaml-schema.gemspec CHANGED
@@ -15,5 +15,5 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.add_development_dependency 'rake', '~> 13.0'
17
17
  s.add_development_dependency 'psych', '~> 5.0'
18
- s.add_development_dependency 'minitest', '~> 5.15'
18
+ s.add_development_dependency 'minitest', '>= 5.15'
19
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaml-schema
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aaron Patterson
@@ -41,14 +41,14 @@ dependencies:
41
41
  name: minitest
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - "~>"
44
+ - - ">="
45
45
  - !ruby/object:Gem::Version
46
46
  version: '5.15'
47
47
  type: :development
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - "~>"
51
+ - - ">="
52
52
  - !ruby/object:Gem::Version
53
53
  version: '5.15'
54
54
  description: If you need to validate YAML against a schema, use this
@@ -65,6 +65,9 @@ files:
65
65
  - README.md
66
66
  - Rakefile
67
67
  - lib/yaml-schema.rb
68
+ - lib/yaml-schema/compiler.rb
69
+ - lib/yaml-schema/runtime.rb
70
+ - test/compiler_test.rb
68
71
  - test/pointer_test.rb
69
72
  - test/validator_test.rb
70
73
  - yaml-schema.gemspec
@@ -86,9 +89,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
89
  - !ruby/object:Gem::Version
87
90
  version: '0'
88
91
  requirements: []
89
- rubygems_version: 3.6.9
92
+ rubygems_version: 4.0.20
90
93
  specification_version: 4
91
94
  summary: Validate YAML against a schema
92
95
  test_files:
96
+ - test/compiler_test.rb
93
97
  - test/pointer_test.rb
94
98
  - test/validator_test.rb