Class: Mountapi::Schema::Object
- Inherits:
-
Object
- Object
- Mountapi::Schema::Object
- Includes:
- Base
- Defined in:
- lib/mountapi/schema/object.rb
Overview
Schema implementation for object
Class Method Summary collapse
-
.to_json_schema(key_name, value) ⇒ Object
Override the Base method to deep validates properties.
Instance Method Summary collapse
-
#cast(value) ⇒ Object
For object we also deep cast properties.
Methods included from Base
Class Method Details
.to_json_schema(key_name, value) ⇒ Object
Override the Base method to deep validates properties
27 28 29 30 31 32 33 34 |
# File 'lib/mountapi/schema/object.rb', line 27 def self.to_json_schema(key_name, value) if key_name == "properties" value = value.inject({}) do |acc, (name, schema)| acc.merge({name => Schema.build(schema).to_json_schema}) end end {key_name => value} end |
Instance Method Details
#cast(value) ⇒ Object
For object we also deep cast properties
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/mountapi/schema/object.rb', line 12 def cast(value) raise_cast_error(value) unless value.is_a?(Hash) open_api_schema.properties.inject({}) do |acc, (k,val)| if value.has_key?(k) acc.merge(k.to_sym => Schema.build(val).cast(value[k])) else acc end end end |