@loopback/rest 1.26.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +95 -0
- package/dist/coercion/coerce-parameter.js +8 -3
- package/dist/coercion/coerce-parameter.js.map +1 -1
- package/dist/coercion/validator.d.ts +7 -0
- package/dist/coercion/validator.js +26 -1
- package/dist/coercion/validator.js.map +1 -1
- package/package.json +8 -8
- package/src/coercion/coerce-parameter.ts +10 -3
- package/src/coercion/validator.ts +26 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,101 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [2.0.0](https://github.com/strongloop/loopback-next/compare/@loopback/rest@1.26.1...@loopback/rest@2.0.0) (2020-02-06)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* suport complex objects for query params in api explorer ([a4ef640](https://github.com/strongloop/loopback-next/commit/a4ef64037a80d1ff7df37ba7912909a1bfcdbf51))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### BREAKING CHANGES
|
|
15
|
+
|
|
16
|
+
* This fix has modified the api definitions described by the decorator
|
|
17
|
+
'param.query.object', to support Open-API's `url-encoded` definition for json query
|
|
18
|
+
parameters.
|
|
19
|
+
|
|
20
|
+
Previously, such parameters were described with `exploded: true` and
|
|
21
|
+
`style: deepObject`, i.e exploded encoding, which turned out to be problematic as explained and discussed in,
|
|
22
|
+
https://github.com/swagger-api/swagger-js/issues/1385 and
|
|
23
|
+
https://github.com/OAI/OpenAPI-Specification/issues/1706
|
|
24
|
+
|
|
25
|
+
```json
|
|
26
|
+
{
|
|
27
|
+
"in": "query",
|
|
28
|
+
"style": "deepObject"
|
|
29
|
+
"explode": "true",
|
|
30
|
+
"schema": {}
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Exploded encoding worked for simple json objects as below but not for complex objects.
|
|
35
|
+
|
|
36
|
+
```
|
|
37
|
+
http://localhost:3000/todos?filter[limit]=2
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
To address these issues with exploded queries, this fix switches definition of json
|
|
41
|
+
query params from the `exploded`, `deep-object` style to the `url-encoded` style
|
|
42
|
+
definition in Open-API spec.
|
|
43
|
+
|
|
44
|
+
LoopBack already supports receiving url-encoded payload for json query parameters.
|
|
45
|
+
|
|
46
|
+
For instance, to filter api results from the GET '/todo-list' endpoint in the
|
|
47
|
+
todo-list example with a specific relation, { "include": [ { "relation": "todo" } ] },
|
|
48
|
+
the following url-encoded query parameter can be used,
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
http://localhost:3000/todos?filter=%7B%22include%22%3A%5B%7B%22relation%22%3A%22todoList%22%7D%5D%7D
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
The above was possible because the coercion behavior in LoopBack performed json
|
|
55
|
+
parsing for `deep object` style json query params before this fix. This fix has
|
|
56
|
+
modified that behavior by removing json parsing. Since the `exploded` `deep-object`
|
|
57
|
+
definition has been removed from the `param.query.object` decorator, this new
|
|
58
|
+
behaviour remains just an internal source code aspect as of now.
|
|
59
|
+
|
|
60
|
+
In effect, this fix only modifies the open api definitions generated from LoopBack
|
|
61
|
+
APIs. The 'style' and 'explode' fields are removed and the 'schema' field is moved
|
|
62
|
+
under 'content[application/json]'. This is the definition that supports url-encoding
|
|
63
|
+
as per Open-API spec.
|
|
64
|
+
|
|
65
|
+
```json
|
|
66
|
+
{
|
|
67
|
+
"in": "query"
|
|
68
|
+
"content": {
|
|
69
|
+
"application/json": {
|
|
70
|
+
"schema": {}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Certain client libraries (like swagger-ui or LoopBack's api explorer) necessiate
|
|
77
|
+
using Open-API's `url-encoded` style definition for json query params to support
|
|
78
|
+
"sending" url-encoded payload.
|
|
79
|
+
|
|
80
|
+
All consumers of LoopBack APIs may need to regenerate api definitions, if their
|
|
81
|
+
client libraries require them to do so for url-encoding.
|
|
82
|
+
|
|
83
|
+
Otherwise there wouldn't be any significant impact on API consumers.
|
|
84
|
+
|
|
85
|
+
To preserve compatibility with existing REST API clients, this change is backward
|
|
86
|
+
compatible. All exploded queries like `?filter[limit]=1` will continue to work for
|
|
87
|
+
json query params, despite the fact that they are described differently in the
|
|
88
|
+
OpenAPI spec.
|
|
89
|
+
|
|
90
|
+
Existing api clients will continue to work after an upgrade.
|
|
91
|
+
|
|
92
|
+
The signature of the 'param.query.object' decorator has not changed.
|
|
93
|
+
|
|
94
|
+
There is no code changes required in the LoopBack APIs after upgrading to this
|
|
95
|
+
fix. No method signatures or data structures are impacted.
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
6
101
|
## [1.26.1](https://github.com/strongloop/loopback-next/compare/@loopback/rest@1.26.0...@loopback/rest@1.26.1) (2020-02-05)
|
|
7
102
|
|
|
8
103
|
**Note:** Version bump only for package @loopback/rest
|
|
@@ -23,7 +23,12 @@ const debug = debug_1.default('loopback:rest:coercion');
|
|
|
23
23
|
* @param schema - The parameter's schema defined in OpenAPI specification
|
|
24
24
|
*/
|
|
25
25
|
function coerceParameter(data, spec) {
|
|
26
|
-
|
|
26
|
+
let schema = spec.schema;
|
|
27
|
+
// If a query parameter is a url encoded Json object, the schema is defined under content['application/json']
|
|
28
|
+
if (!schema && spec.in === 'query' && spec.content) {
|
|
29
|
+
const jsonSpec = spec.content['application/json'];
|
|
30
|
+
schema = jsonSpec.schema;
|
|
31
|
+
}
|
|
27
32
|
if (!schema || openapi_v3_1.isReferenceObject(schema)) {
|
|
28
33
|
debug('The parameter with schema %s is not coerced since schema' +
|
|
29
34
|
'dereference is not supported yet.', schema);
|
|
@@ -139,8 +144,8 @@ function coerceObject(input, spec) {
|
|
|
139
144
|
function parseJsonIfNeeded(data, spec) {
|
|
140
145
|
if (typeof data !== 'string')
|
|
141
146
|
return data;
|
|
142
|
-
if (spec.in !== 'query' || spec.
|
|
143
|
-
debug('Skipping JSON.parse, argument %s is not
|
|
147
|
+
if (spec.in !== 'query' || (spec.in === 'query' && !spec.content)) {
|
|
148
|
+
debug('Skipping JSON.parse, argument %s is not a url encoded json object query parameter (since content field is missing in parameter schema)', spec.name);
|
|
144
149
|
return data;
|
|
145
150
|
}
|
|
146
151
|
if (data === '') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"coerce-parameter.js","sourceRoot":"","sources":["../../src/coercion/coerce-parameter.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;;;AAEhE,qDAAwE;AACxE,kDAAgC;AAChC,2BAAmC;AACnC,8CAAwC;AACxC,mCASiB;AACjB,2CAAsC;AACtC,MAAM,SAAS,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;AACrD,MAAM,KAAK,GAAG,eAAW,CAAC,wBAAwB,CAAC,CAAC;AAEpD;;;;;;GAMG;AACH,SAAgB,eAAe,CAC7B,IAAiC,EACjC,IAAqB;IAErB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"coerce-parameter.js","sourceRoot":"","sources":["../../src/coercion/coerce-parameter.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;;;AAEhE,qDAAwE;AACxE,kDAAgC;AAChC,2BAAmC;AACnC,8CAAwC;AACxC,mCASiB;AACjB,2CAAsC;AACtC,MAAM,SAAS,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;AACrD,MAAM,KAAK,GAAG,eAAW,CAAC,wBAAwB,CAAC,CAAC;AAEpD;;;;;;GAMG;AACH,SAAgB,eAAe,CAC7B,IAAiC,EACjC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,QAAQ;QAAE,OAAO,IAAI,CAAC;IAE1C,IAAI,IAAI,CAAC,EAAE,KAAK,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,KAAK,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;QACjE,KAAK,CACH,wIAAwI,EACxI,IAAI,CAAC,IAAI,CACV,CAAC;QACF,OAAO,IAAI,CAAC;KACb;IAED,IAAI,IAAI,KAAK,EAAE,EAAE;QACf,KAAK,CAAC,oDAAoD,CAAC,CAAC;QAC5D,OAAO,SAAS,CAAC;KAClB;IAED,IAAI;QACF,MAAM,MAAM,GAAG,sBAAS,CAAC,IAAI,CAAC,CAAC;QAC/B,KAAK,CAAC,2BAA2B,EAAE,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACtD,OAAO,MAAM,CAAC;KACf;IAAC,OAAO,GAAG,EAAE;QACZ,KAAK,CAAC,sCAAsC,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;QAC5E,MAAM,kBAAc,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE;YAChD,OAAO,EAAE;gBACP,WAAW,EAAE,GAAG,CAAC,OAAO;aACzB;SACF,CAAC,CAAC;KACJ;AACH,CAAC"}
|
|
@@ -39,4 +39,11 @@ export declare class Validator {
|
|
|
39
39
|
* @param value
|
|
40
40
|
*/
|
|
41
41
|
isAbsent(value: any): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Return `true` if defined specification is for a url encoded Json object query parameter
|
|
44
|
+
*
|
|
45
|
+
* for url encoded Json object query parameters,
|
|
46
|
+
* schema is defined under content['application/json']
|
|
47
|
+
*/
|
|
48
|
+
isUrlEncodedJsonParam(): boolean;
|
|
42
49
|
}
|
|
@@ -50,9 +50,34 @@ class Validator {
|
|
|
50
50
|
var _a;
|
|
51
51
|
if (value === '' || value === undefined)
|
|
52
52
|
return true;
|
|
53
|
+
const spec = this.ctx.parameterSpec;
|
|
53
54
|
const schema = (_a = this.ctx.parameterSpec.schema, (_a !== null && _a !== void 0 ? _a : {}));
|
|
54
|
-
|
|
55
|
+
const valueIsNull = value === 'null' || value === null;
|
|
56
|
+
if (this.isUrlEncodedJsonParam()) {
|
|
57
|
+
// is this an url encoded Json object query parameter?
|
|
58
|
+
// check for NULL values
|
|
59
|
+
if (valueIsNull)
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
else if (spec.schema) {
|
|
63
|
+
// if parameter spec contains schema object, check if supplied value is NULL
|
|
64
|
+
if (schema.type === 'object' && valueIsNull)
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Return `true` if defined specification is for a url encoded Json object query parameter
|
|
71
|
+
*
|
|
72
|
+
* for url encoded Json object query parameters,
|
|
73
|
+
* schema is defined under content['application/json']
|
|
74
|
+
*/
|
|
75
|
+
isUrlEncodedJsonParam() {
|
|
76
|
+
var _a, _b;
|
|
77
|
+
const spec = this.ctx.parameterSpec;
|
|
78
|
+
if (spec.in === 'query' && ((_b = (_a = spec.content) === null || _a === void 0 ? void 0 : _a['application/json']) === null || _b === void 0 ? void 0 : _b.schema)) {
|
|
55
79
|
return true;
|
|
80
|
+
}
|
|
56
81
|
return false;
|
|
57
82
|
}
|
|
58
83
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/coercion/validator.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;AAGhE,2BAAmC;AAgBnC;;;GAGG;AACH,MAAa,SAAS;IACpB,YAAmB,GAAsB;QAAtB,QAAG,GAAH,GAAG,CAAmB;IAAG,CAAC;IAE7C;;;;;;;OAOG;IACH,2BAA2B,CACzB,KAAkC,EAClC,IAAwB;QAExB,IAAI,IAAI,CAAC,QAAQ,CAAC,K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1
1
|
{
|
|
2
2
|
"name": "@loopback/rest",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=8.9"
|
|
@@ -19,10 +19,10 @@
|
|
|
19
19
|
"copyright.owner": "IBM Corp.",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@loopback/context": "^2.1.
|
|
23
|
-
"@loopback/core": "^1.12.
|
|
24
|
-
"@loopback/http-server": "^1.5.
|
|
25
|
-
"@loopback/openapi-v3": "^
|
|
22
|
+
"@loopback/context": "^2.1.1",
|
|
23
|
+
"@loopback/core": "^1.12.4",
|
|
24
|
+
"@loopback/http-server": "^1.5.4",
|
|
25
|
+
"@loopback/openapi-v3": "^2.0.0",
|
|
26
26
|
"@types/body-parser": "^1.17.1",
|
|
27
27
|
"@types/cors": "^2.8.6",
|
|
28
28
|
"@types/express": "^4.17.2",
|
|
@@ -52,12 +52,12 @@
|
|
|
52
52
|
"@loopback/build": "^3.1.1",
|
|
53
53
|
"@loopback/eslint-config": "^5.0.3",
|
|
54
54
|
"@loopback/openapi-spec-builder": "^1.3.1",
|
|
55
|
-
"@loopback/repository": "^1.19.
|
|
55
|
+
"@loopback/repository": "^1.19.1",
|
|
56
56
|
"@loopback/testlab": "^1.10.3",
|
|
57
57
|
"@types/debug": "^4.1.5",
|
|
58
58
|
"@types/js-yaml": "^3.12.2",
|
|
59
59
|
"@types/lodash": "^4.14.149",
|
|
60
|
-
"@types/multer": "^1.4.
|
|
60
|
+
"@types/multer": "^1.4.2",
|
|
61
61
|
"@types/node": "^10.17.14",
|
|
62
62
|
"@types/on-finished": "^2.3.1",
|
|
63
63
|
"@types/qs": "^6.9.0",
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
"url": "https://github.com/strongloop/loopback-next.git",
|
|
77
77
|
"directory": "packages/rest"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "6eea5e428b145cafb84a998bd53979da8c8fba07"
|
|
80
80
|
}
|
|
@@ -32,7 +32,14 @@ export function coerceParameter(
|
|
|
32
32
|
data: string | undefined | object,
|
|
33
33
|
spec: ParameterObject,
|
|
34
34
|
) {
|
|
35
|
-
|
|
35
|
+
let schema = spec.schema;
|
|
36
|
+
|
|
37
|
+
// If a query parameter is a url encoded Json object, the schema is defined under content['application/json']
|
|
38
|
+
if (!schema && spec.in === 'query' && spec.content) {
|
|
39
|
+
const jsonSpec = spec.content['application/json'];
|
|
40
|
+
schema = jsonSpec.schema;
|
|
41
|
+
}
|
|
42
|
+
|
|
36
43
|
if (!schema || isReferenceObject(schema)) {
|
|
37
44
|
debug(
|
|
38
45
|
'The parameter with schema %s is not coerced since schema' +
|
|
@@ -172,9 +179,9 @@ function parseJsonIfNeeded(
|
|
|
172
179
|
): string | object | undefined {
|
|
173
180
|
if (typeof data !== 'string') return data;
|
|
174
181
|
|
|
175
|
-
if (spec.in !== 'query' || spec.
|
|
182
|
+
if (spec.in !== 'query' || (spec.in === 'query' && !spec.content)) {
|
|
176
183
|
debug(
|
|
177
|
-
'Skipping JSON.parse, argument %s is not
|
|
184
|
+
'Skipping JSON.parse, argument %s is not a url encoded json object query parameter (since content field is missing in parameter schema)',
|
|
178
185
|
spec.name,
|
|
179
186
|
);
|
|
180
187
|
return data;
|
|
@@ -65,9 +65,34 @@ export class Validator {
|
|
|
65
65
|
isAbsent(value: any) {
|
|
66
66
|
if (value === '' || value === undefined) return true;
|
|
67
67
|
|
|
68
|
+
const spec: ParameterObject = this.ctx.parameterSpec;
|
|
68
69
|
const schema: SchemaObject = this.ctx.parameterSpec.schema ?? {};
|
|
69
|
-
|
|
70
|
+
const valueIsNull = value === 'null' || value === null;
|
|
70
71
|
|
|
72
|
+
if (this.isUrlEncodedJsonParam()) {
|
|
73
|
+
// is this an url encoded Json object query parameter?
|
|
74
|
+
// check for NULL values
|
|
75
|
+
if (valueIsNull) return true;
|
|
76
|
+
} else if (spec.schema) {
|
|
77
|
+
// if parameter spec contains schema object, check if supplied value is NULL
|
|
78
|
+
if (schema.type === 'object' && valueIsNull) return true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Return `true` if defined specification is for a url encoded Json object query parameter
|
|
86
|
+
*
|
|
87
|
+
* for url encoded Json object query parameters,
|
|
88
|
+
* schema is defined under content['application/json']
|
|
89
|
+
*/
|
|
90
|
+
isUrlEncodedJsonParam() {
|
|
91
|
+
const spec: ParameterObject = this.ctx.parameterSpec;
|
|
92
|
+
|
|
93
|
+
if (spec.in === 'query' && spec.content?.['application/json']?.schema) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
71
96
|
return false;
|
|
72
97
|
}
|
|
73
98
|
}
|