Sha256: 15449ce7db4bf864487b3e58a83eab72151d0a0b84adefff96fa3d252eefa96f
Contents?: true
Size: 1.22 KB
Versions: 1
Compression:
Stored size: 1.22 KB
Contents
module Swagger class Schema < Hashie::Mash include Attachable include Hashie::Extensions::MergeInitializer include Hashie::Extensions::DeepFind attr_accessor :parent def initialize(hash, default = nil) super attach_to_children end 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? fail 'Could not resolve non-remote $refs 5 cycles - circular references?' if count >= 5 schema.resolve_refs count += 1 end schema.to_hash end protected def refs deep_find_all('$ref') end def resolve_refs items_and_props = [deep_select('items'), deep_select('properties')].flatten.compact items_and_props.each do | item | key = item.delete('$ref') next if remote_ref? key model = root.definitions[key] item.merge!(model) end end def refs_resolved? return true if refs.nil? refs.all? do |ref| remote_ref?(ref) end end def remote_ref?(ref) ref.match(%r{\A\w+\://}) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
swagger-core-0.2.0 | lib/swagger/schema.rb |