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

Parameters delimited by dash cause exception #586

Merged
merged 5 commits into from
Feb 28, 2017

Conversation

risa
Copy link
Contributor

@risa risa commented Feb 27, 2017

In our project we are using api calls to return a range from array, like this:

get '/range/:range_start-:range_end'

Currently this causes
NoMethodError: undefined method delete!' for nil:NilClass
./lib/grape-swagger/doc_methods/operation_id.rb:22:in manipulate'

See the spec below for demostration.

The problem is caused by difference between regexp /\-(\w)/ and include?('-'). The path gets translated to operation: "Range_parameterRange{range_start}-{range_end}". The include?('-') matches the string but the regexp does not. And per specs the gsub! returns nil if no substitutions were made (not the least surprise principle for me).

We are using only dash, possibly underscore can be offending as well, but as a first attempt I suggest only dash.

Suggestions and feedback welcome. Thanks.

@risa risa changed the title Fixed range parameters delimited by dash Parameters delimited by dash cause exception Feb 27, 2017
Copy link
Member

@LeFnord LeFnord left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @risa

@@ -0,0 +1,24 @@
require 'spec_helper'

describe '#XXX nested entity given as string' do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please can you adapt the description, e.g. https://github.com/ruby-grape/grape-swagger/blob/master/spec/issues/582_file_response_spec.rb#L3 and also rename the spec file itself,
starting with issue number, thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the naming, my first PR ever ... should I open an issue for this, to get the number?

result
end

specify { expect(subject.keys).to include '/range_parameter/range/{range_start}-{range_end}' }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you show the operationId, how this had changed, thanks

@LeFnord
Copy link
Member

LeFnord commented Feb 27, 2017

[please add changelog entry, as the bot suggest

@coveralls
Copy link

coveralls commented Feb 27, 2017

Coverage Status

Coverage remained the same at 97.353% when pulling 36ede60 on risa:parameters-with-dash into 26e6d93 on ruby-grape:master.

@LeFnord
Copy link
Member

LeFnord commented Feb 28, 2017

thanks again

@LeFnord LeFnord merged commit 79052e3 into ruby-grape:master Feb 28, 2017
@risa
Copy link
Contributor Author

risa commented Feb 28, 2017

Thanks as well!

LeFnord pushed a commit to LeFnord/grape-swagger that referenced this pull request Feb 9, 2019
* Fixed range parameters delimited by dash

* fixed rubocop offense

* updates for requested changes - renamed spec and showed operationId value in spec

* Changelog updated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants