MCPcopy
hub / github.com/asyncapi/spec / applyUpdates

Function applyUpdates

scripts/validation/embedded-examples-validation.js:51–71  ·  view source on GitHub ↗
(updates, baseDoc)

Source from the content-addressed store, hash-verified

49
50// Function to apply JSON Merge Patch updates to the document
51function 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
74async function validateParser(document, name) {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…