Class: Apipie::Generator::Swagger::MethodDescription::ResponseSchemaService

Inherits:
Object
  • Object
show all
Defined in:
lib/apipie/generator/swagger/method_description/response_schema_service.rb

Instance Method Summary collapse

Constructor Details

#initialize(response_description, allow_null:, http_method:, controller_method:) ⇒ ResponseSchemaService

Returns a new instance of ResponseSchemaService.



3
4
5
6
7
8
# File 'lib/apipie/generator/swagger/method_description/response_schema_service.rb', line 3

def initialize(response_description, allow_null:, http_method:, controller_method:)
  @response_description = response_description
  @allow_null = allow_null
  @http_method = http_method
  @controller_method = controller_method
end

Instance Method Details

#to_swaggerObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/apipie/generator/swagger/method_description/response_schema_service.rb', line 10

def to_swagger
  composite = Apipie::Generator::Swagger::ParamDescription::Composite.new(
    @response_description.params_ordered,
    Apipie::Generator::Swagger::Context.new(
      allow_null: @allow_null,
      http_method: @http_method,
      controller_method: @controller_method
    )
  )

  if Apipie.configuration.generator.swagger.responses_use_refs? && @response_description.typename.present?
    composite = composite.referenced(@response_description.typename)
  end

  schema = composite.to_swagger

  if @response_description.is_array? && schema
    schema = { type: type_for_array, items: schema }
  end

  if @response_description.allow_additional_properties
    schema[:additionalProperties] = true
  end

  schema
end