idcf-json_hyper_schema 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +4 -0
- data/.rspec +1 -0
- data/.rubocop.yml +2 -0
- data/README.md +1 -1
- data/idcf-json_hyper_schema.gemspec +0 -1
- data/lib/idcf/json_hyper_schema/analyst.rb +15 -3
- data/lib/idcf/json_hyper_schema/expands/base.rb +11 -9
- data/lib/idcf/json_hyper_schema/expands/link_info_base.rb +2 -2
- data/lib/idcf/json_hyper_schema/validation.rb +50 -0
- data/lib/idcf/json_hyper_schema/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf6fd0e7a80ec0ef552e19bccec568431e293887
|
4
|
+
data.tar.gz: 0881a485385f89b213f7491e6485f6f1a7bae38a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a82bc9a88edb0460e2bb77b3a017dea8628db49497caf0fe6e5a96cb40b585951f440eca62b76d5e8e82bf191aef97ceb2563739c9ff58a10e75aad2437c69fd
|
7
|
+
data.tar.gz: 0374d508d3728696cb5464b3ed7a49135b43f328c04dc92e4de51111518215e47a05b36b695598549b81b8e57533678adbcdc5688f1c7c4dd9fb0005f3a4bf8d
|
data/.codeclimate.yml
CHANGED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,19 @@
|
|
1
|
+
require 'json_schema'
|
2
|
+
require 'idcf/json_hyper_schema/validation'
|
1
3
|
module Idcf
|
2
4
|
module JsonHyperSchema
|
3
5
|
# json-hyper-schema analyst
|
4
6
|
class Analyst
|
5
7
|
attr_reader :process_version, :schema, :load_schema
|
6
8
|
|
9
|
+
def json_schema_init
|
10
|
+
configuration = JsonSchema.configuration
|
11
|
+
Idcf::JsonHyperSchema::Validation.validations.each do |key, val|
|
12
|
+
configuration.register_format(key, val)
|
13
|
+
end
|
14
|
+
self
|
15
|
+
end
|
16
|
+
|
7
17
|
# json file laod
|
8
18
|
#
|
9
19
|
# @param path [String]
|
@@ -40,6 +50,7 @@ module Idcf
|
|
40
50
|
#
|
41
51
|
# @return Expands::LinkInfoBase
|
42
52
|
def links
|
53
|
+
json_schema_init
|
43
54
|
p_schema = JsonSchema.parse!(@load_schema)
|
44
55
|
@process_version = schema_version(p_schema)
|
45
56
|
p_schema.expand_references!
|
@@ -53,8 +64,9 @@ module Idcf
|
|
53
64
|
# @return Expands::LinkInfoBase
|
54
65
|
def schema_links(schema, options = {})
|
55
66
|
ex_schema = expand(schema, options)
|
56
|
-
|
57
|
-
|
67
|
+
json_schema_init
|
68
|
+
p_schema = JsonSchema.parse!(ex_schema.schema)
|
69
|
+
t_v = @process_version
|
58
70
|
p_schema.expand_references!
|
59
71
|
result = find_links(p_schema)
|
60
72
|
@process_version = t_v
|
@@ -95,7 +107,7 @@ module Idcf
|
|
95
107
|
result << link_obj
|
96
108
|
end
|
97
109
|
|
98
|
-
schema.properties.
|
110
|
+
schema.properties.each_value do |sub|
|
99
111
|
result.concat(find_links(sub))
|
100
112
|
end
|
101
113
|
end
|
@@ -55,7 +55,7 @@ module Idcf
|
|
55
55
|
def make_ids(schema)
|
56
56
|
{}.tap do |result|
|
57
57
|
next if schema['definitions'].nil?
|
58
|
-
schema['definitions'].
|
58
|
+
schema['definitions'].each_value do |v|
|
59
59
|
result[v['id']] = v.deep_dup unless v['id'].nil?
|
60
60
|
result.merge!(search_child_ids(v))
|
61
61
|
end
|
@@ -63,14 +63,15 @@ module Idcf
|
|
63
63
|
end
|
64
64
|
|
65
65
|
def search_child_ids(child)
|
66
|
-
{}
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
66
|
+
result = {}
|
67
|
+
return result unless child.class == Hash
|
68
|
+
child.each_value do |v|
|
69
|
+
next unless v.class == Hash
|
70
|
+
id = v['id']
|
71
|
+
result[id] = v.deep_dup unless id.nil?
|
72
|
+
result.merge!(search_child_ids(v))
|
73
73
|
end
|
74
|
+
result
|
74
75
|
end
|
75
76
|
|
76
77
|
def delete_id(data)
|
@@ -95,7 +96,8 @@ module Idcf
|
|
95
96
|
end
|
96
97
|
|
97
98
|
def exp_hash(schema)
|
98
|
-
schema.keys
|
99
|
+
list = schema.keys
|
100
|
+
list.each do |k|
|
99
101
|
exp = expansion(k, schema[k])
|
100
102
|
if k == '$ref' && exp.class == Hash
|
101
103
|
schema.delete(k)
|
@@ -132,10 +132,10 @@ module Idcf
|
|
132
132
|
param = args.deep_dup
|
133
133
|
next unless param.class == Hash
|
134
134
|
param = param.stringify_keys
|
135
|
-
make_query_params(args).
|
135
|
+
make_query_params(args).each_key do |qk|
|
136
136
|
param.delete(qk)
|
137
137
|
end
|
138
|
-
properties.
|
138
|
+
properties.each_key do |pk|
|
139
139
|
result[pk] = param[pk] if param.key?(pk)
|
140
140
|
end
|
141
141
|
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'json_schema'
|
2
|
+
module Idcf
|
3
|
+
module JsonHyperSchema
|
4
|
+
# json-hyper-schema validation
|
5
|
+
class Validation
|
6
|
+
class << self
|
7
|
+
attr_reader :add_validation
|
8
|
+
|
9
|
+
def reset_format
|
10
|
+
@add_validation = {}
|
11
|
+
self
|
12
|
+
end
|
13
|
+
|
14
|
+
def register_format(name, validator_proc)
|
15
|
+
@add_validation ||= {}
|
16
|
+
@add_validation[name] = validator_proc
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def validations
|
21
|
+
@add_validation ||= {}
|
22
|
+
custom_validations.merge(@add_validation)
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def custom_validations
|
28
|
+
{
|
29
|
+
'ipv4_cidr' => lambda do |data|
|
30
|
+
ip_check(data, JsonSchema::Validator::IPV4_PATTERN)
|
31
|
+
end,
|
32
|
+
'ipv6_cidr' => lambda do |data|
|
33
|
+
ip_check(data, JsonSchema::Validator::IPV6_PATTERN)
|
34
|
+
end,
|
35
|
+
'integer' => lambda do |data|
|
36
|
+
data =~ /^[0-9]+$/
|
37
|
+
end
|
38
|
+
}
|
39
|
+
end
|
40
|
+
|
41
|
+
def ip_check(data, pattern)
|
42
|
+
list = data.split('/')
|
43
|
+
return false unless list.size == 2
|
44
|
+
return false unless list[0] =~ pattern
|
45
|
+
list[1] =~ /^[0-9]*$/
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: idcf-json_hyper_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- IDC Frontier Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -114,6 +114,7 @@ extra_rdoc_files: []
|
|
114
114
|
files:
|
115
115
|
- ".codeclimate.yml"
|
116
116
|
- ".gitignore"
|
117
|
+
- ".rspec"
|
117
118
|
- ".rubocop.yml"
|
118
119
|
- Gemfile
|
119
120
|
- Gemfile.lock
|
@@ -128,6 +129,7 @@ files:
|
|
128
129
|
- lib/idcf/json_hyper_schema/expands/link_info_base.rb
|
129
130
|
- lib/idcf/json_hyper_schema/expands/link_info_v4.rb
|
130
131
|
- lib/idcf/json_hyper_schema/expands/v4.rb
|
132
|
+
- lib/idcf/json_hyper_schema/validation.rb
|
131
133
|
- lib/idcf/json_hyper_schema/version.rb
|
132
134
|
homepage: https://www.idcfcloud.jp
|
133
135
|
licenses:
|
@@ -149,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
151
|
version: '0'
|
150
152
|
requirements: []
|
151
153
|
rubyforge_project:
|
152
|
-
rubygems_version: 2.6.
|
154
|
+
rubygems_version: 2.6.13
|
153
155
|
signing_key:
|
154
156
|
specification_version: 4
|
155
157
|
summary: IDCF Json-Hyper-Schema Expand tools
|