module Rack::Swagger::ServerHelpers
Public Instance Methods
base_path_value(root_or_resource=nil)
click to toggle source
# File lib/rack/swagger/server_helpers.rb, line 36 def base_path_value(root_or_resource=nil) if root_or_resource == :root @opts[:overwrite_base_path] + "/docs/api-docs" else @opts[:overwrite_base_path] end end
display_file(type, file, root_or_resource=nil)
click to toggle source
# File lib/rack/swagger/server_helpers.rb, line 27 def display_file(type, file, root_or_resource=nil) @files ||= {} @files[file] ||= begin contents = ::File.read(file) contents = overwrite_base_path(contents, base_path_value(root_or_resource)) if type == :json contents end end
display_file_or_404(type, file, root_or_resource=nil)
click to toggle source
# File lib/rack/swagger/server_helpers.rb, line 12 def display_file_or_404(type, file, root_or_resource=nil) if ::File.exists?(file) [ 200, { 'Content-Type' => type == :json ? 'application/json' : 'text/html', 'Cache-Control' => 'public, max-age=86400' }, ::StringIO.new(display_file(type, file, root_or_resource)) ] else [404, {}, ["Not found"]] end end
overwrite_base_path(contents, value)
click to toggle source
# File lib/rack/swagger/server_helpers.rb, line 44 def overwrite_base_path(contents, value) if value contents = JSON.parse(contents) contents["basePath"] = value contents.to_json else contents end end
swagger_dist_path()
click to toggle source
# File lib/rack/swagger/server_helpers.rb, line 4 def swagger_dist_path ::File.expand_path("../../../../swagger-ui/dist", __FILE__) end
swagger_index_html_path()
click to toggle source
# File lib/rack/swagger/server_helpers.rb, line 8 def swagger_index_html_path ::File.join(swagger_dist_path, "index.html") end