(target: RouterSpec, additions: RouterSpec)
| 8 | export type RouterSpec = Pick<OpenApiSpec, 'paths' | 'components' | 'tags'>; |
| 9 | |
| 10 | export 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 | } |
no outgoing calls
no test coverage detected