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
94 lines
2.9 KiB
TypeScript
94 lines
2.9 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { normalizeObjectNode } from '../../website/client/scripts/normalizeJsonSchema.js';
|
|
|
|
describe('normalizeObjectNode', () => {
|
|
it('adds additionalProperties: false to object nodes with properties', () => {
|
|
const schema = {
|
|
type: 'object',
|
|
properties: { foo: { type: 'string' } },
|
|
};
|
|
normalizeObjectNode(schema);
|
|
expect((schema as Record<string, unknown>).additionalProperties).toBe(false);
|
|
});
|
|
|
|
it('strips empty required arrays from object nodes', () => {
|
|
const schema = {
|
|
type: 'object',
|
|
properties: { foo: { type: 'string' } },
|
|
required: [] as string[],
|
|
};
|
|
normalizeObjectNode(schema);
|
|
expect('required' in schema).toBe(false);
|
|
});
|
|
|
|
it('preserves non-empty required arrays', () => {
|
|
const schema = {
|
|
type: 'object',
|
|
properties: { foo: { type: 'string' } },
|
|
required: ['foo'],
|
|
};
|
|
normalizeObjectNode(schema);
|
|
expect(schema.required).toEqual(['foo']);
|
|
});
|
|
|
|
it('does not override an explicitly-set additionalProperties', () => {
|
|
const schema = {
|
|
type: 'object',
|
|
properties: { foo: { type: 'string' } },
|
|
additionalProperties: true,
|
|
};
|
|
normalizeObjectNode(schema);
|
|
expect(schema.additionalProperties).toBe(true);
|
|
});
|
|
|
|
it('recurses into nested properties, anyOf, oneOf, and items', () => {
|
|
const schema = {
|
|
type: 'object',
|
|
properties: {
|
|
nested: {
|
|
type: 'object',
|
|
properties: { bar: { type: 'number' } },
|
|
required: [] as string[],
|
|
},
|
|
union: {
|
|
anyOf: [
|
|
{ type: 'object', properties: { a: { type: 'string' } } },
|
|
{ type: 'object', properties: { b: { type: 'string' } } },
|
|
],
|
|
},
|
|
list: {
|
|
type: 'array',
|
|
items: {
|
|
type: 'object',
|
|
properties: { c: { type: 'string' } },
|
|
},
|
|
},
|
|
},
|
|
};
|
|
normalizeObjectNode(schema);
|
|
|
|
const nested = schema.properties.nested as Record<string, unknown>;
|
|
expect(nested.additionalProperties).toBe(false);
|
|
expect('required' in nested).toBe(false);
|
|
|
|
for (const branch of schema.properties.union.anyOf) {
|
|
expect((branch as Record<string, unknown>).additionalProperties).toBe(false);
|
|
}
|
|
|
|
const items = schema.properties.list.items as Record<string, unknown>;
|
|
expect(items.additionalProperties).toBe(false);
|
|
});
|
|
|
|
it('skips non-object nodes (primitives, null)', () => {
|
|
expect(() => normalizeObjectNode(null)).not.toThrow();
|
|
expect(() => normalizeObjectNode('string')).not.toThrow();
|
|
expect(() => normalizeObjectNode(42)).not.toThrow();
|
|
});
|
|
|
|
it('does not add additionalProperties to object nodes without properties', () => {
|
|
const schema = { type: 'object' };
|
|
normalizeObjectNode(schema);
|
|
expect('additionalProperties' in schema).toBe(false);
|
|
});
|
|
});
|