MCPcopy Create free account
hub / github.com/loopbackio/loopback-next / assignRouterSpec

Function assignRouterSpec

packages/rest/src/router/router-spec.ts:10–36  ·  view source on GitHub ↗
(target: RouterSpec, additions: RouterSpec)

Source from the content-addressed store, hash-verified

8export type RouterSpec = Pick<OpenApiSpec, 'paths' | 'components' | 'tags'>;
9
10export function assignRouterSpec(target: RouterSpec, additions: RouterSpec) {
11 if (additions.components) {
12 if (!target.components) target.components = {};
13 for (const key in additions.components) {
14 if (!target.components[key]) target.components[key] = {};
15 Object.assign(target.components[key], additions.components[key]);
16 }
17 }
18
19 for (const url in additions.paths) {
20 if (!(url in target.paths)) target.paths[url] = {};
21 for (const verbOrKey in additions.paths[url]) {
22 // routes registered earlier takes precedence
23 if (verbOrKey in target.paths[url]) continue;
24 target.paths[url][verbOrKey] = additions.paths[url][verbOrKey];
25 }
26 }
27
28 if (additions.tags && additions.tags.length > 0) {
29 if (!target.tags) target.tags = [];
30 for (const tag of additions.tags) {
31 // tags defined earlier take precedence
32 if (target.tags.some(t => t.name === tag.name)) continue;
33 target.tags.push(tag);
34 }
35 }
36}

Callers 3

getApiSpecMethod · 0.90
mountRouterMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected