module Swaggard
Constants
- VERSION
Public Class Methods
configuration()
click to toggle source
# File lib/swaggard.rb, line 19 def configuration @configuration ||= Swaggard::Configuration.new end
configure() { |configuration| ... }
click to toggle source
# File lib/swaggard.rb, line 15 def configure yield configuration end
get_doc(host = nil)
click to toggle source
# File lib/swaggard.rb, line 43 def get_doc(host = nil) load! doc = @api.to_doc doc['host'] = host if doc['host'].blank? && host doc end
Private Class Methods
build_operation(path, verb, route)
click to toggle source
# File lib/swaggard.rb, line 72 def build_operation(path, verb, route) controller_name = route[:controller] action_name = route[:action] controller_tag, controller_operations = tags.find { |tag, _operations| tag_matches?(tag, controller_name, path) } return unless controller_tag return unless controller_operations[action_name] operation_yard_object = controller_operations[action_name] return unless operation_yard_object operation = Swagger::Operation.new(operation_yard_object, controller_tag, path, verb, route[:path_params]) return unless operation.valid? return if Swaggard.configuration.ignore_undocumented_paths && operation.empty? return controller_tag, operation end
build_operations()
click to toggle source
# File lib/swaggard.rb, line 94 def build_operations routes.each do |path, verbs| verbs.each do |verb, route_options| tag, operation = build_operation(path, verb, route_options) next unless tag @api.add_tag(tag) @api.add_operation(operation) end end end
get_yard_objects(file)
click to toggle source
# File lib/swaggard.rb, line 151 def get_yard_objects(file) ::YARD.parse(file) yard_objects = ::YARD::Registry.all ::YARD::Registry.clear yard_objects end
load!()
click to toggle source
# File lib/swaggard.rb, line 55 def load! @api = Swaggard::ApiDefinition.new parse_models build_operations @api.ignore_put_if_patch! if Swaggard.configuration.ignore_put_if_patch_exists end
parse_models()
click to toggle source
# File lib/swaggard.rb, line 136 def parse_models parser = Parsers::Models.new definitions =[] configuration.models_paths.each do |path| Dir[path].each do |file| yard_objects = get_yard_objects(file) definitions.concat(parser.run(yard_objects)) end @api.definitions = definitions end end
routes()
click to toggle source
# File lib/swaggard.rb, line 129 def routes return @routes if @routes parser = Parsers::Routes.new @routes = parser.run(configuration.routes) end
tag_matches?(tag, controller_name, path)
click to toggle source
# File lib/swaggard.rb, line 64 def tag_matches?(tag, controller_name, path) matches = tag.controller_name == controller_name return matches unless tag.route.present? matches && Regexp.new(tag.route).match?(path) end