Class: OasParser::RequestBody
- Includes:
- RawAccessor
- Defined in:
- lib/oas_parser/request_body.rb
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#raw ⇒ Object
Returns the value of attribute raw.
Instance Method Summary collapse
- #deep_safe_merge(source_hash, new_hash) ⇒ Object
- #handle_all_of(schema) ⇒ Object
-
#initialize(endpoint, raw) ⇒ RequestBody
constructor
A new instance of RequestBody.
- #properties_for_format(format) ⇒ Object
- #split_properties_for_format(format) ⇒ Object
Methods included from RawAccessor
included, #method_missing, #respond_to_missing?
Methods inherited from Payload
#exhibits_one_of_multiple_schemas?, #formats, #schema, #split_schemas
Constructor Details
#initialize(endpoint, raw) ⇒ RequestBody
Returns a new instance of RequestBody.
8 9 10 11 |
# File 'lib/oas_parser/request_body.rb', line 8 def initialize(endpoint, raw) @endpoint = endpoint @raw = raw end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class OasParser::RawAccessor
Instance Attribute Details
#endpoint ⇒ Object
Returns the value of attribute endpoint.
6 7 8 |
# File 'lib/oas_parser/request_body.rb', line 6 def endpoint @endpoint end |
#raw ⇒ Object
Returns the value of attribute raw.
6 7 8 |
# File 'lib/oas_parser/request_body.rb', line 6 def raw @raw end |
Instance Method Details
#deep_safe_merge(source_hash, new_hash) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/oas_parser/request_body.rb', line 47 def deep_safe_merge(source_hash, new_hash) source_hash.merge(new_hash) do |key, old, new| if new.respond_to?(:blank) && new.blank? old elsif (old.kind_of?(Hash) and new.kind_of?(Hash)) old.deep_merge(new) elsif (old.kind_of?(Array) and new.kind_of?(Array)) old.concat(new).uniq else new end end end |
#handle_all_of(schema) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/oas_parser/request_body.rb', line 30 def handle_all_of(schema) newSchema = {} if schema['allOf'] schema['allOf'].each do |p| newSchema = deep_safe_merge(newSchema, p) if newSchema['allOf'] newSchema = deep_safe_merge(newSchema, handle_all_of(newSchema)) newSchema.delete('allOf') end end else newSchema = schema end newSchema end |
#properties_for_format(format) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/oas_parser/request_body.rb', line 13 def properties_for_format(format) s = schema(format) s = handle_all_of(s) s['properties'].map do |name, definition| OasParser::Property.new(self, s, name, definition) end end |
#split_properties_for_format(format) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'lib/oas_parser/request_body.rb', line 21 def split_properties_for_format(format) split_schemas(format).map do |schema| schema = handle_all_of(schema) schema['properties'].map do |name, definition| OasParser::Property.new(self, schema, name, definition) end end end |