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 schema 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`, `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 modifies the definition of json
query params from `exploded` and `deep-object` style to the `url-encoded` style
described in Open-API spec.
for example, to filter api results with the following condition,
```json
{
"include": [
{
"relation": "todo"
}
]
}
```
the following url-encoded query parameter is used,
```
http://localhost:3000/todos?filter=%7B%22include%22%3A%5B%7B%22relation%22%3A%22todoList%22%7D%5D%7D
```
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.
LoopBack supported "receiving" url-encoded payload for `exploded`, `deep object` style
query params on the server side even before this fix, even though the Open-API spec has
very clear demarcations for both these styles.
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.
All consumers of LoopBack APIs may need to regenerate api definitions only if their
client libraries require them to do so for url-encoding.
Otherwise there wouldn't be any significant impact on API consumers.
This fix removes the 'style' and 'explode' fields from the definition of json query params.
The 'schema' field is moved under 'content[application/json]' (`url-encoded` style) as below,
```json
{
"in": "query"
"content": {
"application/json": {
"schema": {}
}
}
}
```
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, 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