Skip to content

Commit

Permalink
Pass request object to path_string
Browse files Browse the repository at this point in the history
  • Loading branch information
bekicot committed Jul 15, 2024
1 parent a5e2575 commit 7e60504
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
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

0 comments on commit 7e60504

Please sign in to comment.