require 'set' module SoberSwag ## # A basic, rack-only server to serve up swagger definitions. # By default it is configured to work with rails, but you can pass stuff to initialize. class Server RAILS_CONTROLLER_PROC = proc do Rails.application.routes.routes.map { |route| route.defaults[:controller] }.to_set.reject(&:nil?).map { |controller| "#{controller}_controller".classify.constantize }.filter { |controller| controller.ancestors.include?(SoberSwag::Controller) } end ## # Start up. # # @param controller_proc [Proc] a proc that, when called, gives a list of {SoberSwag::Controller}s to document # @param cache [Bool | Proc] if we should cache our defintions (default false) def initialize( controller_proc: RAILS_CONTROLLER_PROC, cache: false ) @controller_proc = controller_proc @cache = cache end EFFECT_HTML = <<~HTML.freeze