turbot-runner 0.1.23 → 0.1.24
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/turbot_runner.rb +0 -2
- data/lib/turbot_runner/processor.rb +7 -70
- data/lib/turbot_runner/version.rb +1 -1
- data/schema/schemas/company-schema.json +69 -22
- data/schema/schemas/financial-payment-schema.json +12 -5
- data/schema/schemas/includes/address.json +36 -13
- data/schema/schemas/includes/alternative_name.json +32 -9
- data/schema/schemas/includes/company-for-nesting.json +70 -23
- data/schema/schemas/includes/company.json +15 -6
- data/schema/schemas/includes/filing.json +48 -16
- data/schema/schemas/includes/financial-payment-data-object.json +73 -21
- data/schema/schemas/includes/identifier.json +14 -8
- data/schema/schemas/includes/industry_code.json +25 -12
- data/schema/schemas/includes/licence-data-object.json +40 -13
- data/schema/schemas/includes/officer.json +66 -46
- data/schema/schemas/includes/organisation.json +6 -5
- data/schema/schemas/includes/permission.json +36 -17
- data/schema/schemas/includes/person.json +14 -13
- data/schema/schemas/includes/person_name.json +36 -12
- data/schema/schemas/includes/previous_name.json +19 -9
- data/schema/schemas/includes/share-parcel-data.json +55 -40
- data/schema/schemas/includes/share-parcel.json +71 -56
- data/schema/schemas/includes/subsidiary-relationship-data.json +19 -8
- data/schema/schemas/includes/total-shares.json +13 -6
- data/schema/schemas/includes/unknown_entity_type.json +6 -5
- data/schema/schemas/licence-schema.json +157 -17
- data/schema/schemas/primary-data-schema.json +18 -16
- data/schema/schemas/share-parcel-schema.json +8 -7
- data/schema/schemas/simple-financial-payment-schema.json +47 -11
- data/schema/schemas/simple-licence-schema.json +21 -6
- data/schema/schemas/simple-subsidiary-schema.json +15 -4
- data/schema/schemas/subsidiary-relationship-schema.json +26 -7
- data/spec/lib/processor_spec.rb +3 -75
- metadata +5 -10
- data/lib/turbot_runner/validator.rb +0 -77
- data/lib/turbot_runner/validators.rb +0 -12
- data/schema/schemas/rich-licence-schema.json +0 -103
- data/spec/lib/validator_spec.rb +0 -235
- data/spec/lib/validators_spec.rb +0 -48
@@ -1,12 +0,0 @@
|
|
1
|
-
require 'date'
|
2
|
-
require 'json-schema'
|
3
|
-
|
4
|
-
date_format_validator = -> value {
|
5
|
-
begin
|
6
|
-
Date.strptime(value, '%Y-%m-%d')
|
7
|
-
rescue ArgumentError
|
8
|
-
raise JSON::Schema::CustomFormatError.new('must be of format yyyy-mm-dd')
|
9
|
-
end
|
10
|
-
}
|
11
|
-
|
12
|
-
JSON::Validator.register_format_validator('date', date_format_validator)
|
@@ -1,103 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"title": "Rich Licence Schema",
|
3
|
-
"description": "A Licence is a permission for an entity to do something that would otherwise not be permitted. Note that such permissions are recorded in multiple different ways and to different granularity. In addition categories cross over, for example a pawnborker may be regulated as a retail establishment by a city, but also as a financial institution by a national or regional financial regulator. Sometimes the licence is a simple statement – the government of Rwanda has given a banking licence to a certain bank -- other times it is fine-grained and highly complex (e.g. an extractives licence or the UK FCA licencing scheme). This schema tries to make it easy to submit the former, while not losing granularity of the latter. The object has the name of Rich Licence to distinguish it from Simple Licence, which it is expected to ultimately replace.",
|
4
|
-
"$schema": "http://json-schema.org/draft-04/schema#",
|
5
|
-
"properties": {
|
6
|
-
"licence_holder": {
|
7
|
-
"properties": {
|
8
|
-
"entity": {
|
9
|
-
"oneOf": [
|
10
|
-
{
|
11
|
-
"properties": {
|
12
|
-
"entity_type": {"enum": ["company"]},
|
13
|
-
"entity_properties": {"$ref": "includes/company-for-nesting.json"}
|
14
|
-
}
|
15
|
-
}, {
|
16
|
-
"properties": {
|
17
|
-
"entity_type": {"enum": ["person"]},
|
18
|
-
"entity_properties": {"$ref": "includes/person.json"}
|
19
|
-
}
|
20
|
-
}, {
|
21
|
-
"properties": {
|
22
|
-
"entity_type": {"enum": ["organisation"]},
|
23
|
-
"entity_properties": {"$ref": "includes/organisation.json"}
|
24
|
-
}
|
25
|
-
}, {
|
26
|
-
"properties": {
|
27
|
-
"entity_type": {"enum": ["unknown"]},
|
28
|
-
"entity_properties": {"$ref": "includes/unknown_entity_type.json"}
|
29
|
-
}
|
30
|
-
}
|
31
|
-
]
|
32
|
-
},
|
33
|
-
"entity_type": {
|
34
|
-
"enum": ["company", "person", "organisation", "unknown_entity_type", null]
|
35
|
-
}
|
36
|
-
}
|
37
|
-
},
|
38
|
-
"licence_issuer": {
|
39
|
-
"oneOf": [
|
40
|
-
{
|
41
|
-
"type": ["string","null"],
|
42
|
-
"minLength": 2
|
43
|
-
},
|
44
|
-
{"$ref": "includes/organisation.json"}
|
45
|
-
]
|
46
|
-
},
|
47
|
-
"licenced_location": {
|
48
|
-
"$ref": "includes/address.json"
|
49
|
-
},
|
50
|
-
"licence_number": {
|
51
|
-
"type": "string"
|
52
|
-
},
|
53
|
-
"start_date": {
|
54
|
-
"description": "The issue date of the licence",
|
55
|
-
"type": "string",
|
56
|
-
"format": "date"
|
57
|
-
},
|
58
|
-
"end_date": {
|
59
|
-
"description": "The expiry date of the licence",
|
60
|
-
"type": "string",
|
61
|
-
"format": "date"
|
62
|
-
},
|
63
|
-
"renewal_date": {
|
64
|
-
"type": "string",
|
65
|
-
"format": "date"
|
66
|
-
},
|
67
|
-
"sample_date": {
|
68
|
-
"description": "Date on which we know this to be true (usually date this information was retrieved from the source)",
|
69
|
-
"type": "string",
|
70
|
-
"format": "date"
|
71
|
-
},
|
72
|
-
"licence_url": {
|
73
|
-
"type": "string",
|
74
|
-
"description": "A public URL for the licence"
|
75
|
-
},
|
76
|
-
"jurisdiction_of_licence": {
|
77
|
-
"type": "string",
|
78
|
-
"description": "The area in which this licence is valid"
|
79
|
-
},
|
80
|
-
"status": {
|
81
|
-
"type": "string",
|
82
|
-
"description": "The status of the licence. If the licence is made up of a number of permissions, each of which has a status, store the status in the permissions field instead/as well"
|
83
|
-
},
|
84
|
-
"category": {
|
85
|
-
"description": "Category of licence",
|
86
|
-
"type": "array",
|
87
|
-
"items": {
|
88
|
-
"type": "string",
|
89
|
-
"enum": ["Financial", "Business", "Extractive"]
|
90
|
-
}
|
91
|
-
},
|
92
|
-
"permissions": {
|
93
|
-
"type": "array",
|
94
|
-
"items": {
|
95
|
-
"$ref": "includes/permission.json"
|
96
|
-
}
|
97
|
-
},
|
98
|
-
"other_attributes": {
|
99
|
-
"description": "Use for other licence attributes for which we don't yet have curated schema attributes"
|
100
|
-
}
|
101
|
-
},
|
102
|
-
"required": ["source_url", "sample_date", "licence_holder", "permissions", "licence_issuer", "jurisdiction_of_licence"]
|
103
|
-
}
|
data/spec/lib/validator_spec.rb
DELETED
@@ -1,235 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe TurbotRunner::Validator do
|
4
|
-
describe 'validation' do
|
5
|
-
specify 'when record is valid' do
|
6
|
-
schema = {
|
7
|
-
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
8
|
-
'type' => 'object',
|
9
|
-
'required' => ['aaa'],
|
10
|
-
}
|
11
|
-
record = {'aaa' => 'zzz'}
|
12
|
-
|
13
|
-
expect([schema, record]).to be_valid
|
14
|
-
end
|
15
|
-
|
16
|
-
specify 'when required top-level property missing' do
|
17
|
-
schema = {
|
18
|
-
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
19
|
-
'type' => 'object',
|
20
|
-
'required' => ['aaa'],
|
21
|
-
}
|
22
|
-
record = {}
|
23
|
-
|
24
|
-
expect([schema, record]).to fail_validation_with(
|
25
|
-
:type => :missing,
|
26
|
-
:path => 'aaa'
|
27
|
-
)
|
28
|
-
end
|
29
|
-
|
30
|
-
specify 'when required nested property missing' do
|
31
|
-
schema = {
|
32
|
-
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
33
|
-
'type' => 'object',
|
34
|
-
'required' => ['aaa'],
|
35
|
-
'properties' => {
|
36
|
-
'aaa' => {
|
37
|
-
'type' => 'object',
|
38
|
-
'required' => ['bbb'],
|
39
|
-
}
|
40
|
-
}
|
41
|
-
}
|
42
|
-
record = {'aaa' => {}}
|
43
|
-
|
44
|
-
expect([schema, record]).to fail_validation_with(
|
45
|
-
:type => :missing,
|
46
|
-
:path => 'aaa.bbb'
|
47
|
-
)
|
48
|
-
end
|
49
|
-
|
50
|
-
context 'when none of oneOf options match' do
|
51
|
-
specify 'and we are switching on an enum field' do
|
52
|
-
schema = {
|
53
|
-
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
54
|
-
'type' => 'object',
|
55
|
-
'required' => ['aaa'],
|
56
|
-
'properties' => {
|
57
|
-
'aaa' => {
|
58
|
-
'type' => 'object',
|
59
|
-
'oneOf' => [{
|
60
|
-
'properties' => {
|
61
|
-
'a_type' => {
|
62
|
-
'enum' => ['a1']
|
63
|
-
},
|
64
|
-
'a_properties' => {
|
65
|
-
'type' => 'object',
|
66
|
-
'required' => ['bbb'],
|
67
|
-
}
|
68
|
-
}
|
69
|
-
}, {
|
70
|
-
'properties' => {
|
71
|
-
'a_type' => {
|
72
|
-
'enum' => ['a2']
|
73
|
-
},
|
74
|
-
'a_properties' => {
|
75
|
-
'type' => 'object',
|
76
|
-
'required' => ['ccc']
|
77
|
-
}
|
78
|
-
}
|
79
|
-
}]
|
80
|
-
}
|
81
|
-
}
|
82
|
-
}
|
83
|
-
|
84
|
-
record = {'aaa' => {'a_type' => 'a1', 'a_properties' => {}}}
|
85
|
-
|
86
|
-
expect([schema, record]).to fail_validation_with(
|
87
|
-
:type => :missing,
|
88
|
-
:path => 'aaa.a_properties.bbb'
|
89
|
-
)
|
90
|
-
end
|
91
|
-
|
92
|
-
specify 'and we are not switching on an enum field' do
|
93
|
-
schema = {
|
94
|
-
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
95
|
-
'type' => 'object',
|
96
|
-
'required' => ['aaa'],
|
97
|
-
'properties' => {
|
98
|
-
'aaa' => {
|
99
|
-
'type' => 'object',
|
100
|
-
'oneOf' => [{
|
101
|
-
'properties' => {
|
102
|
-
'bbb' => {
|
103
|
-
'type' => 'object',
|
104
|
-
'required' => ['ccc'],
|
105
|
-
}
|
106
|
-
}
|
107
|
-
}, {
|
108
|
-
'properties' => {
|
109
|
-
'bbb' => {
|
110
|
-
'type' => 'object',
|
111
|
-
'required' => ['ddd']
|
112
|
-
}
|
113
|
-
}
|
114
|
-
}]
|
115
|
-
}
|
116
|
-
}
|
117
|
-
}
|
118
|
-
|
119
|
-
record = {'aaa' => {'bbb' => {}}}
|
120
|
-
|
121
|
-
expect([schema, record]).to fail_validation_with(
|
122
|
-
:type => :one_of_no_matches,
|
123
|
-
:path => 'aaa'
|
124
|
-
)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
specify 'when top-level property too short' do
|
129
|
-
schema = {
|
130
|
-
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
131
|
-
'type' => 'object',
|
132
|
-
'properties' => {
|
133
|
-
'aaa' => {'minLength' => 2}
|
134
|
-
}
|
135
|
-
}
|
136
|
-
record = {'aaa' => 'x'}
|
137
|
-
|
138
|
-
expect([schema, record]).to fail_validation_with(
|
139
|
-
:type => :too_short,
|
140
|
-
:path => 'aaa',
|
141
|
-
:length => 2
|
142
|
-
)
|
143
|
-
end
|
144
|
-
|
145
|
-
specify 'when nested property too short' do
|
146
|
-
schema = {
|
147
|
-
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
148
|
-
'type' => 'object',
|
149
|
-
'properties' => {
|
150
|
-
'aaa' => {
|
151
|
-
'type' => 'object',
|
152
|
-
'properties' => {
|
153
|
-
'bbb' => {'minLength' => 2}
|
154
|
-
}
|
155
|
-
}
|
156
|
-
}
|
157
|
-
}
|
158
|
-
record = {'aaa' => {'bbb' => 'x'}}
|
159
|
-
|
160
|
-
expect([schema, record]).to fail_validation_with(
|
161
|
-
:type => :too_short,
|
162
|
-
:path => 'aaa.bbb',
|
163
|
-
:length => 2
|
164
|
-
)
|
165
|
-
end
|
166
|
-
|
167
|
-
specify 'when property too long' do
|
168
|
-
schema = {
|
169
|
-
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
170
|
-
'type' => 'object',
|
171
|
-
'properties' => {
|
172
|
-
'aaa' => {'maxLength' => 2}
|
173
|
-
}
|
174
|
-
}
|
175
|
-
record = {'aaa' => 'xxx'}
|
176
|
-
|
177
|
-
expect([schema, record]).to fail_validation_with(
|
178
|
-
:type => :too_long,
|
179
|
-
:path => 'aaa',
|
180
|
-
:length => 2
|
181
|
-
)
|
182
|
-
end
|
183
|
-
|
184
|
-
specify 'when property of wrong type and many types allowed' do
|
185
|
-
schema = {
|
186
|
-
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
187
|
-
'type' => 'object',
|
188
|
-
'properties' => {
|
189
|
-
'aaa' => {'type' => ['number', 'string']}
|
190
|
-
}
|
191
|
-
}
|
192
|
-
record = {'aaa' => ['xxx']}
|
193
|
-
|
194
|
-
expect([schema, record]).to fail_validation_with(
|
195
|
-
:type => :type_mismatch,
|
196
|
-
:path => 'aaa',
|
197
|
-
:allowed_types => ['number', 'string']
|
198
|
-
)
|
199
|
-
end
|
200
|
-
|
201
|
-
specify 'when property of wrong type and single type allowed' do
|
202
|
-
schema = {
|
203
|
-
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
204
|
-
'type' => 'object',
|
205
|
-
'properties' => {
|
206
|
-
'aaa' => {'type' => 'number'}
|
207
|
-
}
|
208
|
-
}
|
209
|
-
record = {'aaa' => 'xxx'}
|
210
|
-
|
211
|
-
expect([schema, record]).to fail_validation_with(
|
212
|
-
:type => :type_mismatch,
|
213
|
-
:path => 'aaa',
|
214
|
-
:allowed_types => ['number']
|
215
|
-
)
|
216
|
-
end
|
217
|
-
|
218
|
-
specify 'when property not in enum' do
|
219
|
-
schema = {
|
220
|
-
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
221
|
-
'type' => 'object',
|
222
|
-
'properties' => {
|
223
|
-
'aaa' => {'enum' => ['a', 'b', 'c']}
|
224
|
-
}
|
225
|
-
}
|
226
|
-
record = {'aaa' => 'z'}
|
227
|
-
|
228
|
-
expect([schema, record]).to fail_validation_with(
|
229
|
-
:type => :enum_mismatch,
|
230
|
-
:path => 'aaa',
|
231
|
-
:allowed_values => ['a', 'b', 'c']
|
232
|
-
)
|
233
|
-
end
|
234
|
-
end
|
235
|
-
end
|
data/spec/lib/validators_spec.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'custom validators' do
|
4
|
-
describe 'for date' do
|
5
|
-
before do
|
6
|
-
@schema = {
|
7
|
-
'$schema' => 'http://json-schema.org/draft-04/schema#',
|
8
|
-
'type' => 'object',
|
9
|
-
'properties' => {
|
10
|
-
'aaa' => {'format' => 'date'}
|
11
|
-
}
|
12
|
-
}
|
13
|
-
end
|
14
|
-
|
15
|
-
specify 'validate valid dates' do
|
16
|
-
strings = [
|
17
|
-
'2015-01-10',
|
18
|
-
'2015-01-10T10:15:57',
|
19
|
-
'2015-01-10T10:15:57Z',
|
20
|
-
'2015-01-10T10:15:57+00:00',
|
21
|
-
'2015-01-10T11:15:57+01:00',
|
22
|
-
'2015-01-10T09:15:57-01:00',
|
23
|
-
'2015-01-10 10:15:57 +0000',
|
24
|
-
'2015-01-10 11:15:57 +0100',
|
25
|
-
'2015-01-10 09:15:57 -0100',
|
26
|
-
]
|
27
|
-
|
28
|
-
strings.each do |string|
|
29
|
-
record = {'aaa' => string}
|
30
|
-
expect([@schema, record]).to be_valid
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
specify 'do not validator invalid dates' do
|
35
|
-
strings = [
|
36
|
-
'nonsense',
|
37
|
-
'2015-01-nonsense',
|
38
|
-
'2015:01:10',
|
39
|
-
'2015/01/10',
|
40
|
-
]
|
41
|
-
|
42
|
-
strings.each do |string|
|
43
|
-
record = {'aaa' => string}
|
44
|
-
expect([@schema, record]).not_to be_valid
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|