Class: Gitlab::GrapeOpenapi::Models::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/grape_openapi/models/response.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status_code:, description:, entity_class:, headers: {}, content_type: 'application/json', example: nil, examples: nil) ⇒ Response

Returns a new instance of Response.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/gitlab/grape_openapi/models/response.rb', line 10

def initialize(
  status_code:, description:, entity_class:, headers: {}, content_type: 'application/json',
  example: nil, examples: nil)
  @status_code = status_code.to_s
  @description = description
  @entity_class = entity_class
  @headers = headers
  @content_type = content_type
  @example = example
  @examples = examples
end

Instance Attribute Details

#content_typeObject (readonly)

Returns the value of attribute content_type.



8
9
10
# File 'lib/gitlab/grape_openapi/models/response.rb', line 8

def content_type
  @content_type
end

#descriptionObject (readonly)

Returns the value of attribute description.



8
9
10
# File 'lib/gitlab/grape_openapi/models/response.rb', line 8

def description
  @description
end

#entity_classObject (readonly)

Returns the value of attribute entity_class.



8
9
10
# File 'lib/gitlab/grape_openapi/models/response.rb', line 8

def entity_class
  @entity_class
end

#headersObject (readonly)

Returns the value of attribute headers.



8
9
10
# File 'lib/gitlab/grape_openapi/models/response.rb', line 8

def headers
  @headers
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



8
9
10
# File 'lib/gitlab/grape_openapi/models/response.rb', line 8

def status_code
  @status_code
end

Instance Method Details

#to_h(schema_registry) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/gitlab/grape_openapi/models/response.rb', line 22

def to_h(schema_registry)
  response = {
    description: description,
    content: {
      content_type => {
        schema: { '$ref' => schema_ref(schema_registry) },
        example: @example,
        examples: @examples
      }.compact
    }
  }

  response[:headers] = headers if headers.any?

  response
end