Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass request object to path_string #936

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/grape-swagger/doc_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def self.output_path_definitions(combi_routes, endpoint, target_class, options)
options
)

paths, definitions = endpoint.path_and_definition_objects(combi_routes, options)
paths, definitions = endpoint.path_and_definition_objects(combi_routes, options, endpoint.request)
tags = tags_from(paths, options)

output[:tags] = tags unless tags.empty? || paths.blank?
Expand Down
4 changes: 2 additions & 2 deletions lib/grape-swagger/doc_methods/path_string.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module GrapeSwagger
module DocMethods
class PathString
class << self
def build(route, options = {})
def build(route, options = {}, request = nil)
path = route.path.dup
# always removing format
path.sub!(/\(\.\w+?\)$/, '')
Expand All @@ -25,7 +25,7 @@ def build(route, options = {})
path.sub!('/{version}', '')
end

path = "#{OptionalObject.build(:base_path, options)}#{path}" if options[:add_base_path]
path = "#{OptionalObject.build(:base_path, options, request)}#{path}" if options[:add_base_path]

[item, path.start_with?('/') ? path : "/#{path}"]
end
Expand Down
8 changes: 4 additions & 4 deletions lib/grape-swagger/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ def contact_object(infos)
end

# building path and definitions objects
def path_and_definition_objects(namespace_routes, options)
def path_and_definition_objects(namespace_routes, options, request = nil)
@paths = {}
@definitions = {}
add_definitions_from options[:models]
namespace_routes.each_value do |routes|
path_item(routes, options)
path_item(routes, options, request)
end

[@paths, @definitions]
Expand All @@ -94,11 +94,11 @@ def add_definitions_from(models)
end

# path object
def path_item(routes, options)
def path_item(routes, options, request = nil)
routes.each do |route|
next if hidden?(route, options)

@item, path = GrapeSwagger::DocMethods::PathString.build(route, options)
@item, path = GrapeSwagger::DocMethods::PathString.build(route, options, request)
@entity = route.entity || route.options[:success]

verb, method_object = method_object(route, options, path)
Expand Down
Loading