Skip to content

Commit 17c1028

Browse files
committed
remove
1 parent d64bf69 commit 17c1028

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

tools/proto-convert/src/utils/helper.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,27 @@ export function remove_unused(spec: OpenAPIV3.Document): void {
200200
}
201201
return false;
202202
});
203+
204+
// Clean up empty properties objects and oneOf/anyOf items left after removing broken refs
205+
deleteMatchingKeys(spec, (obj: any) => {
206+
// Remove oneOf/anyOf items with empty or missing properties (after broken refs removed)
207+
if (obj.properties !== undefined && obj.required !== undefined) {
208+
// Check if all properties are empty or removed
209+
const propKeys = Object.keys(obj.properties);
210+
if (propKeys.length === 0) {
211+
return true; // Remove this oneOf item entirely
212+
}
213+
// Check if properties only contain empty objects
214+
const hasValidProps = propKeys.some(k => {
215+
const prop = obj.properties[k];
216+
return prop && Object.keys(prop).length > 0;
217+
});
218+
if (!hasValidProps) {
219+
return true;
220+
}
221+
}
222+
return false;
223+
});
203224
}
204225

205226
/**

0 commit comments

Comments
 (0)