Class: Generator::ResponseModel

Inherits:
Object
  • Object
show all
Defined in:
lib/generator/builders/response_model.rb

Constant Summary collapse

DEFAULT_PAYLOAD_KEY =
"payload"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation) ⇒ ResponseModel

Returns a new instance of ResponseModel.



9
10
11
# File 'lib/generator/builders/response_model.rb', line 9

def initialize(operation)
  @operation = operation
end

Instance Attribute Details

#operationObject (readonly)

Returns the value of attribute operation.



7
8
9
# File 'lib/generator/builders/response_model.rb', line 7

def operation
  @operation
end

Instance Method Details

#buildObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/generator/builders/response_model.rb', line 13

def build
  success_response = find_success_response
  return default_response_model unless success_response && success_response["schema"]

  schema = success_response["schema"]

  if schema["$ref"]
    build_ref_response_model(schema["$ref"])
  elsif schema["properties"] && schema["properties"]["payload"]
    handle_inline_payload_response(schema["properties"]["payload"])
  else
    default_response_model
  end
end