Class: Swagger::Schema

Inherits:
Hashie::Mash
  • Object
show all
Includes:
Hashie::Extensions::DeepFind, Hashie::Extensions::MergeInitializer, Attachable
Defined in:
lib/swagger/schema.rb

Overview

Represents a Swagger Schema Object, a more deterministic subset of JSON Schema.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Attachable

#attach_parent, #attach_to_children, #root

Constructor Details

#initialize(hash, default = nil) ⇒ Schema

Returns a new instance of Schema.



11
12
13
14
# File 'lib/swagger/schema.rb', line 11

def initialize(hash, default = nil)
  super
  attach_to_children
end

Instance Attribute Details

#parentObject

Returns the value of attribute parent.



9
10
11
# File 'lib/swagger/schema.rb', line 9

def parent
  @parent
end

Instance Method Details

#parseObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/swagger/schema.rb', line 16

def parse
  schema = clone
  if schema.key?('$ref')
    key = schema.delete('$ref')
    model = root.definitions[key]
    schema.merge!(model)
  end

  count = 0
  until schema.refs_resolved?
    raise 'Could not resolve non-remote $refs 5 cycles - circular references?' if count >= 5
    schema.resolve_refs
    count += 1
  end

  schema.to_hash
end