Files
yamadashy--repomix/tests/website/normalizeJsonSchema.test.ts
wehub-resource-sync 719032b19f
Update Schema / Update configuration json schema (push) Has been cancelled
Memory Benchmark / Memory Test (Full Analysis) (push) Has been cancelled
CI Quality / Lint GitHub Actions (actionlint) (push) Has been cancelled
CI Quality / Lint GitHub Actions (zizmor) (push) Has been cancelled
CI Quality / Check typos (push) Has been cancelled
CI / Test coverage (push) Has been cancelled
CI / Test (22.x, windows-latest) (push) Has been cancelled
CI / Test (24.x, macos-latest) (push) Has been cancelled
CI / Test (24.x, ubuntu-latest) (push) Has been cancelled
CI / Test (24.x, windows-latest) (push) Has been cancelled
CI / Test (26.x, macos-latest) (push) Has been cancelled
CI / Test (26.x, ubuntu-latest) (push) Has been cancelled
CI / Test (26.x, windows-latest) (push) Has been cancelled
CI / Test with Bun (latest, macos-latest) (push) Has been cancelled
CI / Test with Bun (latest, ubuntu-latest) (push) Has been cancelled
CI / Test with Bun (latest, windows-latest) (push) Has been cancelled
CI / Build and run (22.x, macos-latest) (push) Has been cancelled
CI / Build and run (22.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (22.x, windows-latest) (push) Has been cancelled
autofix.ci / autofix (push) Has been cancelled
CI Browser Extension / Lint Browser Extension (push) Has been cancelled
CI Browser Extension / Test Browser Extension (push) Has been cancelled
Memory Benchmark / Memory Test (push) Has been cancelled
CI Website / Lint Website Client (push) Has been cancelled
CI Website / Lint Website Server (push) Has been cancelled
CI Website / Test Website Server (push) Has been cancelled
CI Website / Bundle Website Server (push) Has been cancelled
CI / Lint Biome (push) Has been cancelled
CI / Lint oxlint (push) Has been cancelled
CI / Lint TypeScript (push) Has been cancelled
CI / Lint Secretlint (push) Has been cancelled
CI / Test (22.x, macos-latest) (push) Has been cancelled
CI / Test (22.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (24.x, macos-latest) (push) Has been cancelled
CI / Build and run (24.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (24.x, windows-latest) (push) Has been cancelled
CI / Build and run (26.x, macos-latest) (push) Has been cancelled
CI / Build and run (26.x, ubuntu-latest) (push) Has been cancelled
CI / Build and run (26.x, windows-latest) (push) Has been cancelled
CI / Build and run with Bun (latest, macos-latest) (push) Has been cancelled
CI / Build and run with Bun (latest, ubuntu-latest) (push) Has been cancelled
CI / Build and run with Bun (latest, windows-latest) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
Docker / build (linux/amd64, ubuntu-latest) (push) Has been cancelled
Docker / build (linux/arm/v7, ubuntu-24.04-arm) (push) Has been cancelled
Docker / build (linux/arm64, ubuntu-24.04-arm) (push) Has been cancelled
Docker / merge (push) Has been cancelled
Pack repository with Repomix / pack-repo (push) Has been cancelled
Performance Benchmark History / Benchmark (macos-latest) (push) Has been cancelled
Performance Benchmark History / Benchmark (ubuntu-latest) (push) Has been cancelled
Performance Benchmark History / Benchmark (windows-latest) (push) Has been cancelled
Performance Benchmark History / Store Results (push) Has been cancelled
Test Repomix Action / Test Node.js 22 (push) Has been cancelled
Test Repomix Action / Test Node.js 24 (push) Has been cancelled
Test Repomix Action / Test Node.js 26 (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:39:37 +08:00

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);
});
});