Skip to content

[Question] Dynamic query parameters #367

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

Closed
rhazegh opened this issue May 18, 2015 · 10 comments
Closed

[Question] Dynamic query parameters #367

rhazegh opened this issue May 18, 2015 · 10 comments

Comments

@rhazegh
Copy link

rhazegh commented May 18, 2015

I am using Ransack (https://github.com/activerecord-hackery/ransack/wiki/Basic-Searching) to build dynamic queries.

Say I have this model:

first_name: string
last_name: string
age: integer
email: string

Is there any way to document the following query?
GET api/v1/users?q[first_name_cont]=eric&q[email_not_cont]=gmail

or this?
GET api/v1/users?q[last_name_cont]=johnson&q[age_gt]=18&q[email_cont]=gmail

If not, do you know any workarounds for this?

@webron
Copy link
Member

webron commented May 18, 2015

@rhazegh - you'll have to forgive me for not reading that whole document, but I assume you mean the attachment of the _cont, _gt and the like to the query parameters to denote contains, greater than and so on.
Technically, you can document all these combinations as query parameters and that would be fine. It does mean those could be defined together though (that is age_gt and age_lt could potentially co-exist.

@rhazegh
Copy link
Author

rhazegh commented May 18, 2015

Let's say you have 10 attributes in your model. There are 25 attachment kinds of _cont, _gt, etc there. That means you end up adding 250 parameters to the document.

The problem is how do we handle this in Swagger UI? Having 250 parameters makes the UI hard to read/use.

@webron
Copy link
Member

webron commented May 18, 2015

I understand, but the spec currently does not try to deal with such a REST API design.

@rhazegh
Copy link
Author

rhazegh commented May 18, 2015

The request in issue #349 could be a possible solution.

@webron
Copy link
Member

webron commented May 18, 2015

It could, but a - it doesn't really cover your issue, since you do want to document which parameters you have and it's not all that 'free form', and secondly, it would require more traction. We can keep this issue as a feature request as well, leaving people to comment about their needs.

@rhazegh
Copy link
Author

rhazegh commented May 18, 2015

Cool. That would be great.

@izi
Copy link

izi commented Jun 15, 2015

I encountered similar issue while working on server which is supposed to conform certain API specification.

Full spec: http://hl7-fhir.github.io/search.html
I don't want to talk about API design but it would be nice to have some generic point where you can allow user to pass raw query.

GET [base]/Patient/23/Procedure?date=>2010-01-01&date=<2011-12-31

This is something outside of our control but we want to document it and allow users to use Swagger UI to experiment.

@pacbeckh
Copy link

I would also like to see this functionality. We are building a dynamic search application which is based on the data inside the application.

For us an URL looks like :

/services/rest/searchresults?keywords=sometext&JOB_CONTRACT_TYPE=FullTime

Where JOB_CONTRACT_TYPE is a dynamic query parameter that we only know at runtime.

What I would like to see is the possibility to also add these from swagger ui. So just a key and a value field would be really nice!

@dflock
Copy link

dflock commented Oct 13, 2016

I have a similar issue - our application provides a REST query interface to a NoSQL backend, which our (enterprise, on-prem) customers can fill with whatever data they want.

This means that we don't know the 'schema' - the field/key names - up front, so we couldn't hardcode all the possible combinations into the spec file, even if we wanted to.

These appear in the query URL as parameters to query on, with a prefix of data_ and a suffix for operator - e.g. ...&data_FirstName__eq=STRING:Brian... or ...&data_Weight__gte=70.0...

@webron
Copy link
Member

webron commented Mar 3, 2017

Check the Path Parameters object to see how free-form query parameters were added in 3.0.

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

No branches or pull requests

5 participants