@loopback/rest 9.3.0 → 10.1.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/README.md +4 -4
- package/dist/body-parsers/body-parser.helpers.js +2 -2
- package/dist/body-parsers/body-parser.helpers.js.map +1 -1
- package/dist/body-parsers/body-parser.js +12 -12
- package/dist/body-parsers/body-parser.js.map +1 -1
- package/dist/body-parsers/body-parser.json.js +8 -8
- package/dist/body-parsers/body-parser.json.js.map +1 -1
- package/dist/body-parsers/body-parser.raw.js +7 -7
- package/dist/body-parsers/body-parser.raw.js.map +1 -1
- package/dist/body-parsers/body-parser.text.js +7 -7
- package/dist/body-parsers/body-parser.text.js.map +1 -1
- package/dist/body-parsers/body-parser.urlencoded.js +7 -7
- package/dist/body-parsers/body-parser.urlencoded.js.map +1 -1
- package/dist/body-parsers/index.js +8 -8
- package/dist/body-parsers/index.js.map +1 -1
- package/dist/coercion/coerce-parameter.js +14 -14
- package/dist/coercion/coerce-parameter.js.map +1 -1
- package/dist/coercion/utils.js +2 -2
- package/dist/coercion/utils.js.map +1 -1
- package/dist/index.js +19 -19
- package/dist/index.js.map +1 -1
- package/dist/keys.d.ts +1 -1
- package/dist/keys.js +1 -1
- package/dist/keys.js.map +1 -1
- package/dist/parser.js +8 -8
- package/dist/parser.js.map +1 -1
- package/dist/providers/find-route.provider.js +10 -10
- package/dist/providers/find-route.provider.js.map +1 -1
- package/dist/providers/index.js +6 -6
- package/dist/providers/index.js.map +1 -1
- package/dist/providers/invoke-method.provider.js +9 -9
- package/dist/providers/invoke-method.provider.js.map +1 -1
- package/dist/providers/log-error.provider.js +2 -2
- package/dist/providers/log-error.provider.js.map +1 -1
- package/dist/providers/parse-params.provider.js +13 -13
- package/dist/providers/parse-params.provider.js.map +1 -1
- package/dist/providers/reject.provider.js +9 -9
- package/dist/providers/reject.provider.js.map +1 -1
- package/dist/providers/send.provider.js +4 -4
- package/dist/providers/send.provider.js.map +1 -1
- package/dist/request-context.js.map +1 -1
- package/dist/rest-http-error.js +1 -1
- package/dist/rest-http-error.js.map +1 -1
- package/dist/rest.application.js +1 -1
- package/dist/rest.application.js.map +1 -1
- package/dist/rest.component.js +16 -16
- package/dist/rest.component.js.map +1 -1
- package/dist/rest.server.d.ts +1 -1
- package/dist/rest.server.js +33 -33
- package/dist/rest.server.js.map +1 -1
- package/dist/router/controller-route.js +8 -8
- package/dist/router/controller-route.js.map +1 -1
- package/dist/router/external-express-routes.js +5 -5
- package/dist/router/external-express-routes.js.map +1 -1
- package/dist/router/handler-route.js +1 -1
- package/dist/router/handler-route.js.map +1 -1
- package/dist/router/index.js +14 -14
- package/dist/router/index.js.map +1 -1
- package/dist/router/openapi-path.js +1 -1
- package/dist/router/openapi-path.js.map +1 -1
- package/dist/router/regexp-router.js +7 -7
- package/dist/router/regexp-router.js.map +1 -1
- package/dist/router/route-entry.d.ts +1 -1
- package/dist/router/route-sort.js +1 -1
- package/dist/router/route-sort.js.map +1 -1
- package/dist/router/router-base.js +2 -2
- package/dist/router/router-base.js.map +1 -1
- package/dist/router/routing-table.js +6 -6
- package/dist/router/routing-table.js.map +1 -1
- package/dist/router/trie-router.js +5 -5
- package/dist/router/trie-router.js.map +1 -1
- package/dist/router/trie.js +2 -2
- package/dist/router/trie.js.map +1 -1
- package/dist/sequence.js +18 -18
- package/dist/sequence.js.map +1 -1
- package/dist/spec-enhancers/consolidate.spec-enhancer.js +10 -10
- package/dist/spec-enhancers/consolidate.spec-enhancer.js.map +1 -1
- package/dist/spec-enhancers/info.spec-enhancer.js +7 -7
- package/dist/spec-enhancers/info.spec-enhancer.js.map +1 -1
- package/dist/types.d.ts +12 -17
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/validation/ajv-factory.provider.js +27 -36
- package/dist/validation/ajv-factory.provider.js.map +1 -1
- package/dist/validation/openapi-formats.d.ts +5 -5
- package/dist/validation/openapi-formats.js.map +1 -1
- package/dist/validation/request-body.validator.js +9 -9
- package/dist/validation/request-body.validator.js.map +1 -1
- package/dist/writer.js +1 -1
- package/dist/writer.js.map +1 -1
- package/package.json +34 -33
- package/src/body-parsers/body-parser.helpers.ts +1 -1
- package/src/coercion/utils.ts +2 -1
- package/src/keys.ts +13 -16
- package/src/parser.ts +2 -2
- package/src/request-context.ts +2 -1
- package/src/rest.server.ts +4 -3
- package/src/router/route-entry.ts +1 -1
- package/src/router/routing-table.ts +1 -1
- package/src/types.ts +19 -15
- package/src/validation/ajv-factory.provider.ts +14 -21
- package/src/validation/openapi-formats.ts +5 -5
- package/src/validation/request-body.validator.ts +14 -13
- package/src/writer.ts +2 -2
- package/CHANGELOG.md +0 -2207
|
@@ -7,12 +7,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
exports.validateValueAgainstSchema = exports.validateRequestBody = void 0;
|
|
8
8
|
const tslib_1 = require("tslib");
|
|
9
9
|
const openapi_v3_1 = require("@loopback/openapi-v3");
|
|
10
|
-
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
11
|
-
const util_1 = tslib_1.__importDefault(require("util"));
|
|
10
|
+
const debug_1 = (0, tslib_1.__importDefault)(require("debug"));
|
|
11
|
+
const util_1 = (0, tslib_1.__importDefault)(require("util"));
|
|
12
12
|
const __1 = require("..");
|
|
13
13
|
const ajv_factory_provider_1 = require("./ajv-factory.provider");
|
|
14
14
|
const toJsonSchema = require('@openapi-contrib/openapi-schema-to-json-schema');
|
|
15
|
-
const debug = debug_1.default('loopback:rest:validation');
|
|
15
|
+
const debug = (0, debug_1.default)('loopback:rest:validation');
|
|
16
16
|
/**
|
|
17
17
|
* Check whether the request body is valid according to the provided OpenAPI schema.
|
|
18
18
|
* The JSON schema is generated from the OpenAPI schema which is typically defined
|
|
@@ -37,7 +37,7 @@ async function validateRequestBody(body, requestBodySpec, globalSchemas = {}, op
|
|
|
37
37
|
if (debug.enabled) {
|
|
38
38
|
debug('Request body schema:', util_1.default.inspect(schema, { depth: null }));
|
|
39
39
|
if (schema &&
|
|
40
|
-
openapi_v3_1.isReferenceObject(schema) &&
|
|
40
|
+
(0, openapi_v3_1.isReferenceObject)(schema) &&
|
|
41
41
|
schema.$ref.startsWith('#/components/schemas/')) {
|
|
42
42
|
const ref = schema.$ref.slice('#/components/schemas/'.length);
|
|
43
43
|
debug(' referencing:', util_1.default.inspect(globalSchemas[ref], { depth: null }));
|
|
@@ -113,9 +113,9 @@ value, schema, globalSchemas = {}, options = {}) {
|
|
|
113
113
|
}
|
|
114
114
|
let validationErrors = [];
|
|
115
115
|
try {
|
|
116
|
-
const validationResult =
|
|
116
|
+
const validationResult = validate(value);
|
|
117
117
|
debug(`Value from ${options.source} passed AJV validation.`, validationResult);
|
|
118
|
-
return validationResult;
|
|
118
|
+
return await validationResult;
|
|
119
119
|
}
|
|
120
120
|
catch (error) {
|
|
121
121
|
validationErrors = error.errors;
|
|
@@ -143,7 +143,7 @@ function buildErrorDetails(validationErrors) {
|
|
|
143
143
|
return validationErrors.map((e) => {
|
|
144
144
|
var _a;
|
|
145
145
|
return {
|
|
146
|
-
path: e.
|
|
146
|
+
path: e.instancePath,
|
|
147
147
|
code: e.keyword,
|
|
148
148
|
message: (_a = e.message) !== null && _a !== void 0 ? _a : `must pass validation rule ${e.keyword}`,
|
|
149
149
|
info: e.params,
|
|
@@ -161,11 +161,11 @@ function createValidator(schema, globalSchemas = {}, ajvInst) {
|
|
|
161
161
|
// Clone global schemas to set `$async: true` flag
|
|
162
162
|
const schemas = {};
|
|
163
163
|
for (const name in globalSchemas) {
|
|
164
|
-
// See https://github.com/
|
|
164
|
+
// See https://github.com/loopbackio/loopback-next/issues/4939
|
|
165
165
|
schemas[name] = { ...globalSchemas[name], $async: true };
|
|
166
166
|
}
|
|
167
167
|
const schemaWithRef = { components: { schemas }, ...jsonSchema };
|
|
168
|
-
// See https://
|
|
168
|
+
// See https://js.org/#asynchronous-validation for async validation
|
|
169
169
|
schemaWithRef.$async = true;
|
|
170
170
|
return ajvInst.compile(schemaWithRef);
|
|
171
171
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-body.validator.js","sourceRoot":"","sources":["../../src/validation/request-body.validator.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,qDAM8B;
|
|
1
|
+
{"version":3,"file":"request-body.validator.js","sourceRoot":"","sources":["../../src/validation/request-body.validator.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,qDAM8B;AAG9B,+DAAgC;AAChC,6DAAwB;AACxB,0BAA2D;AAM3D,iEAGgC;AAEhC,MAAM,YAAY,GAAG,OAAO,CAAC,gDAAgD,CAAC,CAAC;AAC/E,MAAM,KAAK,GAAG,IAAA,eAAW,EAAC,0BAA0B,CAAC,CAAC;AAEtD;;;;;;;;;GASG;AACI,KAAK,UAAU,mBAAmB,CACvC,IAAiB,EACjB,eAAmC,EACnC,gBAA+B,EAAE,EACjC,UAA6B,qDAA8B;IAE3D,MAAM,QAAQ,GAAG,eAAe,aAAf,eAAe,uBAAf,eAAe,CAAE,QAAQ,CAAC;IAE3C,IAAI,QAAQ,IAAI,IAAI,CAAC,KAAK,IAAI,IAAI,EAAE;QAClC,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CACvB,IAAI,cAAU,CAAC,UAAU,CAAC,0BAA0B,CAAC,EACrD;YACE,IAAI,EAAE,4BAA4B;YAClC,aAAa,EAAE,cAAc;SAC9B,CACF,CAAC;QACF,MAAM,GAAG,CAAC;KACX;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC3B,wBAAwB;IACxB,IAAI,KAAK,CAAC,OAAO,EAAE;QACjB,KAAK,CAAC,sBAAsB,EAAE,cAAI,CAAC,OAAO,CAAC,MAAM,EAAE,EAAC,KAAK,EAAE,IAAI,EAAC,CAAC,CAAC,CAAC;QACnE,IACE,MAAM;Y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MAAA,CAAC,CAAC,OAAO,mCAAI,6BAA6B,CAAC,CAAC,OAAO,EAAE;YAC9D,IAAI,EAAE,CAAC,CAAC,MAAM;SACf,CAAC;IACJ,CAAC,CACF,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,eAAe,CACtB,MAAoB,EACpB,gBAA+B,EAAE,EACjC,OAAY;IAEZ,MAAM,UAAU,GAAG,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAE/C,kDAAkD;IAClD,MAAM,OAAO,GAAkB,EAAE,CAAC;IAClC,KAAK,MAAM,IAAI,IAAI,aAAa,EAAE;QAChC,8DAA8D;QAC9D,OAAO,CAAC,IAAI,CAAC,GAAG,EAAC,GAAG,aAAa,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,IAAI,EAAC,CAAC;KACxD;IACD,MAAM,aAAa,GAAgB,EAAC,UAAU,EAAE,EAAC,OAAO,EAAC,EAAE,GAAG,UAAU,EAAC,CAAC;IAE1E,mEAAmE;IACnE,aAAa,CAAC,MAAM,GAAG,IAAI,CAAC;IAE5B,OAAO,OAAO,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC;AACxC,CAAC"}
|
package/dist/writer.js
CHANGED
|
@@ -45,7 +45,7 @@ result) {
|
|
|
45
45
|
}
|
|
46
46
|
else {
|
|
47
47
|
// TODO(ritch) remove this, should be configurable
|
|
48
|
-
// See https://github.com/
|
|
48
|
+
// See https://github.com/loopbackio/loopback-next/issues/436
|
|
49
49
|
response.setHeader('Content-Type', 'application/json');
|
|
50
50
|
// TODO(bajtos) handle errors - JSON.stringify can throw
|
|
51
51
|
result = JSON.stringify(result);
|
package/dist/writer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writer.js","sourceRoot":"","sources":["../src/writer.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;
|
|
1
|
+
{"version":3,"file":"writer.js","sourceRoot":"","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AY,CAAC,CAAC;YACjD,MAAM,GAAG,MAAM,CAAC,QAAQ,EAAE,CAAC;YAC3B,MAAM;KACT;IACD,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;AACvB,CAAC;AA/CD,sDA+CC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loopback/rest",
|
|
3
3
|
"description": "Expose controllers as REST endpoints and route REST API requests to controller methods",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "10.1.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"copyright.owner": "IBM Corp.",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/
|
|
12
|
+
"url": "https://github.com/loopbackio/loopback-next.git",
|
|
13
13
|
"directory": "packages/rest"
|
|
14
14
|
},
|
|
15
15
|
"engines": {
|
|
@@ -35,27 +35,28 @@
|
|
|
35
35
|
"!*/__tests__"
|
|
36
36
|
],
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@loopback/core": "^2.
|
|
38
|
+
"@loopback/core": "^2.18.0"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@loopback/express": "^3.3.
|
|
42
|
-
"@loopback/http-server": "^2.5.
|
|
43
|
-
"@loopback/openapi-v3": "^
|
|
44
|
-
"@openapi-contrib/openapi-schema-to-json-schema": "^3.1.
|
|
45
|
-
"@types/body-parser": "^1.19.
|
|
46
|
-
"@types/cors": "^2.8.
|
|
47
|
-
"@types/express": "^4.17.
|
|
48
|
-
"@types/express-serve-static-core": "^4.17.
|
|
49
|
-
"@types/http-errors": "^1.8.
|
|
41
|
+
"@loopback/express": "^3.3.4",
|
|
42
|
+
"@loopback/http-server": "^2.5.4",
|
|
43
|
+
"@loopback/openapi-v3": "^6.0.2",
|
|
44
|
+
"@openapi-contrib/openapi-schema-to-json-schema": "^3.1.1",
|
|
45
|
+
"@types/body-parser": "^1.19.1",
|
|
46
|
+
"@types/cors": "^2.8.12",
|
|
47
|
+
"@types/express": "^4.17.13",
|
|
48
|
+
"@types/express-serve-static-core": "^4.17.24",
|
|
49
|
+
"@types/http-errors": "^1.8.1",
|
|
50
50
|
"@types/on-finished": "^2.3.1",
|
|
51
|
-
"@types/serve-static": "1.13.
|
|
51
|
+
"@types/serve-static": "1.13.10",
|
|
52
52
|
"@types/type-is": "^1.6.3",
|
|
53
|
-
"ajv": "^6.
|
|
54
|
-
"ajv-errors": "^
|
|
55
|
-
"ajv-
|
|
53
|
+
"ajv": "^8.6.3",
|
|
54
|
+
"ajv-errors": "^3.0.0",
|
|
55
|
+
"ajv-formats": "^2.1.1",
|
|
56
|
+
"ajv-keywords": "^5.0.0",
|
|
56
57
|
"body-parser": "^1.19.0",
|
|
57
58
|
"cors": "^2.8.5",
|
|
58
|
-
"debug": "^4.3.
|
|
59
|
+
"debug": "^4.3.2",
|
|
59
60
|
"express": "^4.17.1",
|
|
60
61
|
"http-errors": "^1.8.0",
|
|
61
62
|
"js-yaml": "^4.1.0",
|
|
@@ -65,26 +66,26 @@
|
|
|
65
66
|
"path-to-regexp": "^6.2.0",
|
|
66
67
|
"qs": "^6.10.1",
|
|
67
68
|
"strong-error-handler": "^4.0.0",
|
|
68
|
-
"tslib": "^2.
|
|
69
|
+
"tslib": "^2.3.1",
|
|
69
70
|
"type-is": "^1.6.18",
|
|
70
71
|
"validator": "^13.6.0"
|
|
71
72
|
},
|
|
72
73
|
"devDependencies": {
|
|
73
|
-
"@loopback/build": "^
|
|
74
|
-
"@loopback/core": "^2.
|
|
75
|
-
"@loopback/eslint-config": "^
|
|
76
|
-
"@loopback/openapi-spec-builder": "^3.2.
|
|
77
|
-
"@loopback/repository": "^3.
|
|
78
|
-
"@loopback/testlab": "^3.4.
|
|
79
|
-
"@types/debug": "^4.1.
|
|
80
|
-
"@types/js-yaml": "^4.0.
|
|
81
|
-
"@types/json-schema-compare": "^0.2.
|
|
82
|
-
"@types/lodash": "^4.14.
|
|
83
|
-
"@types/multer": "^1.4.
|
|
84
|
-
"@types/node": "^10.17.
|
|
74
|
+
"@loopback/build": "^7.0.2",
|
|
75
|
+
"@loopback/core": "^2.18.0",
|
|
76
|
+
"@loopback/eslint-config": "^11.0.2",
|
|
77
|
+
"@loopback/openapi-spec-builder": "^3.2.4",
|
|
78
|
+
"@loopback/repository": "^3.7.3",
|
|
79
|
+
"@loopback/testlab": "^3.4.4",
|
|
80
|
+
"@types/debug": "^4.1.7",
|
|
81
|
+
"@types/js-yaml": "^4.0.3",
|
|
82
|
+
"@types/json-schema-compare": "^0.2.1",
|
|
83
|
+
"@types/lodash": "^4.14.175",
|
|
84
|
+
"@types/multer": "^1.4.7",
|
|
85
|
+
"@types/node": "^10.17.60",
|
|
85
86
|
"@types/on-finished": "^2.3.1",
|
|
86
|
-
"@types/qs": "^6.9.
|
|
87
|
-
"multer": "^1.4.
|
|
87
|
+
"@types/qs": "^6.9.7",
|
|
88
|
+
"multer": "^1.4.3"
|
|
88
89
|
},
|
|
89
|
-
"gitHead": "
|
|
90
|
+
"gitHead": "d9a29c85dbe38f12ba219d8c495cf6038bbc3590"
|
|
90
91
|
}
|
|
@@ -56,7 +56,7 @@ export function invokeBodyParserMiddleware(
|
|
|
56
56
|
request: Request,
|
|
57
57
|
): Promise<any> {
|
|
58
58
|
// A hack to fool TypeScript as we don't need `response`
|
|
59
|
-
const response =
|
|
59
|
+
const response = {} as any as Response;
|
|
60
60
|
return new Promise<void>((resolve, reject) => {
|
|
61
61
|
handle(request, response, err => {
|
|
62
62
|
if (err) {
|
package/src/coercion/utils.ts
CHANGED
|
@@ -51,7 +51,8 @@ export function isValidDateTime(data: Date) {
|
|
|
51
51
|
return isNaN(data.getTime()) ? false : true;
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
const REGEX_RFC3339_DATE =
|
|
54
|
+
const REGEX_RFC3339_DATE =
|
|
55
|
+
/^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])$/;
|
|
55
56
|
|
|
56
57
|
/**
|
|
57
58
|
* Return true when a date follows the RFC3339 standard
|
package/src/keys.ts
CHANGED
|
@@ -36,9 +36,8 @@ export namespace RestBindings {
|
|
|
36
36
|
/**
|
|
37
37
|
* Binding key for setting and injecting RestComponentConfig
|
|
38
38
|
*/
|
|
39
|
-
export const CONFIG: BindingKey<RestServerConfig> =
|
|
40
|
-
'rest'
|
|
41
|
-
);
|
|
39
|
+
export const CONFIG: BindingKey<RestServerConfig> =
|
|
40
|
+
CoreBindings.APPLICATION_CONFIG.deepProperty('rest');
|
|
42
41
|
/**
|
|
43
42
|
* Binding key for setting and injecting the host name of RestServer
|
|
44
43
|
*/
|
|
@@ -62,9 +61,8 @@ export namespace RestBindings {
|
|
|
62
61
|
/**
|
|
63
62
|
* Binding key for HTTPS options
|
|
64
63
|
*/
|
|
65
|
-
export const HTTPS_OPTIONS =
|
|
66
|
-
'rest.httpsOptions'
|
|
67
|
-
);
|
|
64
|
+
export const HTTPS_OPTIONS =
|
|
65
|
+
BindingKey.create<https.ServerOptions>('rest.httpsOptions');
|
|
68
66
|
|
|
69
67
|
/**
|
|
70
68
|
* Binding key for the server itself
|
|
@@ -94,7 +92,7 @@ export namespace RestBindings {
|
|
|
94
92
|
* Binding key for setting and injecting Reject action's error handling
|
|
95
93
|
* options.
|
|
96
94
|
*
|
|
97
|
-
* See https://github.com/
|
|
95
|
+
* See https://github.com/loopbackio/strong-error-handler#options for
|
|
98
96
|
* the list of available options. Please note that the flag `log` is not used
|
|
99
97
|
* by `@loopback/rest`.
|
|
100
98
|
*/
|
|
@@ -105,9 +103,10 @@ export namespace RestBindings {
|
|
|
105
103
|
/**
|
|
106
104
|
* Binding key for request body parser options
|
|
107
105
|
*/
|
|
108
|
-
export const REQUEST_BODY_PARSER_OPTIONS =
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
export const REQUEST_BODY_PARSER_OPTIONS =
|
|
107
|
+
BindingKey.create<RequestBodyParserOptions>(
|
|
108
|
+
'rest.requestBodyParserOptions',
|
|
109
|
+
);
|
|
111
110
|
|
|
112
111
|
/**
|
|
113
112
|
* Binding key for request body parser
|
|
@@ -165,9 +164,8 @@ export namespace RestBindings {
|
|
|
165
164
|
/**
|
|
166
165
|
* Binding key for setting and injecting an OpenAPI spec
|
|
167
166
|
*/
|
|
168
|
-
export const API_SPEC: BindingKey<OpenApiSpec> =
|
|
169
|
-
'rest.apiSpec'
|
|
170
|
-
);
|
|
167
|
+
export const API_SPEC: BindingKey<OpenApiSpec> =
|
|
168
|
+
BindingKey.create<OpenApiSpec>('rest.apiSpec');
|
|
171
169
|
|
|
172
170
|
/**
|
|
173
171
|
* Binding key for setting and injecting an OpenAPI operation spec
|
|
@@ -256,9 +254,8 @@ export namespace RestBindings {
|
|
|
256
254
|
/**
|
|
257
255
|
* Binding key for setting and injecting the http request
|
|
258
256
|
*/
|
|
259
|
-
export const REQUEST: BindingKey<Request> =
|
|
260
|
-
'rest.http.request'
|
|
261
|
-
);
|
|
257
|
+
export const REQUEST: BindingKey<Request> =
|
|
258
|
+
BindingKey.create<Request>('rest.http.request');
|
|
262
259
|
/**
|
|
263
260
|
* Binding key for setting and injecting the http response
|
|
264
261
|
*/
|
package/src/parser.ts
CHANGED
|
@@ -79,7 +79,7 @@ async function buildOperationArguments(
|
|
|
79
79
|
for (const paramSpec of operationSpec.parameters ?? []) {
|
|
80
80
|
if (isReferenceObject(paramSpec)) {
|
|
81
81
|
// TODO(bajtos) implement $ref parameters
|
|
82
|
-
// See https://github.com/
|
|
82
|
+
// See https://github.com/loopbackio/loopback-next/issues/435
|
|
83
83
|
throw new Error('$ref parameters are not supported yet.');
|
|
84
84
|
}
|
|
85
85
|
const spec = paramSpec as ParameterObject;
|
|
@@ -116,7 +116,7 @@ function getParamFromRequest(
|
|
|
116
116
|
// @jannyhou TBD: check edge cases
|
|
117
117
|
return request.headers[spec.name.toLowerCase()];
|
|
118
118
|
// TODO(jannyhou) to support `cookie`,
|
|
119
|
-
// see issue https://github.com/
|
|
119
|
+
// see issue https://github.com/loopbackio/loopback-next/issues/997
|
|
120
120
|
default:
|
|
121
121
|
throw RestHttpErrors.invalidParamLocation(spec.in);
|
|
122
122
|
}
|
package/src/request-context.ts
CHANGED
|
@@ -19,7 +19,8 @@ import {RestServerResolvedConfig} from './rest.server';
|
|
|
19
19
|
*/
|
|
20
20
|
export class RequestContext
|
|
21
21
|
extends MiddlewareContext
|
|
22
|
-
implements HandlerContext
|
|
22
|
+
implements HandlerContext
|
|
23
|
+
{
|
|
23
24
|
/**
|
|
24
25
|
* Get the protocol used by the client to make the request.
|
|
25
26
|
* Please note this protocol may be different from what we are observing
|
package/src/rest.server.ts
CHANGED
|
@@ -113,7 +113,8 @@ const SequenceActions = RestBindings.SequenceActions;
|
|
|
113
113
|
*/
|
|
114
114
|
export class RestServer
|
|
115
115
|
extends BaseMiddlewareRegistry
|
|
116
|
-
implements Server, HttpServerLike
|
|
116
|
+
implements Server, HttpServerLike
|
|
117
|
+
{
|
|
117
118
|
/**
|
|
118
119
|
* Handle incoming HTTP(S) request by invoking the corresponding
|
|
119
120
|
* Controller method via the configured Sequence.
|
|
@@ -397,7 +398,7 @@ export class RestServer
|
|
|
397
398
|
if (this._httpHandler) return;
|
|
398
399
|
|
|
399
400
|
// Watch for binding events
|
|
400
|
-
// See https://github.com/
|
|
401
|
+
// See https://github.com/loopbackio/loopback-next/issues/433
|
|
401
402
|
const routesObserver: ContextObserver = {
|
|
402
403
|
filter: binding =>
|
|
403
404
|
filterByKey(RestBindings.API_SPEC.key)(binding) ||
|
|
@@ -1146,7 +1147,7 @@ export interface ApiExplorerOptions {
|
|
|
1146
1147
|
* URL for the API explorer served over `http` protocol to deal with mixed
|
|
1147
1148
|
* content security imposed by browsers as the spec is exposed over `http` by
|
|
1148
1149
|
* default.
|
|
1149
|
-
* See https://github.com/
|
|
1150
|
+
* See https://github.com/loopbackio/loopback-next/issues/1603
|
|
1150
1151
|
*/
|
|
1151
1152
|
httpUrl?: string;
|
|
1152
1153
|
|
|
@@ -53,7 +53,7 @@ export interface ResolvedRoute extends RouteEntry {
|
|
|
53
53
|
* Server/application wide schemas shared by multiple routes,
|
|
54
54
|
* e.g. model schemas. This is a temporary workaround for
|
|
55
55
|
* missing support for $ref references, see
|
|
56
|
-
* https://github.com/
|
|
56
|
+
* https://github.com/loopbackio/loopback-next/issues/435
|
|
57
57
|
*/
|
|
58
58
|
readonly schemas: SchemasObject;
|
|
59
59
|
}
|
|
@@ -61,7 +61,7 @@ export class RoutingTable {
|
|
|
61
61
|
*/
|
|
62
62
|
registerRoute(route: RouteEntry) {
|
|
63
63
|
// TODO(bajtos) handle the case where opSpec.parameters contains $ref
|
|
64
|
-
// See https://github.com/
|
|
64
|
+
// See https://github.com/loopbackio/loopback-next/issues/435
|
|
65
65
|
/* istanbul ignore if */
|
|
66
66
|
if (debug.enabled) {
|
|
67
67
|
debug(
|
package/src/types.ts
CHANGED
|
@@ -5,7 +5,14 @@
|
|
|
5
5
|
|
|
6
6
|
import {HandlerContext, Request, Response} from '@loopback/express';
|
|
7
7
|
import {ReferenceObject, SchemaObject} from '@loopback/openapi-v3';
|
|
8
|
-
import
|
|
8
|
+
import Ajv, {
|
|
9
|
+
ErrorObject,
|
|
10
|
+
FormatDefinition,
|
|
11
|
+
KeywordDefinition,
|
|
12
|
+
Options as AjvOptions,
|
|
13
|
+
ValidateFunction,
|
|
14
|
+
} from 'ajv';
|
|
15
|
+
import {ErrorMessageOptions} from 'ajv-errors';
|
|
9
16
|
import {
|
|
10
17
|
Options,
|
|
11
18
|
OptionsJson,
|
|
@@ -82,31 +89,29 @@ export type LogError = (
|
|
|
82
89
|
*/
|
|
83
90
|
export type SchemaValidatorCache = WeakMap<
|
|
84
91
|
SchemaObject | ReferenceObject, // First keyed by schema object
|
|
85
|
-
Map<string,
|
|
92
|
+
Map<string, ValidateFunction> // Second level keyed by stringified AJV options
|
|
86
93
|
>;
|
|
87
94
|
|
|
88
95
|
/**
|
|
89
96
|
* Options for AJV errors
|
|
90
97
|
*/
|
|
91
|
-
export type AjvErrorOptions =
|
|
92
|
-
keepErrors?: boolean;
|
|
93
|
-
singleError?: boolean;
|
|
94
|
-
};
|
|
98
|
+
export type AjvErrorOptions = ErrorMessageOptions;
|
|
95
99
|
|
|
96
100
|
/**
|
|
97
101
|
* Factory function for Ajv instances
|
|
98
102
|
*/
|
|
99
|
-
export type AjvFactory = (options?:
|
|
103
|
+
export type AjvFactory = (options?: AjvOptions) => Ajv;
|
|
100
104
|
|
|
101
105
|
/**
|
|
102
106
|
* Ajv keyword definition with a name
|
|
103
107
|
*/
|
|
104
|
-
export type AjvKeyword = KeywordDefinition
|
|
108
|
+
export type AjvKeyword = KeywordDefinition;
|
|
105
109
|
|
|
106
110
|
/**
|
|
107
111
|
* Ajv format definition with a name
|
|
108
112
|
*/
|
|
109
|
-
export type AjvFormat
|
|
113
|
+
export type AjvFormat<T extends string | number = string> =
|
|
114
|
+
FormatDefinition<T> & {name: string};
|
|
110
115
|
|
|
111
116
|
/**
|
|
112
117
|
* Options for any value validation using AJV
|
|
@@ -127,7 +132,7 @@ export interface ValueValidationOptions extends ValidationOptions {
|
|
|
127
132
|
/**
|
|
128
133
|
* Options for request body validation using AJV
|
|
129
134
|
*/
|
|
130
|
-
export interface ValidationOptions extends
|
|
135
|
+
export interface ValidationOptions extends AjvOptions {
|
|
131
136
|
/**
|
|
132
137
|
* Custom cache for compiled schemas by AJV. This setting makes it possible
|
|
133
138
|
* to skip the default cache.
|
|
@@ -135,27 +140,26 @@ export interface ValidationOptions extends ajv.Options {
|
|
|
135
140
|
compiledSchemaCache?: SchemaValidatorCache;
|
|
136
141
|
/**
|
|
137
142
|
* Enable additional AJV keywords from https://github.com/epoberezkin/ajv-keywords
|
|
138
|
-
* - `true`: Add all keywords from `ajv-keywords`
|
|
139
143
|
* - `string[]`: Add an array of keywords from `ajv-keywords`
|
|
140
144
|
*/
|
|
141
|
-
ajvKeywords?:
|
|
145
|
+
ajvKeywords?: string[];
|
|
142
146
|
/**
|
|
143
147
|
* Enable custom error messages in JSON-Schema for AJV validator
|
|
144
148
|
* from https://github.com/epoberezkin/ajv-errors
|
|
145
149
|
* - `true`: Enable `ajv-errors`
|
|
146
150
|
* - `AjvErrorOptions`: Enable `ajv-errors` with options
|
|
147
151
|
*/
|
|
148
|
-
ajvErrors?:
|
|
152
|
+
ajvErrors?: AjvErrorOptions;
|
|
149
153
|
/**
|
|
150
154
|
* A function that transform the `ErrorObject`s reported by AJV.
|
|
151
155
|
* This could be used for error messages customization, localization, etc.
|
|
152
156
|
*/
|
|
153
|
-
ajvErrorTransformer?: (errors:
|
|
157
|
+
ajvErrorTransformer?: (errors: ErrorObject[]) => ErrorObject[];
|
|
154
158
|
|
|
155
159
|
/**
|
|
156
160
|
* A factory to create Ajv instance
|
|
157
161
|
*/
|
|
158
|
-
ajvFactory?: (options:
|
|
162
|
+
ajvFactory?: (options: AjvOptions) => Ajv;
|
|
159
163
|
|
|
160
164
|
/**
|
|
161
165
|
* An array of keys to be rejected, such as `__proto__`.
|
|
@@ -11,6 +11,9 @@ import {
|
|
|
11
11
|
Provider,
|
|
12
12
|
} from '@loopback/core';
|
|
13
13
|
import AjvCtor from 'ajv';
|
|
14
|
+
import ajvErrors from 'ajv-errors';
|
|
15
|
+
import ajvFormats from 'ajv-formats';
|
|
16
|
+
import ajvKeywords from 'ajv-keywords';
|
|
14
17
|
import debugModule from 'debug';
|
|
15
18
|
import {RestBindings, RestTags} from '../keys';
|
|
16
19
|
import {AjvFactory, AjvFormat, AjvKeyword, ValidationOptions} from '../types';
|
|
@@ -18,13 +21,8 @@ import {openapiFormats} from './openapi-formats';
|
|
|
18
21
|
|
|
19
22
|
const debug = debugModule('loopback:rest:ajv');
|
|
20
23
|
|
|
21
|
-
const ajvKeywords = require('ajv-keywords');
|
|
22
|
-
const ajvErrors = require('ajv-errors');
|
|
23
|
-
|
|
24
24
|
export const DEFAULT_AJV_VALIDATION_OPTIONS: ValidationOptions = {
|
|
25
25
|
$data: true,
|
|
26
|
-
ajvKeywords: true,
|
|
27
|
-
ajvErrors: true,
|
|
28
26
|
};
|
|
29
27
|
|
|
30
28
|
/**
|
|
@@ -55,34 +53,29 @@ export class AjvFactoryProvider implements Provider<AjvFactory> {
|
|
|
55
53
|
// See https://github.com/epoberezkin/ajv#options
|
|
56
54
|
validationOptions = {
|
|
57
55
|
allErrors: true,
|
|
58
|
-
|
|
59
|
-
// nullable: support keyword "nullable" from Open API 3 specification.
|
|
60
|
-
nullable: true,
|
|
56
|
+
strictTypes: false,
|
|
61
57
|
...validationOptions,
|
|
62
58
|
};
|
|
63
59
|
|
|
64
60
|
debug('AJV options', validationOptions);
|
|
65
|
-
const
|
|
61
|
+
const ajvOptions = {...validationOptions};
|
|
62
|
+
delete ajvOptions.ajvErrors;
|
|
63
|
+
const ajvInst = new AjvCtor(ajvOptions);
|
|
64
|
+
ajvInst.addKeyword('components');
|
|
65
|
+
ajvInst.addKeyword('x-typescript-type');
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
ajvKeywords(ajvInst);
|
|
69
|
-
} else if (Array.isArray(validationOptions.ajvKeywords)) {
|
|
70
|
-
ajvKeywords(ajvInst, validationOptions.ajvKeywords);
|
|
71
|
-
}
|
|
67
|
+
ajvKeywords(ajvInst, validationOptions.ajvKeywords);
|
|
72
68
|
|
|
73
|
-
|
|
74
|
-
ajvErrors(ajvInst);
|
|
75
|
-
} else if (validationOptions.ajvErrors?.constructor === Object) {
|
|
76
|
-
ajvErrors(ajvInst, validationOptions.ajvErrors);
|
|
77
|
-
}
|
|
69
|
+
ajvErrors(ajvInst, validationOptions.ajvErrors);
|
|
78
70
|
|
|
79
71
|
if (this.keywords) {
|
|
80
72
|
this.keywords.forEach(keyword => {
|
|
81
|
-
debug('Adding Ajv keyword %s', keyword.
|
|
82
|
-
ajvInst.addKeyword(keyword
|
|
73
|
+
debug('Adding Ajv keyword %s', keyword.keyword);
|
|
74
|
+
ajvInst.addKeyword(keyword);
|
|
83
75
|
});
|
|
84
76
|
}
|
|
85
77
|
|
|
78
|
+
ajvFormats(ajvInst);
|
|
86
79
|
for (const format of openapiFormats) {
|
|
87
80
|
ajvInst.addFormat(format.name, format);
|
|
88
81
|
}
|
|
@@ -8,7 +8,7 @@ import {AjvFormat} from '../types';
|
|
|
8
8
|
/**
|
|
9
9
|
* int32: [-2147483648, 21474836 47]
|
|
10
10
|
*/
|
|
11
|
-
export const int32Format: AjvFormat = {
|
|
11
|
+
export const int32Format: AjvFormat<number> = {
|
|
12
12
|
name: 'int32',
|
|
13
13
|
type: 'number',
|
|
14
14
|
validate: (value: number) => {
|
|
@@ -22,7 +22,7 @@ export const int32Format: AjvFormat = {
|
|
|
22
22
|
/**
|
|
23
23
|
* int64: [-9223372036854775808, 9223372036854775807]
|
|
24
24
|
*/
|
|
25
|
-
export const int64Format: AjvFormat = {
|
|
25
|
+
export const int64Format: AjvFormat<number> = {
|
|
26
26
|
name: 'int64',
|
|
27
27
|
type: 'number',
|
|
28
28
|
validate: (value: number) => {
|
|
@@ -36,7 +36,7 @@ export const int64Format: AjvFormat = {
|
|
|
36
36
|
/**
|
|
37
37
|
* float: [-2^128, 2^128]
|
|
38
38
|
*/
|
|
39
|
-
export const floatFormat: AjvFormat = {
|
|
39
|
+
export const floatFormat: AjvFormat<number> = {
|
|
40
40
|
name: 'float',
|
|
41
41
|
type: 'number',
|
|
42
42
|
validate: (value: number) => {
|
|
@@ -48,7 +48,7 @@ export const floatFormat: AjvFormat = {
|
|
|
48
48
|
/**
|
|
49
49
|
* double: [-2^1024, 2^1024]
|
|
50
50
|
*/
|
|
51
|
-
export const doubleFormat: AjvFormat = {
|
|
51
|
+
export const doubleFormat: AjvFormat<number> = {
|
|
52
52
|
name: 'double',
|
|
53
53
|
type: 'number',
|
|
54
54
|
validate: (value: number) => {
|
|
@@ -82,7 +82,7 @@ export const binaryFormat: AjvFormat = {
|
|
|
82
82
|
async: false,
|
|
83
83
|
};
|
|
84
84
|
|
|
85
|
-
export const openapiFormats: AjvFormat[] = [
|
|
85
|
+
export const openapiFormats: (AjvFormat<string> | AjvFormat<number>)[] = [
|
|
86
86
|
int32Format,
|
|
87
87
|
int64Format,
|
|
88
88
|
floatFormat,
|