Class: Eazypi::Response

Inherits:
Object
  • Object
show all
Includes:
SpecObject
Defined in:
lib/eazypi/response.rb

Overview

OpenAPI spec ResponseObject

Instance Method Summary collapse

Methods included from SpecObject

included, #load

Constructor Details

#initializeResponse

Returns a new instance of Response.



10
11
12
13
14
15
# File 'lib/eazypi/response.rb', line 10

def initialize
  @content = {}
  @object_type = {}

  super
end

Instance Method Details

#collect_components(**kwargs) ⇒ Object



34
35
36
37
38
# File 'lib/eazypi/response.rb', line 34

def collect_components(**kwargs)
  @content.each_value do |media_type|
    media_type.collect_components(**kwargs)
  end
end

#content(schema, content_type = "application/json") ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/eazypi/response.rb', line 17

def content(schema, content_type = "application/json")
  return if schema.nil?

  media_type = MediaType.new

  media_type.load do
    schema Schema.from_object(schema)
  end

  @content[content_type] = media_type
  @object_type[content_type] = schema
end

#object_type_for_content_type(content_type = "application/json") ⇒ Object



30
31
32
# File 'lib/eazypi/response.rb', line 30

def object_type_for_content_type(content_type = "application/json")
  @object_type[content_type]
end

#to_openapi_specObject



40
41
42
43
44
45
# File 'lib/eazypi/response.rb', line 40

def to_openapi_spec
  {
    "description" => description,
    "content" => @content.empty? ? nil : @content.transform_values(&:to_openapi_spec)
  }.compact
end