Module: EasyTalk::RefHelper

Defined in:
lib/easy_talk/ref_helper.rb

Class Method Summary collapse

Class Method Details

.build_ref_schema(type, constraints) ⇒ Object



22
23
24
25
# File 'lib/easy_talk/ref_helper.rb', line 22

def self.build_ref_schema(type, constraints)
  # Remove ref and optional from constraints as they're not JSON Schema keywords
  { '$ref': type.ref_template }.merge(constraints.except(:ref, :optional))
end

.should_use_ref?(type, constraints) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/easy_talk/ref_helper.rb', line 7

def self.should_use_ref?(type, constraints)
  ModelHelper.easytalk_model?(type) && should_use_ref_for_type?(type, constraints)
end

.should_use_ref_for_type?(type, constraints) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
# File 'lib/easy_talk/ref_helper.rb', line 11

def self.should_use_ref_for_type?(type, constraints)
  return false unless ModelHelper.easytalk_model?(type)

  # Per-property constraint takes precedence
  if constraints.key?(:ref)
    constraints[:ref]
  else
    EasyTalk.configuration.use_refs
  end
end