Class: OpenApi::DSL::ResponseObj
- Inherits:
-
Hash
- Object
- Hash
- OpenApi::DSL::ResponseObj
- Includes:
- Helpers
- Defined in:
- lib/oas_objs/response_obj.rb
Overview
Instance Attribute Summary collapse
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#media_types ⇒ Object
Returns the value of attribute media_types.
-
#processed ⇒ Object
Returns the value of attribute processed.
Instance Method Summary collapse
- #absorb(desc, media_type, headers: { }, **media_hash) ⇒ Object
-
#initialize(desc) ⇒ ResponseObj
constructor
A new instance of ResponseObj.
- #process ⇒ Object
Methods included from Helpers
#_combined_schema, #arrow_writing_support, #process_schema_input
Constructor Details
#initialize(desc) ⇒ ResponseObj
Returns a new instance of ResponseObj.
14 15 16 17 18 |
# File 'lib/oas_objs/response_obj.rb', line 14 def initialize(desc) self.media_types = [ ] self.headers = { } self.processed = { description: desc } end |
Instance Attribute Details
#headers ⇒ Object
Returns the value of attribute headers.
12 13 14 |
# File 'lib/oas_objs/response_obj.rb', line 12 def headers @headers end |
#media_types ⇒ Object
Returns the value of attribute media_types.
12 13 14 |
# File 'lib/oas_objs/response_obj.rb', line 12 def media_types @media_types end |
#processed ⇒ Object
Returns the value of attribute processed.
12 13 14 |
# File 'lib/oas_objs/response_obj.rb', line 12 def processed @processed end |
Instance Method Details
#absorb(desc, media_type, headers: { }, **media_hash) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/oas_objs/response_obj.rb', line 20 def absorb(desc, media_type, headers: { }, **media_hash) self.processed[:description] = desc if desc.present? self.headers.merge!(headers) media_types << MediaTypeObj.new(media_type, **media_hash) self end |
#process ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/oas_objs/response_obj.rb', line 27 def process content = media_types.map(&:process).reduce({ }, &fusion) processed[:content] = content if content.present? _headers = headers.map do |name, schema| schema = schema.is_a?(Hash) ? schema : { type: schema } [ name, HeaderObj.new(schema.delete(:desc), schema).process ] end.to_h processed[:headers] = _headers if _headers.present? processed end |