UNPKG

1.53 kBJavaScriptView Raw
1"use strict";
2// Copyright IBM Corp. and LoopBack contributors 2019. All Rights Reserved.
3// Node module: @loopback/rest
4// This file is licensed under the MIT License.
5// License text available at https://opensource.org/licenses/MIT
6Object.defineProperty(exports, "__esModule", { value: true });
7exports.assignRouterSpec = void 0;
8function assignRouterSpec(target, additions) {
9 if (additions.components) {
10 if (!target.components)
11 target.components = {};
12 for (const key in additions.components) {
13 if (!target.components[key])
14 target.components[key] = {};
15 Object.assign(target.components[key], additions.components[key]);
16 }
17 }
18 for (const url in additions.paths) {
19 if (!(url in target.paths))
20 target.paths[url] = {};
21 for (const verbOrKey in additions.paths[url]) {
22 // routes registered earlier takes precedence
23 if (verbOrKey in target.paths[url])
24 continue;
25 target.paths[url][verbOrKey] = additions.paths[url][verbOrKey];
26 }
27 }
28 if (additions.tags && additions.tags.length > 0) {
29 if (!target.tags)
30 target.tags = [];
31 for (const tag of additions.tags) {
32 // tags defined earlier take precedence
33 if (target.tags.some(t => t.name === tag.name))
34 continue;
35 target.tags.push(tag);
36 }
37 }
38}
39exports.assignRouterSpec = assignRouterSpec;
40//# sourceMappingURL=router-spec.js.map
\No newline at end of file