Skip to content

Commit 319ed73

Browse files
Omitting a few properties from being bundled.
Signed-off-by: Steve Springett <[email protected]>
1 parent 41ad354 commit 319ed73

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

tools/src/main/js/bundler/bundle-schemas.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,15 @@ function removeComments(obj, isRoot = false) {
151151
return newObj;
152152
}
153153

154+
function stripTopLevelKeys(obj, keysToRemove = []) {
155+
if (!isObject(obj)) return obj;
156+
const clone = { ...obj };
157+
for (const k of keysToRemove) {
158+
if (k in clone) delete clone[k];
159+
}
160+
return clone;
161+
}
162+
154163
async function bundleSchemas(modelsDirectory, rootSchemaPath, options = {}) {
155164
try {
156165
const absoluteModelsDir = path.resolve(modelsDirectory);
@@ -265,11 +274,18 @@ async function bundleSchemas(modelsDirectory, rootSchemaPath, options = {}) {
265274
// Get the rewritten root schema
266275
const rootSchemaRewritten = rewrittenDefinitions[rootSchemaName];
267276

277+
// Strip top-level metadata keys from each embedded definition ($defs)
278+
const keysToStripFromDefs = ['$schema', '$id', '$comment'];
279+
const cleanedDefinitions = {};
280+
for (const [defName, defSchema] of Object.entries(rewrittenDefinitions)) {
281+
cleanedDefinitions[defName] = stripTopLevelKeys(defSchema, keysToStripFromDefs);
282+
}
283+
268284
// Build the final schema with root schema properties at the top level
269285
const finalSchema = {
270286
...rootSchemaRewritten,
271287
"$schema": schemaVersion,
272-
[defsKeyword]: rewrittenDefinitions
288+
[defsKeyword]: cleanedDefinitions
273289
};
274290

275291
// Post-check: ensure all internal JSON Pointer refs resolve in the final bundle

0 commit comments

Comments
 (0)