class Apipie::Params::Descriptor::Hash

Public Class Methods

build(argument, options, block) click to toggle source
# File lib/apipie/params/descriptor.rb, line 182
def self.build(argument, options, block)
  if block.is_a?(::Proc) && block.arity <= 0 && argument == ::Hash
    self.new(block, options)
  end
end
new(block, options) click to toggle source
Calls superclass method Apipie::Params::Descriptor::Base::new
# File lib/apipie/params/descriptor.rb, line 188
def initialize(block, options)
  super(options)
  @dsl_data = DSL.new(&block)._apipie_params_dsl_data
end

Public Instance Methods

description() click to toggle source
# File lib/apipie/params/descriptor.rb, line 204
def description
  "Must be a Hash"
end
fragment_descriptor(param_description, fragment) click to toggle source
# File lib/apipie/params/descriptor.rb, line 226
def fragment_descriptor(param_description, fragment)
  keys_path = fragment.sub(/\A#\/root\//,'').split('/')
  keys_path.delete_if { |a| a =~ /\A\d+\Z/ }
  keys_path.reduce(param_description) do |description, key|
    description.param(key)
  end
end
invalid_param_error(param_description, error_value, errors) click to toggle source
# File lib/apipie/params/descriptor.rb, line 216
def invalid_param_error(param_description, error_value, errors)
  descriptions = errors.map do |error|
    fragment_descriptor(param_description, error[:fragment])
  end
  # TODO: handle multiple errors at the same time
  invalid_param = descriptions.first
  description = invalid_param.descriptor.description
  Params::Errors::Invalid.new(invalid_param, error_value, description)
end
json_schema() click to toggle source
# File lib/apipie/params/descriptor.rb, line 208
def json_schema
  properties = params.reduce({}) do |hash, description|
    hash.update(description.name.to_s => description.descriptor.json_schema)
  end
  super.merge('type' => 'object',
              'properties' => properties)
end
param(param_name) click to toggle source
# File lib/apipie/params/descriptor.rb, line 200
def param(param_name)
  params.find { |param| param.name.to_s == param_name.to_s }
end
params() click to toggle source
# File lib/apipie/params/descriptor.rb, line 193
def params
  @params ||= @dsl_data.map do |name, arg, options, block|
    Description.new(name, arg, options, &block)
  end
  return @params
end