Skip to content

Commit

Permalink
fix: update script
Browse files Browse the repository at this point in the history
Changes:
- update script to match the json_pointer object
- add check for the root doc
  • Loading branch information
AnimeshKumar923 committed Jun 20, 2024
1 parent cc79163 commit 13d56c7
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions scripts/validation/embedded-examples-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function extractCommentsAndExamples(content) {

combinedData.push({
name: json.name,
json_path: json.json_path,
json_pointer: json.json_pointer,
example: example,
format: format,
});
Expand All @@ -51,17 +51,17 @@ const combinedData = extractCommentsAndExamples(markdownContent);
function applyUpdates(updates, baseDoc) {
updates.forEach(update => {
try {
if (update.json_path === "$") {
if (update.json_pointer === "") {
// Apply patch directly at the root
baseDoc = mergePatch.apply(baseDoc, update.example);
} else {
// Apply patch at a specified JSON Pointer path
const targetObject = jsonpointer.get(baseDoc, update.json_path);
const targetObject = jsonpointer.get(baseDoc, update.json_pointer);
const patchedObject = mergePatch.apply(targetObject || {}, update.example);
jsonpointer.set(baseDoc, update.json_path, patchedObject);
jsonpointer.set(baseDoc, update.json_pointer, patchedObject);
}
} catch (e) {
console.error(`\nError processing update for '${update.name}' at path '${update.json_path}'`, e);
console.error(`\nError processing update for '${update.name}' at path '${update.json_pointer}'`, e);
// process.exit(1);
}
});
Expand Down

0 comments on commit 13d56c7

Please sign in to comment.