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
36
37
38
|
# File 'lib/api_sketch/examples_server.rb', line 10
def response
if api_resource
api_response = if api_response_context
api_resource.responses.find { |rsp| rsp.name == api_response_context }
else
api_resource.responses.first
end
if api_response
Rack::Response.new do |response|
api_response..each do ||
response[.name] = .value
end
response['Content-Type'] = 'application/json'
response.status = Rack::Utils.status_code(api_response.http_status)
params_array = (api_response.parameters.body_container_type.to_s == "array") ? [api_response.parameters.wrapped_body] : api_response.parameters.body
response.write(ApiSketch::ResponseRenderer.new(params_array, api_response.parameters.body_container_type, get_elements_count).to_json)
end
else
api_sketch_message("No any responses defined for this resource and context", 404)
end
else
api_sketch_message("Resource is not Found", 404)
end
end
|