in generator/generate.ts [275:294]
export async function clearAutoGeneratedSchemaRefs(autoGenList: AutoGenConfig[]) {
for (const [scopeType, rootSchemaConfig] of RootSchemaConfigs) {
const currentRefs = await getCurrentTemplateRefs(scopeType, rootSchemaConfig);
const autogenlistedFiles = new Set(autoGenList.map(x => getSchemaFileName(x.namespace, x.suffix).toLowerCase()));
const schemasToRemove = [];
const schemasByFilePath = groupBy(currentRefs, getFilePathFromRef);
// clean up existing schemas to detect deletions
for (const schemaFile of keys(schemasByFilePath)) {
const fileName = path.basename(schemaFile).toLowerCase();
if (autogenlistedFiles.has(fileName)) {
schemasToRemove.push(...schemasByFilePath[schemaFile]);
await safeUnlink(schemaFile);
}
}
const newRefs = difference(currentRefs, schemasToRemove);
const template = await readJsonFile(rootSchemaConfig.file);
set(template, rootSchemaConfig.jsonPath, newRefs.map(ref => ({ '$ref': ref })));
await writeJsonFile(rootSchemaConfig.file, template);
}
}