Class: Mountapi::Schema::Array

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/mountapi/schema/array.rb

Overview

Schema implementation for Array

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

included

Class Method Details

.to_json_schema(key_name, value) ⇒ Object

for array we also transform items to json_schema



21
22
23
24
25
26
# File 'lib/mountapi/schema/array.rb', line 21

def self.to_json_schema(key_name, value)
  if key_name == "items"
    value = Schema.build(value).to_json_schema
  end
  { key_name => value }
end

Instance Method Details

#cast(array) ⇒ Object

cast the inbound value and it’s items in case of array we already expect an array. (from rack Query parser)

Parameters:

  • value (Object)

    the inbound value for this schema



13
14
15
16
17
18
# File 'lib/mountapi/schema/array.rb', line 13

def cast(array)
  raise_cast_error(array) unless array.is_a?(::Array)
  array.to_a.map do |item|
    Schema.build(open_api_schema.items).cast(item)
  end
end