class Aries::Schema

Public Class Methods

new(schema) click to toggle source

@param Hash [JSON] Json Schema Object @raise [JsonSchema::SchemaError]

# File lib/aries/schema.rb, line 9
def initialize schema
  @schema = ::JsonSchema.parse!(schema).tap(&:expand_references!)
end

Public Instance Methods

base_url() click to toggle source

Find base url of api @return [String] url @raise [Aries::BaseUrlNotFound]

# File lib/aries/schema.rb, line 24
def base_url
  root_link.try(:href) or raise BaseUrlNotFound
end
inspect() click to toggle source
# File lib/aries/schema.rb, line 49
def inspect
  "#<Aries::Schema base_url=#{base_url}>"
end
property_by(href) click to toggle source

@param href [String] @return [JsonSchema::Schema] @example

property_by "#/definitions/apps/definitions/identiry" #=> JsonSchema::Schema
# File lib/aries/schema.rb, line 40
def property_by href
  accessor = href.gsub(/([a-zA-Z0-9\-\_]+)/).to_a
  result = @schema
  accessor.each_with_index do |a, i|
    result = (i % 2) == 0 ? result.send(a.to_sym) : result[a]
  end
  result
end
resources() click to toggle source

Resources of json schema @param [Array<Aries::Resource>]

# File lib/aries/schema.rb, line 15
def resources
  @resources ||= @schema.properties.map do |name, schema|
    Resource.new name, schema, self
  end
end