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
fix: suport complex objects for query params in api explorer
BREAKING CHANGE: This fix has modified the api definitions described by the decorator
'param.query.object', to support Open-API's `url-encoded` definition for json query
parameters.
Previously, such parameters were described with `exploded: true` and
`style: deepObject` which turned out to be problematic as explained and discussed in,
swagger-api/swagger-js#1385 and
OAI/OpenAPI-Specification#1706
```json
{
"in": "query",
"style": "deepObject"
"explode": "true",
"schema": {}
}
```
Exploded encoding worked for simple json objects as below but not for complex objects.
```
http://localhost:3000/todos?filter[limit]=2
```
To address these issues with exploded queries, this fix switches definition of json
query params from the `exploded`, `deep-object` style to the `url-encoded` style
definition in Open-API spec.
LoopBack already supports receiving url-encoded payload for json query parameters.
For instance, to filter api results from the GET '/todo-list' endpoint in the
todo-list example with a specific relation, { "include": [ { "relation": "todo" } ] },
the following url-encoded query parameter can be used,
```
http://localhost:3000/todos?filter=%7B%22include%22%3A%5B%7B%22relation%22%3A%22todoList%22%7D%5D%7D
```
The coercion behavior in LoopBack has always supported receiving url-encoded payload
for `exploded`, `deep object` style json query params before this fix. This fix has
modified that behavior by removing json parsing for `deep object` json query params.
Since the `exploded` `deep-object` definition has been removed from the
`param.query.object` decorator, this new behaviour remains just an internal source
code aspect as of now.
In effect, this fix only clarifies the schema contract as per Open-API spec.
The impact is only on the open api definitions generated from LoopBack APIs.
This fix removes the 'style' and 'explode' fields from the definition of json query
params and moves the 'schema' field under 'content[application/json]'. This is the
definition that should support url-encoding as per Open-API spec.
```json
{
"in": "query"
"content": {
"application/json": {
"schema": {}
}
}
}
```
Certain client libraries (like swagger-ui or LoopBack's api explorer) necessiate
using Open-API's `url-encoded` style definition for json query params to support
"sending" url-encoded payload.
All consumers of LoopBack APIs may need to regenerate api definitions, if their
client libraries require them to do so for url-encoding.
Otherwise there wouldn't be any significant impact on API consumers.
To preserve compatibility with existing REST API clients, this change is backward
compatible with all previously supported formats for json query parameters.
Exploded queries like `?filter[limit]=1` will continue to work for json query
params, despite the fact that they are described differently in the OpenAPI spec.
As a result, existing REST API clients will keep working after an upgrade.
The signature of the 'param.query.object' decorator has not changed.
There is no code changes required in the LoopBack APIs after upgrading to this
fix. No method signatures or data structures are impacted.
0 commit comments