mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-22 22:06:43 +00:00
33 lines
655 B
Ruby
33 lines
655 B
Ruby
require 'json'
|
|
|
|
module SwaggerRails
|
|
class SwaggerUiController < ApplicationController
|
|
|
|
def root
|
|
redirect_to action: 'index'
|
|
end
|
|
|
|
def index
|
|
swagger_root = SwaggerRails.config.resolve_swagger_root(request.env)
|
|
swagger_filenames = Dir["#{swagger_root}/**/*.json"]
|
|
|
|
@discovery_paths = Hash[
|
|
swagger_filenames.map do |filename|
|
|
[
|
|
filename.sub(swagger_root, root_path),
|
|
load_json(filename)["info"]["title"]
|
|
]
|
|
end
|
|
]
|
|
|
|
render :index, layout: false
|
|
end
|
|
|
|
private
|
|
|
|
def load_json(filename)
|
|
JSON.parse(File.read(filename))
|
|
end
|
|
end
|
|
end
|