-
Notifications
You must be signed in to change notification settings - Fork 472
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
issue #584: do not mutate route.path #585
Changes from all commits
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 |
---|---|---|
|
@@ -108,10 +108,10 @@ def method_object(route, options, path) | |
method[:description] = description_object(route) | ||
method[:produces] = produces_object(route, options[:produces] || options[:format]) | ||
method[:consumes] = consumes_object(route, options[:format]) | ||
method[:parameters] = params_object(route) | ||
method[:parameters] = params_object(route, path) | ||
method[:security] = security_object(route) | ||
method[:responses] = response_object(route) | ||
method[:tags] = route.options.fetch(:tags, tag_object(route)) | ||
method[:tags] = route.options.fetch(:tags, tag_object(route, path)) | ||
method[:operationId] = GrapeSwagger::DocMethods::OperationId.build(route, path) | ||
method.delete_if { |_, value| value.blank? } | ||
|
||
|
@@ -161,7 +161,7 @@ def consumes_object(route, format) | |
mime_types | ||
end | ||
|
||
def params_object(route) | ||
def params_object(route, path) | ||
parameters = partition_params(route).map do |param, value| | ||
value = { required: false }.merge(value) if value.is_a?(Hash) | ||
_, value = default_type([[param, value]]).first if value == '' | ||
|
@@ -170,11 +170,11 @@ def params_object(route) | |
elsif value[:documentation] | ||
expose_params(value[:documentation][:type]) | ||
end | ||
GrapeSwagger::DocMethods::ParseParams.call(param, value, route, @definitions) | ||
GrapeSwagger::DocMethods::ParseParams.call(param, value, path, route, @definitions) | ||
end | ||
|
||
if GrapeSwagger::DocMethods::MoveParams.can_be_moved?(parameters, route.request_method) | ||
parameters = GrapeSwagger::DocMethods::MoveParams.to_definition(parameters, route, @definitions) | ||
parameters = GrapeSwagger::DocMethods::MoveParams.to_definition(path, parameters, route, @definitions) | ||
end | ||
|
||
parameters | ||
|
@@ -227,11 +227,11 @@ def apply_success_codes(route) | |
[default_code] | ||
end | ||
|
||
def tag_object(route) | ||
def tag_object(route, path) | ||
version = GrapeSwagger::DocMethods::Version.get(route) | ||
version = [version] unless version.is_a?(Array) | ||
Array( | ||
route.path.split('{')[0].split('/').reject(&:empty?).delete_if do |i| | ||
path.split('{')[0].split('/').reject(&:empty?).delete_if do |i| | ||
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. I know you don't changed that, but please can we extract this split and reject into a separate method which explains, what it did? It's really hard to understand and a good method name would help with that. 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. This array initialisation is quite complex and worth abstracting away from Application logic. |
||
i == route.prefix.to_s || version.map(&:to_s).include?(i) | ||
end.first | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,14 @@ | |
specify { expect(subject).to eql GrapeSwagger::DocMethods::PathString } | ||
specify { expect(subject).to respond_to :build } | ||
|
||
describe 'operation_id_object' do | ||
describe 'path_string_object' do | ||
specify 'The original route path is not mutated' do | ||
route = Struct.new(:version, :path).new | ||
route.path = '/foo/:dynamic/bar' | ||
subject.build(route, add_version: true) | ||
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. I would like to see an expectation here as well to see that the |
||
expect(route.path).to eq '/foo/:dynamic/bar' | ||
end | ||
|
||
describe 'version' do | ||
describe 'defaults: given, true' do | ||
let(:options) { { add_version: true } } | ||
|
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.
Wouldn't it be better to append the new param
path
instead of prepending it? This is a public method so the change could break other code.