interpol 0.8.1 → 0.9.0

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.
@@ -21,6 +21,32 @@ module JSON
21
21
  end
22
22
  end
23
23
  end
24
+
25
+ # Monkey patch json-schema to only allow the defined formats.
26
+ # We've been accidentally using invalid formats like "timestamp",
27
+ # so this will help ensure we only use valid ones.
28
+ class Validator
29
+ VALID_FORMATS = %w[
30
+ date-time date time utc-millisec regex color style
31
+ phone uri email ip-address ipv6 host-name
32
+ ]
33
+
34
+ def open(uri)
35
+ return super unless uri.start_with?('file://') && uri.end_with?('draft-03.json')
36
+ return StringIO.new(Validator.overriden_draft_03) if Validator.overriden_draft_03
37
+
38
+ schema = JSON.parse(super.read)
39
+ schema.fetch("properties").fetch("format")["enum"] = VALID_FORMATS
40
+
41
+ override = JSON.dump(schema)
42
+ Validator.overriden_draft_03 = override
43
+ StringIO.new(override)
44
+ end
45
+
46
+ class << self
47
+ attr_accessor :overriden_draft_03
48
+ end
49
+ end
24
50
  end
25
51
 
26
52
  module Interpol
@@ -212,18 +238,32 @@ module Interpol
212
238
  private
213
239
 
214
240
  def make_schema_strict!(raw_schema, modify_object=true)
215
- return unless Hash === raw_schema
241
+ case raw_schema
242
+ when Hash then make_schema_hash_strict!(raw_schema, modify_object)
243
+ when Array then make_schema_array_strict!(raw_schema, modify_object)
244
+ end
245
+ end
216
246
 
247
+ def make_schema_hash_strict!(raw_schema, modify_object=true)
217
248
  raw_schema.each do |key, value|
218
249
  make_schema_strict!(value, key != 'properties')
219
250
  end
220
251
 
221
252
  return unless modify_object
222
253
 
223
- raw_schema['additionalProperties'] ||= false
254
+ if raw_schema.has_key?('properties')
255
+ raw_schema['additionalProperties'] ||= false
256
+ end
257
+
224
258
  raw_schema['required'] = !raw_schema.delete('optional')
225
259
  end
226
260
 
261
+ def make_schema_array_strict!(raw_schema, modify_object=true)
262
+ raw_schema.each do |entry|
263
+ make_schema_strict!(entry, modify_object)
264
+ end
265
+ end
266
+
227
267
  def extract_examples_from(definition)
228
268
  fetch_from(definition, 'examples').map do |ex|
229
269
  EndpointExample.new(ex, self)
@@ -1,3 +1,4 @@
1
1
  module Interpol
2
- VERSION = "0.8.1"
2
+ VERSION = "0.9.0"
3
3
  end
4
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interpol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-18 00:00:00.000000000 Z
12
+ date: 2013-02-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rack
@@ -34,14 +34,14 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 1.0.10
37
+ version: 1.1.1
38
38
  none: false
39
39
  type: :runtime
40
40
  version_requirements: !ruby/object:Gem::Requirement
41
41
  requirements:
42
42
  - - ~>
43
43
  - !ruby/object:Gem::Version
44
- version: 1.0.10
44
+ version: 1.1.1
45
45
  none: false
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: nokogiri