mirror of
https://github.com/yamadashy/repomix.git
synced 2026-05-30 11:18:53 +02:00
53ddb5ac36
intent(test-coverage): normalizeObjectNode is the load-bearing workaround for @valibot/to-json-schema's output gaps (missing additionalProperties:false, noisy empty required arrays). A bug in its tree walk would silently break the published repomix.config.json IntelliSense schema. Extract to its own module and pin the behavior: adding/respecting additionalProperties, stripping empty required, recursing through properties / anyOf / oneOf / items, handling null and primitives
25 lines
1.0 KiB
TypeScript
25 lines
1.0 KiB
TypeScript
// @valibot/to-json-schema quirks:
|
|
// - Does not emit `additionalProperties: false` for `v.object`, even though
|
|
// Valibot strips unknown keys at runtime. We add it so editors flag typos.
|
|
// - Emits an empty `required: []` on every object node, which is valid but noisy.
|
|
// We strip empty arrays to match the previous zod-generated output.
|
|
// Mutates the tree in place — the caller passes the root schema and discards
|
|
// the return value.
|
|
export const normalizeObjectNode = (node: unknown): void => {
|
|
if (!node || typeof node !== 'object') return;
|
|
if (Array.isArray(node)) {
|
|
for (const item of node) normalizeObjectNode(item);
|
|
return;
|
|
}
|
|
const obj = node as Record<string, unknown>;
|
|
if (obj.type === 'object' && obj.properties && typeof obj.properties === 'object') {
|
|
if (!('additionalProperties' in obj)) {
|
|
obj.additionalProperties = false;
|
|
}
|
|
if (Array.isArray(obj.required) && obj.required.length === 0) {
|
|
delete obj.required;
|
|
}
|
|
}
|
|
for (const value of Object.values(obj)) normalizeObjectNode(value);
|
|
};
|