(updates, baseDoc)
| 49 | |
| 50 | // Function to apply JSON Merge Patch updates to the document |
| 51 | function applyUpdates(updates, baseDoc) { |
| 52 | updates.forEach(update => { |
| 53 | try { |
| 54 | // Handle root document case |
| 55 | if (update.json_pointer === '') { |
| 56 | baseDoc = mergePatch.apply(baseDoc, update.example); |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | // For non-root cases, use jsonpointer to get and set the correct location |
| 61 | const targetObject = jsonpointer.get(baseDoc, update.json_pointer); |
| 62 | const updatedObject = mergePatch.apply(targetObject || {}, update.example); |
| 63 | jsonpointer.set(baseDoc, update.json_pointer, updatedObject); |
| 64 | |
| 65 | } catch (e) { |
| 66 | console.error(`\nError processing update for '${update.name}' at path '${update.json_pointer}'`, e); |
| 67 | process.exit(1); |
| 68 | } |
| 69 | }); |
| 70 | return baseDoc; |
| 71 | } |
| 72 | |
| 73 | // Function to validate a document using AsyncAPI parser |
| 74 | async function validateParser(document, name) { |
no outgoing calls
no test coverage detected
searching dependent graphs…