5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/api_def/mock.rb', line 5
def self.create_application(spec)
Class.new(Sinatra::Base) do
configure do
disable :protection
settings.add_charset << "application/json"
end
before do
content_type :json
end
get "/" do
content_type :html
tpl = ApiDef::Template::Html.new
tpl.render spec
end
spec.groups.each do |group|
group.entries.each do |entry|
self.send(entry.method.to_sym, entry.path) do
JSON.pretty_generate(entry.responses.sample.body)
end
end
end
end
end
|