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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ed64f9aaef3e2938d7acc6be34ed091be662481
4
- data.tar.gz: deff92931b41fe071a4309aefe1ad1faac02d329
3
+ metadata.gz: e3cdae95dcf0a460bc93654369b5cf59dfb832a3
4
+ data.tar.gz: e50163ac9bf8b00fa5a2b44742306167ff9e9377
5
5
  SHA512:
6
- metadata.gz: 597a4975b76df8a187e3f6dd8d94e5f0d92eddcefcab92484b7cf5238f0bd814ab93b0abe9706b5dc8de4fd54e144bee193c9b6d5d4f3c0ae44d9588c6d9fa57
7
- data.tar.gz: d48a83321d27bac628e41662d9326627f804f9c38a2186e7688a47ed863193528979b613b4337a880841293e7cdf0e0cf332a8b32d5ee9a41488504346e5d372
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'].each do |_key, val|
49
- val['additionalProperties'] = false
50
- end unless loaded['definitions'].nil?
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
@@ -1,6 +1,6 @@
1
1
  module ADIWG
2
2
  module MdjsonSchemas
3
3
  # Current schema version number
4
- VERSION = "2.0.0-alpha.2"
4
+ VERSION = "2.0.0-alpha.3"
5
5
  end
6
6
  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
- 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
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
- 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
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
- 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
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
- def test_load_schemas
25
- assert_nil(ADIWG::MdjsonSchemas::Utils.load_schemas, 'Failed to load schemas.')
24
+ def test_load_schemas
25
+ assert_nil(ADIWG::MdjsonSchemas::Utils.load_schemas, 'Failed to load schemas.')
26
26
 
27
- JSON::Validator.clear_cache
27
+ JSON::Validator.clear_cache
28
28
 
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
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.2
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-08 00:00:00.000000000 Z
11
+ date: 2017-02-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler