@loopback/rest 5.0.1 → 5.2.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.
Files changed (118) hide show
  1. package/CHANGELOG.md +47 -0
  2. package/dist/body-parsers/body-parser.d.ts +1 -1
  3. package/dist/body-parsers/body-parser.helpers.js +1 -1
  4. package/dist/body-parsers/body-parser.js +112 -115
  5. package/dist/body-parsers/body-parser.js.map +1 -1
  6. package/dist/body-parsers/body-parser.json.js +24 -27
  7. package/dist/body-parsers/body-parser.json.js.map +1 -1
  8. package/dist/body-parsers/body-parser.raw.js +19 -22
  9. package/dist/body-parsers/body-parser.raw.js.map +1 -1
  10. package/dist/body-parsers/body-parser.text.js +21 -24
  11. package/dist/body-parsers/body-parser.text.js.map +1 -1
  12. package/dist/body-parsers/body-parser.urlencoded.js +19 -22
  13. package/dist/body-parsers/body-parser.urlencoded.js.map +1 -1
  14. package/dist/body-parsers/index.js +1 -1
  15. package/dist/body-parsers/index.js.map +1 -1
  16. package/dist/coercion/coerce-parameter.d.ts +3 -1
  17. package/dist/coercion/coerce-parameter.js +28 -12
  18. package/dist/coercion/coerce-parameter.js.map +1 -1
  19. package/dist/coercion/validator.js +1 -1
  20. package/dist/http-handler.d.ts +1 -1
  21. package/dist/http-handler.js +1 -1
  22. package/dist/index.d.ts +1 -0
  23. package/dist/index.js +2 -0
  24. package/dist/index.js.map +1 -1
  25. package/dist/keys.d.ts +1 -1
  26. package/dist/keys.js +33 -34
  27. package/dist/keys.js.map +1 -1
  28. package/dist/parser.js +1 -1
  29. package/dist/parser.js.map +1 -1
  30. package/dist/providers/find-route.provider.d.ts +1 -1
  31. package/dist/providers/find-route.provider.js +21 -24
  32. package/dist/providers/find-route.provider.js.map +1 -1
  33. package/dist/providers/invoke-method.provider.d.ts +1 -1
  34. package/dist/providers/invoke-method.provider.js +16 -19
  35. package/dist/providers/invoke-method.provider.js.map +1 -1
  36. package/dist/providers/log-error.provider.d.ts +1 -1
  37. package/dist/providers/parse-params.provider.d.ts +1 -1
  38. package/dist/providers/parse-params.provider.js +20 -23
  39. package/dist/providers/parse-params.provider.js.map +1 -1
  40. package/dist/providers/reject.provider.d.ts +1 -1
  41. package/dist/providers/reject.provider.js +25 -28
  42. package/dist/providers/reject.provider.js.map +1 -1
  43. package/dist/providers/send.provider.d.ts +1 -1
  44. package/dist/request-context.d.ts +1 -1
  45. package/dist/rest.application.d.ts +15 -2
  46. package/dist/rest.application.js +14 -1
  47. package/dist/rest.application.js.map +1 -1
  48. package/dist/rest.component.d.ts +1 -1
  49. package/dist/rest.component.js +46 -49
  50. package/dist/rest.component.js.map +1 -1
  51. package/dist/rest.server.d.ts +15 -2
  52. package/dist/rest.server.js +615 -588
  53. package/dist/rest.server.js.map +1 -1
  54. package/dist/router/base-route.d.ts +1 -1
  55. package/dist/router/controller-route.d.ts +1 -1
  56. package/dist/router/controller-route.js +3 -4
  57. package/dist/router/controller-route.js.map +1 -1
  58. package/dist/router/external-express-routes.js +1 -1
  59. package/dist/router/external-express-routes.js.map +1 -1
  60. package/dist/router/handler-route.d.ts +1 -1
  61. package/dist/router/handler-route.js +2 -2
  62. package/dist/router/handler-route.js.map +1 -1
  63. package/dist/router/redirect-route.js +2 -2
  64. package/dist/router/redirect-route.js.map +1 -1
  65. package/dist/router/regexp-router.js +55 -58
  66. package/dist/router/regexp-router.js.map +1 -1
  67. package/dist/router/route-entry.d.ts +1 -1
  68. package/dist/router/trie-router.js +32 -35
  69. package/dist/router/trie-router.js.map +1 -1
  70. package/dist/sequence.d.ts +1 -1
  71. package/dist/sequence.js +74 -77
  72. package/dist/sequence.js.map +1 -1
  73. package/dist/spec-enhancers/consolidate.spec-enhancer.js +89 -92
  74. package/dist/spec-enhancers/consolidate.spec-enhancer.js.map +1 -1
  75. package/dist/spec-enhancers/info.spec-enhancer.js +63 -67
  76. package/dist/spec-enhancers/info.spec-enhancer.js.map +1 -1
  77. package/dist/types.d.ts +10 -0
  78. package/dist/validation/ajv-factory.provider.js +63 -66
  79. package/dist/validation/ajv-factory.provider.js.map +1 -1
  80. package/dist/validation/request-body.validator.d.ts +10 -2
  81. package/dist/validation/request-body.validator.js +25 -9
  82. package/dist/validation/request-body.validator.js.map +1 -1
  83. package/package.json +25 -23
  84. package/src/body-parsers/body-parser.helpers.ts +1 -1
  85. package/src/body-parsers/body-parser.json.ts +1 -1
  86. package/src/body-parsers/body-parser.raw.ts +1 -1
  87. package/src/body-parsers/body-parser.text.ts +1 -1
  88. package/src/body-parsers/body-parser.ts +1 -1
  89. package/src/body-parsers/body-parser.urlencoded.ts +1 -1
  90. package/src/body-parsers/index.ts +1 -1
  91. package/src/coercion/coerce-parameter.ts +55 -15
  92. package/src/coercion/validator.ts +1 -1
  93. package/src/http-handler.ts +2 -2
  94. package/src/index.ts +6 -0
  95. package/src/keys.ts +1 -2
  96. package/src/parser.ts +1 -1
  97. package/src/providers/find-route.provider.ts +1 -1
  98. package/src/providers/invoke-method.provider.ts +1 -1
  99. package/src/providers/log-error.provider.ts +1 -1
  100. package/src/providers/parse-params.provider.ts +1 -1
  101. package/src/providers/reject.provider.ts +1 -1
  102. package/src/providers/send.provider.ts +1 -1
  103. package/src/request-context.ts +1 -1
  104. package/src/rest.application.ts +19 -3
  105. package/src/rest.component.ts +1 -1
  106. package/src/rest.server.ts +35 -3
  107. package/src/router/base-route.ts +1 -1
  108. package/src/router/controller-route.ts +2 -2
  109. package/src/router/external-express-routes.ts +2 -2
  110. package/src/router/handler-route.ts +1 -1
  111. package/src/router/redirect-route.ts +1 -2
  112. package/src/router/regexp-router.ts +1 -1
  113. package/src/router/route-entry.ts +1 -1
  114. package/src/router/trie-router.ts +2 -2
  115. package/src/sequence.ts +1 -1
  116. package/src/spec-enhancers/info.spec-enhancer.ts +3 -2
  117. package/src/types.ts +11 -0
  118. package/src/validation/request-body.validator.ts +35 -12
