Class: JSON::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/interpol/endpoint.rb

Overview

Monkey patch json-schema to only allow the defined formats. We’ve been accidentally using invalid formats like “timestamp”, so this will help ensure we only use valid ones.

Constant Summary collapse

VALID_FORMATS =
%w[
  date-time date time utc-millisec regex color style
  phone uri email ip-address ipv6 host-name
]

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.overriden_draft_03Object

Returns the value of attribute overriden_draft_03.



49
50
51
# File 'lib/interpol/endpoint.rb', line 49

def overriden_draft_03
  @overriden_draft_03
end

Instance Method Details

#open(uri) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/interpol/endpoint.rb', line 36

def open(uri)
  return super unless uri.start_with?('file://') && uri.end_with?('draft-03.json')
  return StringIO.new(Validator.overriden_draft_03) if Validator.overriden_draft_03

  schema = JSON.parse(super.read)
  schema.fetch("properties").fetch("format")["enum"] = VALID_FORMATS

  override = JSON.dump(schema)
  Validator.overriden_draft_03 = override
  StringIO.new(override)
end