adiwg-mdjson_schemas 2.0.0.pre.alpha.2 → 2.0.0.pre.alpha.3
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/lib/adiwg/mdjson_schemas/utils.rb +26 -4
- data/lib/adiwg/mdjson_schemas/version.rb +1 -1
- data/test/tu_utils.rb +32 -18
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3cdae95dcf0a460bc93654369b5cf59dfb832a3
|
4
|
+
data.tar.gz: e50163ac9bf8b00fa5a2b44742306167ff9e9377
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f484a68bef624eee01a6b950631efe1a2573858e038e36b8e87da82c416883afd5d82440ebbb10baffc652767bb0b57b19985371261481a2b2139b53de7c76db
|
7
|
+
data.tar.gz: 38a6edb6458cfb3a3351f9196be4d449027fbdf2e363db97b536bbd0e6cf7ac44c2936fa29183a09b5415f8fea8d9bf76a2352ba0a056e30b754e05951ce572a
|
@@ -38,16 +38,18 @@ module ADIWG
|
|
38
38
|
#
|
39
39
|
# @param [Boolean] strict If true, will disallow additional properties
|
40
40
|
# @return [nil]
|
41
|
-
def self.load_schemas(strict=false)
|
41
|
+
def self.load_schemas(strict = false)
|
42
42
|
Dir.glob(schema_dir + '*.json') do |schema|
|
43
43
|
loaded = Utils.load_json(schema)
|
44
44
|
name = File.basename(schema)
|
45
45
|
|
46
46
|
if strict
|
47
47
|
loaded['additionalProperties'] = false
|
48
|
-
loaded['definitions'].
|
49
|
-
|
50
|
-
|
48
|
+
unless loaded['definitions'].nil?
|
49
|
+
loaded['definitions'].each do |_key, val|
|
50
|
+
val['additionalProperties'] = false
|
51
|
+
end
|
52
|
+
end
|
51
53
|
end
|
52
54
|
|
53
55
|
jschema = JSON::Schema.new(loaded, Addressable::URI.parse(name))
|
@@ -55,6 +57,26 @@ module ADIWG
|
|
55
57
|
JSON::Validator.add_schema(jschema)
|
56
58
|
end
|
57
59
|
end
|
60
|
+
|
61
|
+
# Load one schema and make it strict, i.e. additionalProperties=false and
|
62
|
+
# all properties required
|
63
|
+
#
|
64
|
+
# @param [String] schema The filename of the schema to load
|
65
|
+
# @return [Hash] The schema as Ruby hash
|
66
|
+
def self.load_strict(schema)
|
67
|
+
loaded = load_json(schema_dir + schema)
|
68
|
+
loaded['additionalProperties'] = false
|
69
|
+
loaded['required'] = loaded['properties'].keys unless loaded['properties'].nil?
|
70
|
+
|
71
|
+
unless loaded['definitions'].nil?
|
72
|
+
loaded['definitions'].each do |_key, val|
|
73
|
+
val['additionalProperties'] = false
|
74
|
+
val['required'] = val['properties'].keys unless val['properties'].nil?
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
loaded
|
79
|
+
end
|
58
80
|
end
|
59
81
|
end
|
60
82
|
end
|
data/test/tu_utils.rb
CHANGED
@@ -6,27 +6,41 @@ require 'minitest/autorun'
|
|
6
6
|
require File.join(File.dirname(__FILE__), '..', 'lib', 'adiwg-mdjson_schemas.rb')
|
7
7
|
|
8
8
|
class TestUtils < Minitest::Test
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
9
|
+
def test_examples_dir
|
10
|
+
errors = File.exist?(ADIWG::MdjsonSchemas::Utils.examples_dir)
|
11
|
+
assert_equal(true, errors, 'Examples directory does not exist.')
|
12
|
+
end
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def test_schema_path
|
15
|
+
errors = File.file?(ADIWG::MdjsonSchemas::Utils.schema_path)
|
16
|
+
assert_equal(true, errors, 'File schema.json does not exist.')
|
17
|
+
end
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
def test_schema_dir
|
20
|
+
errors = File.exist?(ADIWG::MdjsonSchemas::Utils.schema_dir)
|
21
|
+
assert_equal(true, errors, 'Schema directory does not exist.')
|
22
|
+
end
|
23
23
|
|
24
|
-
|
25
|
-
|
24
|
+
def test_load_schemas
|
25
|
+
assert_nil(ADIWG::MdjsonSchemas::Utils.load_schemas, 'Failed to load schemas.')
|
26
26
|
|
27
|
-
|
27
|
+
JSON::Validator.clear_cache
|
28
28
|
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
assert_nil(ADIWG::MdjsonSchemas::Utils.load_schemas(true), 'Failed to load schemas.')
|
30
|
+
assert_nil(JSON::Validator.schemas.detect { |schema| schema[1].schema['additionalProperties'] }, 'Failed to set additionalProperties.')
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_load_strict
|
34
|
+
loaded = ADIWG::MdjsonSchemas::Utils.load_strict('contact.json')
|
35
|
+
|
36
|
+
assert_kind_of(Hash, loaded, 'Failed to load schema.')
|
37
|
+
|
38
|
+
refute(loaded['additionalProperties'], 'additionalProperties is true')
|
39
|
+
refute_nil(loaded['additionalProperties'], 'additionalProperties is nil')
|
40
|
+
assert_equal(loaded['required'], loaded['properties'].keys, 'All properties not required in main schema')
|
41
|
+
|
42
|
+
refute(loaded['definitions']['address']['additionalProperties'], 'Address additionalProperties is true')
|
43
|
+
refute_nil(loaded['definitions']['address']['additionalProperties'], 'additionalProperties is nil')
|
44
|
+
assert_equal(loaded['definitions']['address']['required'], loaded['definitions']['address']['properties'].keys, 'All properties not required in address schema')
|
45
|
+
end
|
32
46
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: adiwg-mdjson_schemas
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.pre.alpha.
|
4
|
+
version: 2.0.0.pre.alpha.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Bradley, Stan Smith
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|