From 741701df8ff0861b3607a30e9aaf8b8a0c303cdf Mon Sep 17 00:00:00 2001 From: gebele Date: Thu, 13 Jun 2019 15:28:59 +0000 Subject: update with API --- lib/api.rb | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'lib/api.rb') diff --git a/lib/api.rb b/lib/api.rb index 28e33df..c3b27ce 100644 --- a/lib/api.rb +++ b/lib/api.rb @@ -1,9 +1,23 @@ -# route to swagger API file -get "/api/api.json" do - response['Content-Type'] = "application/json" +get "/api" do api_file = File.join("api", "api.json") - bad_request_error "API Documentation in Swagger JSON is not implemented." unless File.exists?(api_file) - api_hash = JSON.parse(File.read(api_file)) - api_hash["host"] = request.env['HTTP_HOST'] - return api_hash.to_json + halt 400, "API Documentation in Swagger JSON is not implemented." unless File.exists?(api_file) + case @accept + when "text/html" + response['Content-Type'] = "text/html" + index_file = File.join(ENV['HOME'],"swagger-ui/dist/index.html") + File.read(index_file) + when "application/json" + response['Content-Type'] = "application/json" + api_hash = JSON.parse(File.read(api_file)) + api_hash["host"] = request.env['HTTP_HOST'] + return api_hash.to_json + else + halt 400, "unknown MIME type '#{@accept}'" + end +end + +get "/api/api.json" do + response['Content-Type'] = "text/html" + index_file = File.join(ENV['HOME'],"swagger-ui/dist/index.html") + File.read(index_file) end -- cgit v1.2.3