feat: добавить split-режим генерации REST-клиента

- добавлен режим генерации single, split и both
- добавлены отдельные operation-файлы и createApiClient
- удалена генерация SWR-хуков и зависимости React/SWR
- обновлены CLI, шаблоны, примеры, документация и тесты
- версия пакета повышена до 3.0.0
This commit is contained in:
2026-06-30 07:59:52 +03:00
parent 961c7f0ec1
commit bf340b3dbe
21 changed files with 1029 additions and 732 deletions

View File

@@ -28,11 +28,12 @@ describe('Generated Client', () => {
inputPath: FIXTURES.VALID,
outputPath,
fileName: 'TestApi',
mode: 'split',
};
await generate(config);
const generatedFile = join(outputPath, 'TestApi.ts');
const generatedFile = join(outputPath, 'index.ts');
// Пытаемся скомпилировать
const { exitCode } = await execa('bun', ['build', generatedFile, '--outdir', tempDir]);
@@ -46,11 +47,12 @@ describe('Generated Client', () => {
inputPath: FIXTURES.VALID,
outputPath,
fileName: 'TestApi',
mode: 'split',
};
await generate(config);
const generatedFile = join(outputPath, 'TestApi.ts');
const generatedFile = join(outputPath, 'index.ts');
// Проверяем с помощью TypeScript компилятора
const { exitCode, stderr } = await execa('bun', ['build', generatedFile, '--outdir', tempDir]);
@@ -65,16 +67,17 @@ describe('Generated Client', () => {
inputPath: FIXTURES.VALID,
outputPath,
fileName: 'TestApi',
mode: 'split',
};
await generate(config);
const generatedFile = join(outputPath, 'TestApi.ts');
const generatedFile = join(outputPath, 'index.ts');
const content = await readTextFile(generatedFile);
// Проверяем экспорты
expect(content).toContain('export');
expect(content).toContain('class');
expect(content).toContain('createApiClient');
}, 30000);
});
@@ -85,11 +88,12 @@ describe('Generated Client', () => {
inputPath: FIXTURES.VALID,
outputPath,
fileName: 'TestApi',
mode: 'split',
};
await generate(config);
const generatedFile = join(outputPath, 'TestApi.ts');
const generatedFile = join(outputPath, 'operations', 'index.ts');
const content = await readTextFile(generatedFile);
// Проверяем что все основные методы есть
@@ -97,7 +101,7 @@ describe('Generated Client', () => {
expect(content).toContain('create');
expect(content).toContain('getById');
expect(content).toContain('update');
expect(content).toContain('delete');
expect(content).toContain('deleteUsersId');
}, 30000);
test('корректные имена методов (без Controller префиксов)', async () => {
@@ -106,11 +110,12 @@ describe('Generated Client', () => {
inputPath: FIXTURES.VALID,
outputPath,
fileName: 'TestApi',
mode: 'split',
};
await generate(config);
const generatedFile = join(outputPath, 'TestApi.ts');
const generatedFile = join(outputPath, 'operations', 'index.ts');
const content = await readTextFile(generatedFile);
// Проверяем что "Controller" удален
@@ -128,11 +133,12 @@ describe('Generated Client', () => {
inputPath: FIXTURES.VALID,
outputPath,
fileName: 'TestApi',
mode: 'split',
};
await generate(config);
const generatedFile = join(outputPath, 'TestApi.ts');
const generatedFile = join(outputPath, 'http-client.ts');
const content = await readTextFile(generatedFile);
// Проверяем наличие HttpClient
@@ -148,11 +154,12 @@ describe('Generated Client', () => {
inputPath: FIXTURES.WITH_AUTH,
outputPath,
fileName: 'AuthApi',
mode: 'split',
};
await generate(config);
const generatedFile = join(outputPath, 'AuthApi.ts');
const generatedFile = join(outputPath, 'http-client.ts');
const content = await readTextFile(generatedFile);
// Проверяем наличие метода для установки токена
@@ -167,11 +174,12 @@ describe('Generated Client', () => {
inputPath: FIXTURES.MINIMAL,
outputPath,
fileName: 'MinimalApi',
mode: 'split',
};
await generate(config);
const generatedFile = join(outputPath, 'MinimalApi.ts');
const generatedFile = join(outputPath, 'index.ts');
const exists = await fileExists(generatedFile);
expect(exists).toBe(true);
@@ -186,11 +194,12 @@ describe('Generated Client', () => {
inputPath: FIXTURES.WITH_AUTH,
outputPath,
fileName: 'AuthApi',
mode: 'split',
};
await generate(config);
const generatedFile = join(outputPath, 'AuthApi.ts');
const generatedFile = join(outputPath, 'operations', 'index.ts');
const content = await readTextFile(generatedFile);
// Проверяем наличие методов авторизации
@@ -204,17 +213,18 @@ describe('Generated Client', () => {
inputPath: FIXTURES.COMPLEX,
outputPath,
fileName: 'ComplexApi',
mode: 'split',
};
await generate(config);
const generatedFile = join(outputPath, 'ComplexApi.ts');
const generatedFile = join(outputPath, 'index.ts');
const exists = await fileExists(generatedFile);
expect(exists).toBe(true);
// Проверяем что файл не пустой
const content = await readTextFile(generatedFile);
const content = await readTextFile(join(outputPath, 'operations', 'index.ts'));
expect(content.length).toBeGreaterThan(1000);
}, 30000);
});
});
});