You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
API Explorer ignores filter options where, fields, and order #2208
I am using the example Todo model with the memory connector. The GET/ operations show the following example filter object, but "where", "fields", and "order "o are stripped before getting to the controller's find method.
From other posts, this may be a coercion issue, but I would expect this functionality from LB3 to work flawlessly in LB4. I strongly disagree with the announcement that "...LoopBack 4 GA is Now Ready for Production Use!" Also, I cannot find ANY documentation on filters in the LB4 documentation. My test filter is as simple as:
{
"where": {
"id" : 1
}
}
Acceptance Criteria:
- this is a breaking fix, needs semver major release
- change existing param.query.object decorator to support json objects in query params.
including content field in param spec, helps to support both exploded filter conditions like filter[limit] = 0 and json objects as per spike PR feat: spike on API Explorer supporting complex objects in query param #4141
- parameter schema cannot have content field along with schema, explode, type fields. swagger validation fails (check with https://editor.swagger.io/) if they appear together.
- loopback currently does not support extracting parameter schema from the content field. if we are including schema under content and not schema field, then it means additional changes in tests and source.
- add additional unit, acceptance and regression tests
- add documentation for filter conditions and above changes
- Close related stories
Reacted by Irfandy J, Daniel Szasz, mikeevstropov, Ramon van de Ven, Arnaud MAURICE and DanielJaramillo94
"where", "fields", and "order "o are stripped before getting to the controller's find method.
I assume this is happening when making the request from the API Explorer, is that correct?
I am afraid this is a known bug/limitation of swagger-ui and swagger-js, see the discussion in #1679 and the tracking issue swagger-api/swagger-client#1385.
You can see this yourself in API Explorer UI. When you send the request, the UI shows the full URL, request headers and response headers. There you can see that the request URL created by API Explorer (swagger-js) does not contain the filter properties.
Unfortunately swagger-ui does not warn the user about this problem, which makes the entire experience less than ideal.
Having said that, the actual implementation in LoopBack4 does support where/fields/order, you need to create the request URL manually or use a different OpenAPI client.
I cannot find ANY documentation on filters in the LB4 documentation. My test filter is as simple as:
LoopBack 4 uses the same format as LoopBack 3 does. I agree our documentation should be more explicit about this fact. To keep things simple, maybe it's enough to add a link pointing to existing LB3 docs? Would you like to contribute such change yourself? See https://loopback.io/doc/en/contrib/doc-contrib.html to get started.
Me and my team we are using this great framework, loopback 2 and 3 from more 3 year and we are testig the new loopback 4 version to upgrade some of our apps.
I installed the last versión of Loopback from CLI @loopback/cli version: 1.5.2. and the problem related with the atributes "where", "fields", and "order not works. Of course if generated the services from swagger generator for angular 6 the problem persist if you try to pass any filters, orders or fields from the services created.
Like a user of loopback for many years and like @ewrayjohnson said, LoopBack 4 GA can't be launch to production!. Where do you resolve this problem related with Open API?
Not really. Re-posting one of my earlier comments:
I am afraid this is a known bug/limitation of swagger-ui and swagger-js, see the discussion in #1679 and the tracking issue swagger-api/swagger-client#1385.
(...)
Unfortunately swagger-ui does not warn the user about this problem, which makes the entire experience less than ideal.
Having said that, the actual implementation in LoopBack4 does support where/fields/order, you need to create the request URL manually or use a different OpenAPI client.
@sergiomata Would you like to contribute the necessary changes to swagger-js yourself?
what if content (each qs param value) be subject to JSON.parse/JSON.stringify subject to URL/URI decoding/encoding as needed with whitespace removal.
For example:
all tasks completed, acceptance criteria satisfied.
@deepakrkris Just wanted to thank you for this work. It's a welcome relief to be able to write my filters normally, instead of weird workarounds like "include][][relation": "someRelation" and so on.
Activity
bajtos commentedon Jan 10, 2019
I assume this is happening when making the request from the API Explorer, is that correct?
I am afraid this is a known bug/limitation of swagger-ui and swagger-js, see the discussion in #1679 and the tracking issue swagger-api/swagger-client#1385.
You can see this yourself in API Explorer UI. When you send the request, the UI shows the full URL, request headers and response headers. There you can see that the request URL created by API Explorer (swagger-js) does not contain the filter properties.
Unfortunately swagger-ui does not warn the user about this problem, which makes the entire experience less than ideal.
Having said that, the actual implementation in LoopBack4 does support where/fields/order, you need to create the request URL manually or use a different OpenAPI client.
LoopBack 4 uses the same format as LoopBack 3 does. I agree our documentation should be more explicit about this fact. To keep things simple, maybe it's enough to add a link pointing to existing LB3 docs? Would you like to contribute such change yourself? See https://loopback.io/doc/en/contrib/doc-contrib.html to get started.
ghsamm commentedon Jan 12, 2019
I found this tricky workaround:
There seems to be no other way to pass nested filters from the Swagger UI.
A more convenient workaround would be to use something something like Postman and pass the filter as a string.
masalinas commentedon Jan 29, 2019
Me and my team we are using this great framework, loopback 2 and 3 from more 3 year and we are testig the new loopback 4 version to upgrade some of our apps.
I installed the last versión of Loopback from CLI @loopback/cli version: 1.5.2. and the problem related with the atributes "where", "fields", and "order not works. Of course if generated the services from swagger generator for angular 6 the problem persist if you try to pass any filters, orders or fields from the services created.
Like a user of loopback for many years and like @ewrayjohnson said, LoopBack 4 GA can't be launch to production!. Where do you resolve this problem related with Open API?
Regards.
yiiliveext commentedon Mar 23, 2019
Filter parameter value in UI:
{
"filter[name][like]": "peter",
"filter[created_at][gt]": 1536843061
}
Generated query:
curl -X GET "http://mysite.com/api/v1/users?filter[name][like]=peter&filter[created_at][gt]=1536843061" -H "accept: application/json"
sergiomata commentedon May 24, 2019
Hello, any update for this issue?
bajtos commentedon Jun 7, 2019
Not really. Re-posting one of my earlier comments:
@sergiomata Would you like to contribute the necessary changes to swagger-js yourself?
bharathgrk commentedon Jun 20, 2019
This works for "where" clauses as well.
bajtos commentedon Sep 19, 2019
Based on OAI/OpenAPI-Specification#1706 (comment) (cross-posted below), maybe we can switch
filterencoding fromdeepObjectstyle intoJSON?Here is an experiment we can try:
@param.query.objectwith no changes for backwards compatibility.@param.query.jsonObjectthat will use JSON encoding instead of deepObject style.parseJsonIfNeededto detect JSON encoding and parse the string value - see packages/rest/src/coercion/coerce-parameter.ts@param.query.jsonObject- see examples/todo/src/controllers/todo.controller.tsThe comment:
24 remaining items
docs: update docs for issue 2208 switching to url-encoded style params
docs: update decorator documentation for url-encoded query params
docs: update docs for issue 2208 switching to url-encoded style params
docs: update decorator documentation for url-encoded query params
docs: update decorator documentation for url-encoded query params
docs: update decorator documentation for url-encoded query params
docs: update decorator documentation for url-encoded query params
docs: update docs for issue 2208 switching to url-encoded style params
docs: update decorator documentation for url-encoded query params
docs: update docs for issue 2208 switching to url-encoded style params
docs: update decorator documentation for url-encoded query params
deepakrkris commentedon Feb 13, 2020
all tasks completed, acceptance criteria satisfied.
ibmjm commentedon Mar 24, 2020
@deepakrkris Just wanted to thank you for this work. It's a welcome relief to be able to write my filters normally, instead of weird workarounds like "include][][relation": "someRelation" and so on.
Cheers!
ewrayjohnson commentedon Mar 24, 2020
@deepakrkris: I just looked back to when I first reported this. Its been a long journey. Thanks for persevering and resolving this impediment!