package/dist/sequence.js CHANGED
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.DefaultSequence = void 0;
8
8
  const tslib_1 = require("tslib");
9
9
  const debug = require('debug')('loopback:rest:sequence');
10
- const context_1 = require("@loopback/context");
10
+ const core_1 = require("@loopback/core");
11
11
  const keys_1 = require("./keys");
12
12
  const SequenceActions = keys_1.RestBindings.SequenceActions;
13
13
  /**
@@ -28,85 +28,82 @@ const SequenceActions = keys_1.RestBindings.SequenceActions;
28
28
  * app.bind(CoreBindings.SEQUENCE).toClass(MySequence);
29
29
  * ```
30
30
  */
31
- let DefaultSequence = /** @class */ (() => {
32
- let DefaultSequence = class DefaultSequence {
31
+ let DefaultSequence = class DefaultSequence {
32
+ /**
33
+ * Constructor: Injects findRoute, invokeMethod & logError
34
+ * methods as promises.
35
+ *
36
+ * @param findRoute - Finds the appropriate controller method,
37
+ * spec and args for invocation (injected via SequenceActions.FIND_ROUTE).
38
+ * @param parseParams - The parameter parsing function (injected
39
+ * via SequenceActions.PARSE_PARAMS).
40
+ * @param invoke - Invokes the method specified by the route
41
+ * (injected via SequenceActions.INVOKE_METHOD).
42
+ * @param send - The action to merge the invoke result with the response
43
+ * (injected via SequenceActions.SEND)
44
+ * @param reject - The action to take if the invoke returns a rejected
45
+ * promise result (injected via SequenceActions.REJECT).
46
+ */
47
+ constructor(findRoute, parseParams, invoke, send, reject) {
48
+ this.findRoute = findRoute;
49
+ this.parseParams = parseParams;
50
+ this.invoke = invoke;
51
+ this.send = send;
52
+ this.reject = reject;
33
53
  /**
34
- * Constructor: Injects findRoute, invokeMethod & logError
35
- * methods as promises.
36
- *
37
- * @param findRoute - Finds the appropriate controller method,
38
- * spec and args for invocation (injected via SequenceActions.FIND_ROUTE).
39
- * @param parseParams - The parameter parsing function (injected
40
- * via SequenceActions.PARSE_PARAMS).
41
- * @param invoke - Invokes the method specified by the route
42
- * (injected via SequenceActions.INVOKE_METHOD).
43
- * @param send - The action to merge the invoke result with the response
44
- * (injected via SequenceActions.SEND)
45
- * @param reject - The action to take if the invoke returns a rejected
46
- * promise result (injected via SequenceActions.REJECT).
54
+ * Optional invoker for registered middleware in a chain.
55
+ * To be injected via SequenceActions.INVOKE_MIDDLEWARE.
47
56
  */
48
- constructor(findRoute, parseParams, invoke, send, reject) {
49
- this.findRoute = findRoute;
50
- this.parseParams = parseParams;
51
- this.invoke = invoke;
52
- this.send = send;
53
- this.reject = reject;
54
- /**
55
- * Optional invoker for registered middleware in a chain.
56
- * To be injected via SequenceActions.INVOKE_MIDDLEWARE.
57
- */
58
- this.invokeMiddleware = () => false;
59
- }
60
- /**
61
- * Runs the default sequence. Given a handler context (request and response),
62
- * running the sequence will produce a response or an error.
63
- *
64
- * Default sequence executes these steps
65
- * - Executes middleware for CORS, OpenAPI spec endpoints
66
- * - Finds the appropriate controller method, swagger spec
67
- * and args for invocation
68
- * - Parses HTTP request to get API argument list
69
- * - Invokes the API which is defined in the Application Controller
70
- * - Writes the result from API into the HTTP response
71
- * - Error is caught and logged using 'logError' if any of the above steps
72
- * in the sequence fails with an error.
73
- *
74
- * @param context - The request context: HTTP request and response objects,
75
- * per-request IoC container and more.
76
- */
77
- async handle(context) {
78
- try {
79
- const { request, response } = context;
80
- // Invoke registered Express middleware
81
- const finished = await this.invokeMiddleware(context);
82
- if (finished) {
83
- // The response been produced by the middleware chain
84
- return;
85
- }
86
- const route = this.findRoute(request);
87
- const args = await this.parseParams(request, route);
88
- const result = await this.invoke(route, args);
89
- debug('%s result -', route.describe(), result);
90
- this.send(response, result);
91
- }
92
- catch (error) {
93
- this.reject(context, error);
57
+ this.invokeMiddleware = () => false;
58
+ }
59
+ /**
60
+ * Runs the default sequence. Given a handler context (request and response),
61
+ * running the sequence will produce a response or an error.
62
+ *
63
+ * Default sequence executes these steps
64
+ * - Executes middleware for CORS, OpenAPI spec endpoints
65
+ * - Finds the appropriate controller method, swagger spec
66
+ * and args for invocation
67
+ * - Parses HTTP request to get API argument list
68
+ * - Invokes the API which is defined in the Application Controller
69
+ * - Writes the result from API into the HTTP response
70
+ * - Error is caught and logged using 'logError' if any of the above steps
71
+ * in the sequence fails with an error.
72
+ *
73
+ * @param context - The request context: HTTP request and response objects,
74
+ * per-request IoC container and more.
75
+ */
76
+ async handle(context) {
77
+ try {
78
+ const { request, response } = context;
79
+ // Invoke registered Express middleware
80
+ const finished = await this.invokeMiddleware(context);
81
+ if (finished) {
82
+ // The response been produced by the middleware chain
83
+ return;
94
84
  }
85
+ const route = this.findRoute(request);
86
+ const args = await this.parseParams(request, route);
87
+ const result = await this.invoke(route, args);
88
+ debug('%s result -', route.describe(), result);
89
+ this.send(response, result);
90
+ }
91
+ catch (error) {
92
+ this.reject(context, error);
95
93
  }
96
- };
97
- tslib_1.__decorate([
98
- context_1.inject(SequenceActions.INVOKE_MIDDLEWARE, { optional: true }),
99
- tslib_1.__metadata("design:type", Function)
100
- ], DefaultSequence.prototype, "invokeMiddleware", void 0);
101
- DefaultSequence = tslib_1.__decorate([
102
- tslib_1.__param(0, context_1.inject(SequenceActions.FIND_ROUTE)),
103
- tslib_1.__param(1, context_1.inject(SequenceActions.PARSE_PARAMS)),
104
- tslib_1.__param(2, context_1.inject(SequenceActions.INVOKE_METHOD)),
105
- tslib_1.__param(3, context_1.inject(SequenceActions.SEND)),
106
- tslib_1.__param(4, context_1.inject(SequenceActions.REJECT)),
107
- tslib_1.__metadata("design:paramtypes", [Function, Function, Function, Function, Function])
108
- ], DefaultSequence);
109
- return DefaultSequence;
110
- })();
94
+ }
95
+ };
96
+ tslib_1.__decorate([
97
+ core_1.inject(SequenceActions.INVOKE_MIDDLEWARE, { optional: true }),
98
+ tslib_1.__metadata("design:type", Function)
99
+ ], DefaultSequence.prototype, "invokeMiddleware", void 0);
100
+ DefaultSequence = tslib_1.__decorate([
101
+ tslib_1.__param(0, core_1.inject(SequenceActions.FIND_ROUTE)),
102
+ tslib_1.__param(1, core_1.inject(SequenceActions.PARSE_PARAMS)),
103
+ tslib_1.__param(2, core_1.inject(SequenceActions.INVOKE_METHOD)),
104
+ tslib_1.__param(3, core_1.inject(SequenceActions.SEND)),
105
+ tslib_1.__param(4, core_1.inject(SequenceActions.REJECT)),
106
+ tslib_1.__metadata("design:paramtypes", [Function, Function, Function, Function, Function])
107
+ ], DefaultSequence);
111
108
  exports.DefaultSequence = DefaultSequence;
112
109
  //# sourceMappingURL=sequence.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sequence.js","sourceRoot":"","sources":["../src/sequence.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,wBAAwB,CAAC,CAAC;AACzD,+CAAyD;AAEzD,iCAAoC;AAIpC,MAAM,eAAe,GAAG,mBAAY,CAAC,eAAe,CAAC;AAyBrD;;;;;;;;;;;;;;;;;GAiBG;AACH;IAAA,IAAa,eAAe,GAA5B,MAAa,eAAe;QAQ1B;;;;;;;;;;;;;;WAcG;QACH,YACgD,SAAoB,EAClB,WAAwB,EACvB,MAAoB,EAChC,IAAU,EACR,MAAc;YAJP,cAAS,GAAT,SAAS,CAAW;YAClB,gBAAW,GAAX,WAAW,CAAa;YACvB,WAAM,GAAN,MAAM,CAAc;YAChC,SAAI,GAAJ,IAAI,CAAM;YACR,WAAM,GAAN,MAAM,CAAQ;YA3BvD;;;eAGG;YAEO,qBAAgB,GAAqB,GAAG,EAAE,CAAC,KAAK,CAAC;QAuBxD,CAAC;QAEJ;;;;;;;;;;;;;;;;WAgBG;QACH,KAAK,CAAC,MAAM,CAAC,OAAuB;YAClC,IAAI;gBACF,MAAM,EAAC,OAAO,EAAE,QAAQ,EAAC,GAAG,OAAO,CAAC;gBACpC,uCAAuC;gBACvC,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;gBACtD,IAAI,QAAQ,EAAE;oBACZ,qDAAqD;oBACrD,OAAO;iBACR;gBACD,MAAM,KAAK,GAAG,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC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yDACD;AANhD,eAAe;IAwBvB,mBAAA,aAAM,CAAC,eAAe,CAAC,UAAU,CAAC,CAAA;IAClC,mBAAA,aAAM,CAAC,eAAe,CAAC,YAAY,CAAC,CAAA;IACpC,mBAAA,aAAM,CAAC,eAAe,CAAC,aAAa,CAAC,CAAA;IACrC,mBAAA,aAAM,CAAC,eAAe,CAAC,IAAI,CAAC,CAAA;IAC5B,mBAAA,aAAM,CAAC,eAAe,CAAC,MAAM,CAAC,CAAA;;GA5BtB,eAAe,CAmE3B;AAnEY,0CAAe"}
@@ -45,101 +45,98 @@ const debug = debug_1.default('loopback:openapi:spec-enhancer:consolidate');
45
45
  * When comparing schemas to avoid naming collisions, the description field
46
46
  * is ignored.
47
47
  */
48
- let ConsolidationEnhancer = /** @class */ (() => {
49
- let ConsolidationEnhancer = class ConsolidationEnhancer {
50
- constructor(config) {
51
- var _a, _b, _c;
52
- this.config = config;
53
- this.name = 'consolidate';
54
- this.disabled = ((_c = (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.rest) === null || _b === void 0 ? void 0 : _b.openApiSpec) === null || _c === void 0 ? void 0 : _c.consolidate) === false;
55
- }
56
- modifySpec(spec) {
57
- return !this.disabled ? this.consolidateSchemaObjects(spec) : spec;
58
- }
59
- /**
60
- * Recursively search OpenApiSpec PathsObject for SchemaObjects with title
61
- * property. Moves reusable schema bodies to #/components/schemas and replace
62
- * with json pointer. It handles title collisions with schema body comparision.
63
- */
64
- consolidateSchemaObjects(spec) {
65
- // use 'paths' as crawl root
66
- this.recursiveWalk(spec.paths, ['paths'], spec);
67
- return spec;
48
+ let ConsolidationEnhancer = class ConsolidationEnhancer {
49
+ constructor(config) {
50
+ var _a, _b, _c;
51
+ this.config = config;
52
+ this.name = 'consolidate';
53
+ this.disabled = ((_c = (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.rest) === null || _b === void 0 ? void 0 : _b.openApiSpec) === null || _c === void 0 ? void 0 : _c.consolidate) === false;
54
+ }
55
+ modifySpec(spec) {
56
+ return !this.disabled ? this.consolidateSchemaObjects(spec) : spec;
57
+ }
58
+ /**
59
+ * Recursively search OpenApiSpec PathsObject for SchemaObjects with title
60
+ * property. Moves reusable schema bodies to #/components/schemas and replace
61
+ * with json pointer. It handles title collisions with schema body comparision.
62
+ */
63
+ consolidateSchemaObjects(spec) {
64
+ // use 'paths' as crawl root
65
+ this.recursiveWalk(spec.paths, ['paths'], spec);
66
+ return spec;
67
+ }
68
+ recursiveWalk(rootSchema, parentPath, spec) {
69
+ if (this.isTraversable(rootSchema)) {
70
+ Object.entries(rootSchema).forEach(([key, subSchema]) => {
71
+ if (subSchema) {
72
+ this.recursiveWalk(subSchema, parentPath.concat(key), spec);
73
+ this.processSchema(subSchema, parentPath.concat(key), spec);
74
+ }
75
+ });
68
76
  }
69
- recursiveWalk(rootSchema, parentPath, spec) {
70
- if (this.isTraversable(rootSchema)) {
71
- Object.entries(rootSchema).forEach(([key, subSchema]) => {
72
- if (subSchema) {
73
- this.recursiveWalk(subSchema, parentPath.concat(key), spec);
74
- this.processSchema(subSchema, parentPath.concat(key), spec);
75
- }
76
- });
77
+ }
78
+ /**
79
+ * Carry out schema consolidation after tree traversal. If 'title' property
80
+ * set then we consider current schema for consolidation. SchemaObjects with
81
+ * properties (and title set) are moved to #/components/schemas/<title> and
82
+ * replaced with ReferenceObject.
83
+ *
84
+ * Features:
85
+ * - name collision protection
86
+ *
87
+ * @param schema - current schema element to process
88
+ * @param parentPath - path object to parent
89
+ * @param spec - subject OpenApi specification
90
+ */
91
+ processSchema(schema, parentPath, spec) {
92
+ const schemaObj = this.ifConsolidationCandidate(schema);
93
+ if (schemaObj) {
94
+ // name collison protection
95
+ let instanceNo = 1;
96
+ let title = schemaObj.title;
97
+ let refSchema = this.getRefSchema(title, spec);
98
+ while (refSchema &&
99
+ !json_schema_compare_1.default(schemaObj, refSchema, {
100
+ ignore: ['description'],
101
+ })) {
102
+ title = `${schemaObj.title}${instanceNo++}`;
103
+ refSchema = this.getRefSchema(title, spec);
77
104
  }
78
- }
79
- /**
80
- * Carry out schema consolidation after tree traversal. If 'title' property
81
- * set then we consider current schema for consolidation. SchemaObjects with
82
- * properties (and title set) are moved to #/components/schemas/<title> and
83
- * replaced with ReferenceObject.
84
- *
85
- * Features:
86
- * - name collision protection
87
- *
88
- * @param schema - current schema element to process
89
- * @param parentPath - path object to parent
90
- * @param spec - subject OpenApi specification
91
- */
92
- processSchema(schema, parentPath, spec) {
93
- const schemaObj = this.ifConsolidationCandidate(schema);
94
- if (schemaObj) {
95
- // name collison protection
96
- let instanceNo = 1;
97
- let title = schemaObj.title;
98
- let refSchema = this.getRefSchema(title, spec);
99
- while (refSchema &&
100
- !json_schema_compare_1.default(schemaObj, refSchema, {
101
- ignore: ['description'],
102
- })) {
103
- title = `${schemaObj.title}${instanceNo++}`;
104
- refSchema = this.getRefSchema(title, spec);
105
- }
106
- if (!refSchema) {
107
- debug('Creating new component $ref with schema %j', schema);
108
- this.patchRef(title, schema, spec);
109
- }
110
- debug('Creating link to $ref %j', title);
111
- this.patchPath(title, parentPath, spec);
105
+ if (!refSchema) {
106
+ debug('Creating new component $ref with schema %j', schema);
107
+ this.patchRef(title, schema, spec);
112
108
  }
109
+ debug('Creating link to $ref %j', title);
110
+ this.patchPath(title, parentPath, spec);
113
111
  }
114
- getRefSchema(name, spec) {
115
- const schema = lodash_1.default.get(spec, ['components', 'schemas', name]);
116
- return schema;
117
- }
118
- patchRef(name, value, spec) {
119
- lodash_1.default.set(spec, ['components', 'schemas', name], value);
120
- }
121
- patchPath(name, path, spec) {
122
- const patch = {
123
- $ref: `#/components/schemas/${name}`,
124
- };
125
- lodash_1.default.set(spec, path, patch);
126
- }
127
- ifConsolidationCandidate(schema) {
128
- // use title to discriminate references
129
- return openapi_v3_1.isSchemaObject(schema) && schema.properties && schema.title
130
- ? schema
131
- : undefined;
132
- }
133
- isTraversable(schema) {
134
- return schema && typeof schema === 'object' ? true : false;
135
- }
136
- };
137
- ConsolidationEnhancer = tslib_1.__decorate([
138
- core_1.bind(openapi_v3_1.asSpecEnhancer, { scope: core_1.BindingScope.SINGLETON }),
139
- tslib_1.__param(0, core_1.inject(core_1.CoreBindings.APPLICATION_CONFIG, { optional: true })),
140
- tslib_1.__metadata("design:paramtypes", [Object])
141
- ], ConsolidationEnhancer);
142
- return ConsolidationEnhancer;
143
- })();
112
+ }
113
+ getRefSchema(name, spec) {
114
+ const schema = lodash_1.default.get(spec, ['components', 'schemas', name]);
115
+ return schema;
116
+ }
117
+ patchRef(name, value, spec) {
118
+ lodash_1.default.set(spec, ['components', 'schemas', name], value);
119
+ }
120
+ patchPath(name, path, spec) {
121
+ const patch = {
122
+ $ref: `#/components/schemas/${name}`,
123
+ };
124
+ lodash_1.default.set(spec, path, patch);
125
+ }
126
+ ifConsolidationCandidate(schema) {
127
+ // use title to discriminate references
128
+ return openapi_v3_1.isSchemaObject(schema) && schema.properties && schema.title
129
+ ? schema
130
+ : undefined;
131
+ }
132
+ isTraversable(schema) {
133
+ return schema && typeof schema === 'object' ? true : false;
134
+ }
135
+ };
136
+ ConsolidationEnhancer = tslib_1.__decorate([
137
+ core_1.bind(openapi_v3_1.asSpecEnhancer, { scope: core_1.BindingScope.SINGLETON }),
138
+ tslib_1.__param(0, core_1.inject(core_1.CoreBindings.APPLICATION_CONFIG, { optional: true })),
139
+ tslib_1.__metadata("design:paramtypes", [Object])
140
+ ], ConsolidationEnhancer);
144
141
  exports.ConsolidationEnhancer = ConsolidationEnhancer;
145
142
  //# sourceMappingURL=consolidate.spec-enhancer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"consolidate.spec-enhancer.js","sourceRoot":"","sources":["../../src/spec-enhancers/consolidate.spec-enhancer.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,yCAMwB;AACxB,qDAQ8B;AAC9B,0DAAiC;AACjC,sFAA0C;AAC1C,4DAAuB;AAEvB,MAAM,KAAK,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I,EAAE;SACrC,CAAC;QACF,gBAAC,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;IAC3B,CAAC;IAEO,wBAAwB,CAC9B,MAAsC;QAEtC,uCAAuC;QACvC,OAAO,2BAAc,CAAC,MAAM,CAAC,IAAI,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,KAAK;YAChE,CAAC,CAAC,MAAM;YACR,CAAC,CAAC,SAAS,CAAC;IAChB,CAAC;IAEO,aAAa,CAAC,MAA+B;QACnD,OAAO,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC;IAC7D,CAAC;CACF,CAAA;AAxHY,qBAAqB;IADjC,WAAI,CAAC,2BAAc,EAAE,EAAC,KAAK,EAAE,mBAAY,CAAC,SAAS,EAAC,CAAC;IAMjD,mBAAA,aAAM,CAAC,mBAAY,CAAC,kBAAkB,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAA;;GALjD,qBAAqB,CAwHjC;AAxHY,sDAAqB"}
@@ -3,10 +3,10 @@
3
3
  // Node module: @loopback/rest
4
4
  // This file is licensed under the MIT License.
5
5
  // License text available at https://opensource.org/licenses/MIT
6
+ var InfoSpecEnhancer_1;
6
7
  Object.defineProperty(exports, "__esModule", { value: true });
7
8
  exports.InfoSpecEnhancer = void 0;
8
9
  const tslib_1 = require("tslib");
9
- const context_1 = require("@loopback/context");
10
10
  const core_1 = require("@loopback/core");
11
11
  const openapi_v3_1 = require("@loopback/openapi-v3");
12
12
  const debug_1 = tslib_1.__importDefault(require("debug"));
@@ -15,75 +15,71 @@ const debug = debug_1.default('loopback:openapi:spec-enhancer:info');
15
15
  * An OpenAPI spec enhancer to populate `info` with application metadata
16
16
  * (package.json).
17
17
  */
18
- let InfoSpecEnhancer = /** @class */ (() => {
19
- var InfoSpecEnhancer_1;
20
- let InfoSpecEnhancer = InfoSpecEnhancer_1 = class InfoSpecEnhancer {
21
- constructor(pkg) {
22
- this.pkg = pkg;
23
- this.name = 'info';
18
+ let InfoSpecEnhancer = InfoSpecEnhancer_1 = class InfoSpecEnhancer {
19
+ constructor(pkg) {
20
+ this.pkg = pkg;
21
+ this.name = 'info';
22
+ }
23
+ modifySpec(spec) {
24
+ if (this.pkg == null) {
25
+ debug('Application metadata is not found. Skipping spec enhancing.');
26
+ return spec;
24
27
  }
25
- modifySpec(spec) {
26
- if (this.pkg == null) {
27
- debug('Application metadata is not found. Skipping spec enhancing.');
28
- return spec;
29
- }
30
- const contact = InfoSpecEnhancer_1.parseAuthor(this.pkg.author);
31
- const patchSpec = {
32
- info: {
33
- title: this.pkg.name,
34
- description: this.pkg.description,
35
- version: this.pkg.version,
36
- contact,
37
- },
28
+ const contact = InfoSpecEnhancer_1.parseAuthor(this.pkg.author);
29
+ const patchSpec = {
30
+ info: {
31
+ title: this.pkg.name,
32
+ description: this.pkg.description,
33
+ version: this.pkg.version,
34
+ contact,
35
+ },
36
+ };
37
+ debug('Enhancing OpenAPI spec with %j', patchSpec);
38
+ return openapi_v3_1.mergeOpenAPISpec(spec, patchSpec);
39
+ }
40
+ /**
41
+ * Parse package.json
42
+ * {@link https://docs.npmjs.com/files/package.json#people-fields-author-contributors | author}
43
+ *
44
+ * @param author - Author string or object from package.json
45
+ */
46
+ static parseAuthor(author) {
47
+ var _a, _b, _c, _d, _e, _f;
48
+ let contact = {};
49
+ if (author == null) {
50
+ contact = {};
51
+ }
52
+ else if (typeof author === 'string') {
53
+ // "Barney Rubble <b@rubble.com> (http://barnyrubble.tumblr.com/)"
54
+ const emailRegex = /<([^<>]+)>/; // <email>
55
+ const urlRegex = /\(([^()]+)\)/; // (url)
56
+ const nameRegex = /([^<>()]+)/;
57
+ contact = {
58
+ name: (_b = (_a = nameRegex.exec(author)) === null || _a === void 0 ? void 0 : _a[1]) === null || _b === void 0 ? void 0 : _b.trim(),
59
+ email: (_d = (_c = emailRegex.exec(author)) === null || _c === void 0 ? void 0 : _c[1]) === null || _d === void 0 ? void 0 : _d.trim(),
60
+ url: (_f = (_e = urlRegex.exec(author)) === null || _e === void 0 ? void 0 : _e[1]) === null || _f === void 0 ? void 0 : _f.trim(),
61
+ };
62
+ }
63
+ else if (typeof author === 'object') {
64
+ const authorObj = author;
65
+ contact = {
66
+ name: authorObj.name,
67
+ email: authorObj.email,
68
+ url: authorObj.url,
38
69
  };
39
- debug('Enhancing OpenAPI spec with %j', patchSpec);
40
- return openapi_v3_1.mergeOpenAPISpec(spec, patchSpec);
41
70
  }
42
- /**
43
- * Parse package.json
44
- * {@link https://docs.npmjs.com/files/package.json#people-fields-author-contributors | author}
45
- *
46
- * @param author - Author string or object from package.json
47
- */
48
- static parseAuthor(author) {
49
- var _a, _b, _c, _d, _e, _f;
50
- let contact = {};
51
- if (author == null) {
52
- contact = {};
53
- }
54
- else if (typeof author === 'string') {
55
- // "Barney Rubble <b@rubble.com> (http://barnyrubble.tumblr.com/)"
56
- const emailRegex = /<([^<>]+)>/; // <email>
57
- const urlRegex = /\(([^()]+)\)/; // (url)
58
- const nameRegex = /([^<>()]+)/;
59
- contact = {
60
- name: (_b = (_a = nameRegex.exec(author)) === null || _a === void 0 ? void 0 : _a[1]) === null || _b === void 0 ? void 0 : _b.trim(),
61
- email: (_d = (_c = emailRegex.exec(author)) === null || _c === void 0 ? void 0 : _c[1]) === null || _d === void 0 ? void 0 : _d.trim(),
62
- url: (_f = (_e = urlRegex.exec(author)) === null || _e === void 0 ? void 0 : _e[1]) === null || _f === void 0 ? void 0 : _f.trim(),
63
- };
64
- }
65
- else if (typeof author === 'object') {
66
- const authorObj = author;
67
- contact = {
68
- name: authorObj.name,
69
- email: authorObj.email,
70
- url: authorObj.url,
71
- };
72
- }
73
- // Remove undefined/null values
74
- for (const p in contact) {
75
- if (contact[p] == null)
76
- delete contact[p];
77
- }
78
- return contact;
71
+ // Remove undefined/null values
72
+ for (const p in contact) {
73
+ if (contact[p] == null)
74
+ delete contact[p];
79
75
  }
80
- };
81
- InfoSpecEnhancer = InfoSpecEnhancer_1 = tslib_1.__decorate([
82
- context_1.bind(openapi_v3_1.asSpecEnhancer, { scope: context_1.BindingScope.SINGLETON }),
83
- tslib_1.__param(0, context_1.inject(core_1.CoreBindings.APPLICATION_METADATA, { optional: true })),
84
- tslib_1.__metadata("design:paramtypes", [Object])
85
- ], InfoSpecEnhancer);
86
- return InfoSpecEnhancer;
87
- })();
76
+ return contact;
77
+ }
78
+ };
79
+ InfoSpecEnhancer = InfoSpecEnhancer_1 = tslib_1.__decorate([
80
+ core_1.bind(openapi_v3_1.asSpecEnhancer, { scope: core_1.BindingScope.SINGLETON }),
81
+ tslib_1.__param(0, core_1.inject(core_1.CoreBindings.APPLICATION_METADATA, { optional: true })),
82
+ tslib_1.__metadata("design:paramtypes", [Object])
83
+ ], InfoSpecEnhancer);
88
84
  exports.InfoSpecEnhancer = InfoSpecEnhancer;
89
85
  //# sourceMappingURL=info.spec-enhancer.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"info.spec-enhancer.js","sourceRoot":"","sources":["../../src/spec-enhancers/info.spec-enhancer.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,+CAM2B;AAC3B,yCAAiE;AACjE,qDAM8B;AAC9B,0DAAiC;AAEjC,MAAM,KAAK,GAAG,eAAY,CAAC,qCAAqC,CAAC,CAAC;AAElE;;;GAGG;AAEH;;IAAA,IAAa,gBAAgB,wBAA7B,MAAa,gBAAgB;QAG3B,YAEW,GAAyB;YAAzB,QAAG,GAAH,GAAG,CAAsB;YAJpC,SAAI,GAAG,MAAM,CAAC;QAKX,CAAC;QAEJ,UAAU,CAAC,IAAiB;YAC1B,IAAI,IAAI,CAAC,GAAG,IAAI,IAAI,EAAE;gBACpB,KAAK,CAAC,6DAA6D,CAAC,CAAC;gBACrE,OAAO,IAAI,CAAC;aACb;YACD,MAAM,OAAO,GAAkB,kBAAg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,IAAI,OAAO,CAAC,CAAC,CAAC,IAAI,IAAI;gBAAE,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;SAC3C;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;CACF,CAAA;AA9DY,gBAAgB;IAD5B,WAAI,CAAC,2BAAc,EAAE,EAAC,KAAK,EAAE,mBAAY,CAAC,SAAS,EAAC,CAAC;IAKjD,mBAAA,aAAM,CAAC,mBAAY,CAAC,oBAAoB,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAA;;GAJnD,gBAAgB,CA8D5B;AA9DY,4CAAgB"}
package/dist/types.d.ts CHANGED
@@ -77,6 +77,16 @@ export declare type AjvKeyword = KeywordDefinition & {
77
77
  export declare type AjvFormat = FormatDefinition & {
78
78
  name: string;
79
79
  };
80
+ /**
81
+ * Options for any value validation using AJV
82
+ */
83
+ export interface ValueValidationOptions extends RequestBodyValidationOptions {
84
+ /**
85
+ * Where the data comes from. It can be 'body', 'path', 'header',
86
+ * 'query', 'cookie', etc...
87
+ */
88
+ source?: string;
89
+ }
80
90
  /**
81
91
  * Options for request body validation using AJV
82
92
  */