Skip to content
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.1
2.1.2
2 changes: 1 addition & 1 deletion app/controllers/swagger_yard/swagger_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def index

def show
swagger_api = SwaggerYard.get_api("/#{params[:resource]}")
swagger_api.merge!("basePath" => request.base_url + SwaggerYard.api_path) if swagger_api["basePath"].blank?
swagger_api.merge!("basePath" => request.base_url + request.script_name + "/api") if swagger_api["basePath"].blank?
render :json => swagger_api
end

Expand Down
2 changes: 1 addition & 1 deletion app/views/swagger_yard/swagger/doc.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<script type="text/javascript">
$(function () {
window.swaggerUi = new SwaggerUi({
discoveryUrl: location.protocol + "//" + location.host + "/swagger/api",
discoveryUrl: "<%= request.base_url + request.script_name + '/api' %>",
dom_id:"swagger-ui-container",
supportHeaderParams: true,
supportedSubmitMethods: ['get', 'post', 'put'],
Expand Down
4 changes: 4 additions & 0 deletions lib/swagger_yard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ def get_listing
end
end

def clear_cache
cache["listing_index"] = nil
end

private
##
# Register some custom yard tags used by swagger-ui
Expand Down
20 changes: 12 additions & 8 deletions lib/swagger_yard/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@

module SwaggerYard
class Engine < ::Rails::Engine
if SwaggerYard::LocalDispatcher.new.server?
isolate_namespace SwaggerYard
isolate_namespace SwaggerYard

# NOTE: We should opt for asset pipeline instead of this.
initializer 'swagger_yard.load_static_assets' do |app|
app.middleware.use(::ActionDispatch::Static, "#{root}/public")
end
initializer :after do |app|
if SwaggerYard::LocalDispatcher.new.server?
# NOTE: We should opt for asset pipeline instead of this.
#initializer 'swagger_yard.load_static_assets' do |app|
app.middleware.use(::ActionDispatch::Static, "#{root}/public")
#end

initializer "swagger_yard.finisher_hook" do |app|
SwaggerYard.generate!("#{app.root}/app/controllers/**/*.rb")
#initializer "swagger_yard.finisher_hook" do |app|
SwaggerYard.generate!("#{app.root}/app/controllers/**/*.rb")
#end
SwaggerYard.clear_cache
end
end

end
end
10 changes: 8 additions & 2 deletions lib/swagger_yard/local_dispatcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ def discovered_dispatcher
end

def server?
[:thin, :unicorn].include?(discovered_dispatcher)
[:webrick, :thin, :unicorn].include?(discovered_dispatcher)
end

private

def discover_dispatcher
dispatchers = %w[sidekiq thin unicorn]
dispatchers = %w[sidekiq thin unicorn webrick]
while dispatchers.any? && @discovered_dispatcher.nil?
send 'check_for_' + (dispatchers.shift)
end
Expand Down Expand Up @@ -47,5 +47,11 @@ def check_for_thin
@discovered_dispatcher = :thin
end
end

def check_for_webrick
if !defined?(::WEBrick).nil?
@discovered_dispatcher = :webrick
end
end
end
end