summaryrefslogtreecommitdiff
path: root/lib/api.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api.rb')
-rw-r--r--lib/api.rb28
1 files changed, 21 insertions, 7 deletions
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