yaml-schema 1.2.0 → 1.2.1
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.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +2 -0
- data/README.md +20 -20
- data/lib/yaml-schema.rb +14 -14
- data/yaml-schema.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 162c65cfdc841b1a41db7d8f5d865b51a145361bfd1623723d73ad8c8fd7030a
|
|
4
|
+
data.tar.gz: 6a64e47154f5ed2c8910c588add2c5ff4bceeadea4240ccd3469b52277f5fe9f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1223fa2441b84f33b57c1f826658de489b2d36a4d76de7dd9770832f4a5c12e815aeabbc242d557a76c6f074ab1d344610e1131dd9ea86144ded4c54ac740e23
|
|
7
|
+
data.tar.gz: 3c6758c8c5efec97b10d02ade2bc25c8fe9f7f4301b01602333c0178bd57804f4db3fbb24c390139a8e12981a88a85de72686d1efc628e1ddd086ca8e4b7952c
|
data/.github/workflows/ci.yml
CHANGED
data/README.md
CHANGED
|
@@ -11,14 +11,14 @@ A library for validating YAML documents against a schema.
|
|
|
11
11
|
### Basic Validation
|
|
12
12
|
|
|
13
13
|
```ruby
|
|
14
|
-
require
|
|
14
|
+
require "yaml-schema"
|
|
15
15
|
|
|
16
16
|
schema = {
|
|
17
|
-
type
|
|
18
|
-
properties
|
|
19
|
-
name
|
|
20
|
-
age
|
|
21
|
-
active
|
|
17
|
+
"type" => "object",
|
|
18
|
+
"properties" => {
|
|
19
|
+
"name" => { "type" => "string" },
|
|
20
|
+
"age" => { "type" => "integer" },
|
|
21
|
+
"active" => { "type" => "boolean" }
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -53,9 +53,9 @@ Specify multiple valid types for a field:
|
|
|
53
53
|
|
|
54
54
|
```ruby
|
|
55
55
|
schema = {
|
|
56
|
-
type
|
|
57
|
-
properties
|
|
58
|
-
value
|
|
56
|
+
"type" => "object",
|
|
57
|
+
"properties" => {
|
|
58
|
+
"value" => { "type" => ["null", "string"] }
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
```
|
|
@@ -64,17 +64,17 @@ schema = {
|
|
|
64
64
|
|
|
65
65
|
```ruby
|
|
66
66
|
schema = {
|
|
67
|
-
type
|
|
68
|
-
properties
|
|
69
|
-
users
|
|
70
|
-
type
|
|
71
|
-
items
|
|
72
|
-
type
|
|
73
|
-
properties
|
|
74
|
-
name
|
|
75
|
-
tags
|
|
76
|
-
type
|
|
77
|
-
items
|
|
67
|
+
"type" => "object",
|
|
68
|
+
"properties" => {
|
|
69
|
+
"users" => {
|
|
70
|
+
"type" => "array",
|
|
71
|
+
"items" => {
|
|
72
|
+
"type" => "object",
|
|
73
|
+
"properties" => {
|
|
74
|
+
"name" => { "type" => "string" },
|
|
75
|
+
"tags" => {
|
|
76
|
+
"type" => "array",
|
|
77
|
+
"items" => { "type" => "string" }
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
}
|
data/lib/yaml-schema.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module YAMLSchema
|
|
4
|
-
VERSION = "1.2.
|
|
4
|
+
VERSION = "1.2.1"
|
|
5
5
|
|
|
6
6
|
class Pointer
|
|
7
7
|
include Enumerable
|
|
@@ -79,17 +79,17 @@ module YAMLSchema
|
|
|
79
79
|
##
|
|
80
80
|
# Given a particular schema, validate that the node conforms to the
|
|
81
81
|
# schema. Raises an exception if it is invalid
|
|
82
|
-
def self.validate
|
|
82
|
+
def self.validate schema, node, aliases: true
|
|
83
83
|
INSTANCE.validate schema, node, aliases: aliases
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
module NodeInfo # :nodoc:
|
|
87
|
-
def self.read_tag
|
|
87
|
+
def self.read_tag node
|
|
88
88
|
node.tag
|
|
89
89
|
end
|
|
90
90
|
end
|
|
91
91
|
|
|
92
|
-
def initialize
|
|
92
|
+
def initialize node_info = NodeInfo
|
|
93
93
|
@node_info = node_info
|
|
94
94
|
end
|
|
95
95
|
|
|
@@ -98,8 +98,8 @@ module YAMLSchema
|
|
|
98
98
|
##
|
|
99
99
|
# Given a particular schema, validate that the node conforms to the
|
|
100
100
|
# schema. Raises an exception if it is invalid
|
|
101
|
-
def validate
|
|
102
|
-
val = _validate(schema["type"], schema, node, Valid, {}, [
|
|
101
|
+
def validate schema, node, aliases: true
|
|
102
|
+
val = _validate(schema["type"], schema, node, Valid, {}, [], aliases)
|
|
103
103
|
if val.exception
|
|
104
104
|
raise val
|
|
105
105
|
else
|
|
@@ -110,8 +110,8 @@ module YAMLSchema
|
|
|
110
110
|
##
|
|
111
111
|
# Given a particular schema, validate that the node conforms to the
|
|
112
112
|
# schema. Returns an error object if the node is invalid, otherwise false.
|
|
113
|
-
def invalid?
|
|
114
|
-
res = _validate(schema["type"], schema, node, Valid, {}, [
|
|
113
|
+
def invalid? schema, node, aliases: true
|
|
114
|
+
res = _validate(schema["type"], schema, node, Valid, {}, [], aliases)
|
|
115
115
|
if Valid == res
|
|
116
116
|
false
|
|
117
117
|
else
|
|
@@ -121,13 +121,13 @@ module YAMLSchema
|
|
|
121
121
|
|
|
122
122
|
private
|
|
123
123
|
|
|
124
|
-
def make_error
|
|
125
|
-
ex = klass.new msg + " path:
|
|
124
|
+
def make_error klass, msg, path
|
|
125
|
+
ex = klass.new msg + " path: /#{path.join("/")}"
|
|
126
126
|
ex.set_backtrace caller
|
|
127
127
|
ex
|
|
128
128
|
end
|
|
129
129
|
|
|
130
|
-
def _validate
|
|
130
|
+
def _validate type, schema, node, valid, aliases, path, allow_aliases
|
|
131
131
|
return valid if valid.exception
|
|
132
132
|
|
|
133
133
|
if node.anchor
|
|
@@ -188,7 +188,7 @@ module YAMLSchema
|
|
|
188
188
|
if schema["additionalProperties"]
|
|
189
189
|
schema["additionalProperties"]
|
|
190
190
|
else
|
|
191
|
-
return make_error UnexpectedProperty, "unknown property #{key.value.dump}", path
|
|
191
|
+
return make_error UnexpectedProperty, "unknown property #{key.value.dump}", path + [key.value]
|
|
192
192
|
end
|
|
193
193
|
}
|
|
194
194
|
|
|
@@ -289,7 +289,7 @@ module YAMLSchema
|
|
|
289
289
|
when "integer", "float", "time", "date", "symbol"
|
|
290
290
|
found_type = extract_type(node.value)
|
|
291
291
|
unless found_type == type.to_sym
|
|
292
|
-
return make_error UnexpectedValue, "expected #{type}, got #{
|
|
292
|
+
return make_error UnexpectedValue, "expected #{type}, got #{found_type}", path
|
|
293
293
|
end
|
|
294
294
|
else
|
|
295
295
|
raise "unknown type #{schema["type"]}"
|
|
@@ -315,7 +315,7 @@ module YAMLSchema
|
|
|
315
315
|
|[-+]?0x[_]*[0-9a-fA-F][0-9a-fA-F_]* (?# base 16))$/x
|
|
316
316
|
|
|
317
317
|
# Tokenize +string+ returning the Ruby object
|
|
318
|
-
def extract_type
|
|
318
|
+
def extract_type string
|
|
319
319
|
return :null if string.empty?
|
|
320
320
|
# Check for a String type, being careful not to get caught by hash keys, hex values, and
|
|
321
321
|
# special floats (e.g., -.inf).
|
data/yaml-schema.gemspec
CHANGED
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.
|
|
4
|
+
version: 1.2.1
|
|
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
|
|
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
86
86
|
- !ruby/object:Gem::Version
|
|
87
87
|
version: '0'
|
|
88
88
|
requirements: []
|
|
89
|
-
rubygems_version:
|
|
89
|
+
rubygems_version: 4.0.6
|
|
90
90
|
specification_version: 4
|
|
91
91
|
summary: Validate YAML against a schema
|
|
92
92
|
test_files:
|