-
Notifications
You must be signed in to change notification settings - Fork 463
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
Instead of manually redefine the route for the action, retrieve it from the routes of the application. #187
Changes from 18 commits
1118bc6
53eafab
6d31837
ef29856
6cfc144
2784d61
701c76b
7e90332
dbfc1f8
1bf2c68
1fcefab
cd04c2c
6069885
38a61b5
1247a91
48ab3f4
2f3bba8
11ce9cc
48bfe6c
d35e0a1
170454d
e494e62
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
class RoutesFormater | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be namespaced under Apipie module There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mtparet no action needed: I will fix that with some other updates I will probably have when testing against my apps There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, I forgot to encapsulate it under the module. |
||
API_METHODS = %w{GET POST PUT PATCH OPTIONS DELETE} | ||
|
||
class Path | ||
def format(rails_path_spec) | ||
rails_path_spec.gsub!('(.:format)', '') | ||
rails_path_spec.gsub!(/[()]/, '') | ||
Apipie.configuration.api_base_url.values.each do |values| | ||
rails_path_spec.gsub!("#{values}/", '/') | ||
end | ||
rails_path_spec | ||
end | ||
end | ||
|
||
def initialize | ||
@path_formatter = Path.new | ||
end | ||
|
||
def format_paths(rails_paths) | ||
rails_paths.map { |rails_path| format_path(rails_path) } | ||
end | ||
|
||
def format_path(rails_path) | ||
path = @path_formatter.format(rails_path.path.spec.to_s) | ||
|
||
{ path: path, verb: human_verb(rails_path) } | ||
end | ||
|
||
def human_verb(route) | ||
verb = API_METHODS.select{|defined_verb| defined_verb =~ /\A#{route.verb}\z/} | ||
if verb.count != 1 | ||
verb = API_METHODS.select{|defined_verb| defined_verb == route.constraints[:method]} | ||
if verb.blank? | ||
raise "Unknow verb #{route.path.spec.to_s}" | ||
end | ||
end | ||
verb.first | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the reason for filtering the routes based on the api_base_url? Just optimization or there are other reasons? I causes me some troubles when I want to use this to document some engines that add their specific API
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed the value added is not enough in comparison of problems it may cause.
(I implemented just because I tried to follow current driven behaviors by
api_base_url
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will remove that then, we can add that back later in some cusomizable fashion later, if the need occurs