module GrapeSwagger::DocMethods
Constants
- DEFAULTS
- FORMATTER_METHOD
Public Class Methods
output_path_definitions(combi_routes, endpoint, target_class, options)
click to toggle source
# File lib/grape-swagger/doc_methods.rb, line 46 def self.output_path_definitions(combi_routes, endpoint, target_class, options) output = endpoint.swagger_object( target_class, endpoint.request, options ) paths, definitions = endpoint.path_and_definition_objects(combi_routes, options) tags = tags_from(paths, options) output[:tags] = tags unless tags.empty? || paths.blank? output[:paths] = paths unless paths.blank? output[:definitions] = definitions unless definitions.blank? output end
Public Instance Methods
class_variables_from(options)
click to toggle source
# File lib/grape-swagger/doc_methods.rb, line 129 def class_variables_from(options) @@mount_path = options[:mount_path] @@class_name = options[:class_name] || options[:mount_path].delete('/') @@hide_documentation_path = options[:hide_documentation_path] end
hide_documentation_path()
click to toggle source
# File lib/grape-swagger/doc_methods.rb, line 75 def hide_documentation_path @@hide_documentation_path end
mount_path()
click to toggle source
# File lib/grape-swagger/doc_methods.rb, line 79 def mount_path @@mount_path end
setup(options)
click to toggle source
# File lib/grape-swagger/doc_methods.rb, line 83 def setup(options) options = DEFAULTS.merge(options) # options could be set on #add_swagger_documentation call, # for available options see #defaults target_class = options[:target_class] guard = options[:swagger_endpoint_guard] api_doc = options[:api_documentation].dup specific_api_doc = options[:specific_api_documentation].dup class_variables_from(options) setup_formatter(options[:format]) desc api_doc.delete(:desc), api_doc instance_eval(guard) unless guard.nil? get mount_path do header['Access-Control-Allow-Origin'] = '*' header['Access-Control-Request-Method'] = '*' GrapeSwagger::DocMethods .output_path_definitions(target_class.combined_namespace_routes, self, target_class, options) end desc specific_api_doc.delete(:desc), { params: specific_api_doc.delete(:params) || {}, **specific_api_doc } params do requires :name, type: String, desc: 'Resource name of mounted API' optional :locale, type: Symbol, desc: 'Locale of API documentation' end instance_eval(guard) unless guard.nil? get "#{mount_path}/:name" do I18n.locale = params[:locale] || I18n.default_locale combined_routes = target_class.combined_namespace_routes[params[:name]] error!({ error: 'named resource not exist' }, 400) if combined_routes.nil? GrapeSwagger::DocMethods .output_path_definitions({ params[:name] => combined_routes }, self, target_class, options) end end
setup_formatter(formatter)
click to toggle source
# File lib/grape-swagger/doc_methods.rb, line 135 def setup_formatter(formatter) return unless formatter FORMATTER_METHOD.each { |method| send(method, formatter) } end