ts-openapi-codegen 2.1.0-beta.5 → 2.1.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/README.rus.md +3 -0
- package/dist/cli/checkAndUpdateConfig/__tests__/checkConfig.test.d.ts +2 -0
- package/dist/cli/checkAndUpdateConfig/__tests__/checkConfig.test.d.ts.map +1 -0
- package/dist/cli/checkAndUpdateConfig/__tests__/checkConfig.test.js +63 -0
- package/dist/cli/checkAndUpdateConfig/__tests__/updateConfig.test.d.ts +2 -0
- package/dist/cli/checkAndUpdateConfig/__tests__/updateConfig.test.d.ts.map +1 -0
- package/dist/cli/checkAndUpdateConfig/__tests__/updateConfig.test.js +62 -0
- package/dist/cli/checkAndUpdateConfig/utils/__tests__/prepareConfigData.test.d.ts +2 -0
- package/dist/cli/checkAndUpdateConfig/utils/__tests__/prepareConfigData.test.d.ts.map +1 -0
- package/dist/cli/checkAndUpdateConfig/utils/__tests__/prepareConfigData.test.js +20 -0
- package/dist/cli/checkAndUpdateConfig/utils/__tests__/removeDefaultConfigValues.test.d.ts +2 -0
- package/dist/cli/checkAndUpdateConfig/utils/__tests__/removeDefaultConfigValues.test.d.ts.map +1 -0
- package/dist/cli/checkAndUpdateConfig/utils/__tests__/removeDefaultConfigValues.test.js +35 -0
- package/dist/cli/checkAndUpdateConfig/utils/__tests__/validateAndMigrateConfigData.test.d.ts +2 -0
- package/dist/cli/checkAndUpdateConfig/utils/__tests__/validateAndMigrateConfigData.test.d.ts.map +1 -0
- package/dist/cli/checkAndUpdateConfig/utils/__tests__/validateAndMigrateConfigData.test.js +59 -0
- package/dist/cli/index.js +2 -0
- package/dist/cli/initOpenApiConfig/__tests__/init.test.d.ts +2 -0
- package/dist/cli/initOpenApiConfig/__tests__/init.test.d.ts.map +1 -0
- package/dist/cli/initOpenApiConfig/__tests__/init.test.js +30 -0
- package/dist/cli/initOpenApiConfig/__tests__/initConfig.test.d.ts +2 -0
- package/dist/cli/initOpenApiConfig/__tests__/initConfig.test.d.ts.map +1 -0
- package/dist/cli/initOpenApiConfig/__tests__/initConfig.test.js +47 -0
- package/dist/cli/initOpenApiConfig/init.d.ts.map +1 -1
- package/dist/cli/initOpenApiConfig/init.js +2 -0
- package/dist/cli/initOpenApiConfig/initCustomRequest.d.ts +1 -0
- package/dist/cli/initOpenApiConfig/initCustomRequest.d.ts.map +1 -1
- package/dist/cli/initOpenApiConfig/initCustomRequest.js +2 -1
- package/dist/cli/initOpenApiConfig/utils/__tests__/buildConfig.test.d.ts +2 -0
- package/dist/cli/initOpenApiConfig/utils/__tests__/buildConfig.test.d.ts.map +1 -0
- package/dist/cli/initOpenApiConfig/utils/__tests__/buildConfig.test.js +99 -0
- package/dist/cli/initOpenApiConfig/utils/__tests__/findSpecFiles.test.d.ts +2 -0
- package/dist/cli/initOpenApiConfig/utils/__tests__/findSpecFiles.test.d.ts.map +1 -0
- package/dist/cli/initOpenApiConfig/utils/__tests__/findSpecFiles.test.js +45 -0
- package/dist/cli/initOpenApiConfig/utils/__tests__/validateSpecFiles.test.d.ts +2 -0
- package/dist/cli/initOpenApiConfig/utils/__tests__/validateSpecFiles.test.d.ts.map +1 -0
- package/dist/cli/initOpenApiConfig/utils/__tests__/validateSpecFiles.test.js +52 -0
- package/dist/cli/initOpenApiConfig/utils/buildConfig.d.ts.map +1 -1
- package/dist/cli/initOpenApiConfig/utils/buildConfig.js +4 -0
- package/dist/cli/previewChanges/utils/__tests__/compareFiles.test.d.ts +2 -0
- package/dist/cli/previewChanges/utils/__tests__/compareFiles.test.d.ts.map +1 -0
- package/dist/cli/previewChanges/utils/__tests__/compareFiles.test.js +52 -0
- package/dist/cli/previewChanges/utils/__tests__/isDirectoryEmpty.test.d.ts +2 -0
- package/dist/cli/previewChanges/utils/__tests__/isDirectoryEmpty.test.d.ts.map +1 -0
- package/dist/cli/previewChanges/utils/__tests__/isDirectoryEmpty.test.js +43 -0
- package/dist/cli/previewChanges/utils/__tests__/readDirectoryRecursive.test.d.ts +2 -0
- package/dist/cli/previewChanges/utils/__tests__/readDirectoryRecursive.test.d.ts.map +1 -0
- package/dist/cli/previewChanges/utils/__tests__/readDirectoryRecursive.test.js +32 -0
- package/dist/cli/previewChanges/utils/__tests__/updateOutputPaths.test.d.ts +2 -0
- package/dist/cli/previewChanges/utils/__tests__/updateOutputPaths.test.d.ts.map +1 -0
- package/dist/cli/previewChanges/utils/__tests__/updateOutputPaths.test.js +68 -0
- package/dist/cli/schemas/__tests__/checkConfigAndUpdate.test.d.ts +2 -0
- package/dist/cli/schemas/__tests__/checkConfigAndUpdate.test.d.ts.map +1 -0
- package/dist/cli/schemas/__tests__/checkConfigAndUpdate.test.js +36 -0
- package/dist/cli/schemas/__tests__/generateOptionsSchema.test.d.ts +2 -0
- package/dist/cli/schemas/__tests__/generateOptionsSchema.test.d.ts.map +1 -0
- package/dist/cli/schemas/__tests__/generateOptionsSchema.test.js +59 -0
- package/dist/cli/schemas/__tests__/initOptionsSchema.test.d.ts +2 -0
- package/dist/cli/schemas/__tests__/initOptionsSchema.test.d.ts.map +1 -0
- package/dist/cli/schemas/__tests__/initOptionsSchema.test.js +43 -0
- package/dist/cli/schemas/__tests__/previewChangesSchema.test.d.ts +2 -0
- package/dist/cli/schemas/__tests__/previewChangesSchema.test.d.ts.map +1 -0
- package/dist/cli/schemas/__tests__/previewChangesSchema.test.js +31 -0
- package/dist/cli/schemas/init.d.ts +1 -0
- package/dist/cli/schemas/init.d.ts.map +1 -1
- package/dist/cli/schemas/init.js +1 -0
- package/dist/common/Consts.d.ts.map +1 -1
- package/dist/common/Consts.js +1 -0
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedBase.d.ts +1 -0
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedBase.d.ts.map +1 -1
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV1.d.ts +2 -0
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV1.d.ts.map +1 -1
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV2.d.ts +2 -0
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV2.d.ts.map +1 -1
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV3.d.ts +2 -0
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV3.d.ts.map +1 -1
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV4.d.ts +2 -0
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV4.d.ts.map +1 -1
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV5.d.ts +2 -0
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV5.d.ts.map +1 -1
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedVersionedSchemas.d.ts +11 -0
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedVersionedSchemas.d.ts.map +1 -1
- package/dist/common/VersionedSchema/CommonSchemas.d.ts +2 -0
- package/dist/common/VersionedSchema/CommonSchemas.d.ts.map +1 -1
- package/dist/common/VersionedSchema/CommonSchemas.js +1 -0
- package/dist/common/VersionedSchema/MultiOptionsVersioned/MultiOptionsMigrationPlan.d.ts.map +1 -1
- package/dist/common/VersionedSchema/MultiOptionsVersioned/MultiOptionsMigrationPlan.js +1 -0
- package/dist/common/VersionedSchema/MultiOptionsVersioned/MultiOptionsSchemaV3.d.ts +1 -0
- package/dist/common/VersionedSchema/MultiOptionsVersioned/MultiOptionsSchemaV3.d.ts.map +1 -1
- package/dist/common/VersionedSchema/MultiOptionsVersioned/MultiOptionsSchemaV4.d.ts +1 -0
- package/dist/common/VersionedSchema/MultiOptionsVersioned/MultiOptionsSchemaV4.d.ts.map +1 -1
- package/dist/common/VersionedSchema/MultiOptionsVersioned/MultiOptionsSchemaV5.d.ts +1 -0
- package/dist/common/VersionedSchema/MultiOptionsVersioned/MultiOptionsSchemaV5.d.ts.map +1 -1
- package/dist/common/VersionedSchema/OptionsVersioned/OptionsMigrationPlans.d.ts.map +1 -1
- package/dist/common/VersionedSchema/OptionsVersioned/OptionsMigrationPlans.js +1 -0
- package/dist/common/VersionedSchema/OptionsVersioned/OptionsSchemaV3.d.ts +1 -0
- package/dist/common/VersionedSchema/OptionsVersioned/OptionsSchemaV3.d.ts.map +1 -1
- package/dist/common/VersionedSchema/OptionsVersioned/OptionsSchemaV4.d.ts +1 -0
- package/dist/common/VersionedSchema/OptionsVersioned/OptionsSchemaV4.d.ts.map +1 -1
- package/dist/common/VersionedSchema/Utils/__mocks__/compatibilityCases.d.ts.map +1 -1
- package/dist/common/VersionedSchema/Utils/__mocks__/compatibilityCases.js +8 -2
- package/dist/common/utils/__tests__/convertArrayToObject.test.js +3 -0
- package/dist/common/utils/convertArrayToObject.d.ts.map +1 -1
- package/dist/common/utils/convertArrayToObject.js +2 -0
- package/dist/core/OpenApiClient.d.ts.map +1 -1
- package/dist/core/OpenApiClient.js +6 -1
- package/dist/core/WriteClient.d.ts +3 -1
- package/dist/core/WriteClient.d.ts.map +1 -1
- package/dist/core/WriteClient.js +3 -2
- package/dist/core/utils/GenerationCache.d.ts +18 -0
- package/dist/core/utils/GenerationCache.d.ts.map +1 -0
- package/dist/core/utils/GenerationCache.js +41 -0
- package/dist/core/utils/__tests__/GenerationCache.test.d.ts +2 -0
- package/dist/core/utils/__tests__/GenerationCache.test.d.ts.map +1 -0
- package/dist/core/utils/__tests__/GenerationCache.test.js +37 -0
- package/dist/core/utils/__tests__/loadDiffReport.test.d.ts +2 -0
- package/dist/core/utils/__tests__/loadDiffReport.test.d.ts.map +1 -0
- package/dist/core/utils/__tests__/loadDiffReport.test.js +97 -0
- package/dist/core/utils/__tests__/templateRendering.test.d.ts +2 -0
- package/dist/core/utils/__tests__/templateRendering.test.d.ts.map +1 -0
- package/dist/core/utils/__tests__/templateRendering.test.js +119 -0
- package/dist/core/utils/__tests__/writeClientServices.test.js +1 -0
- package/dist/core/utils/__tests__/writeFileIfChanged.test.d.ts +2 -0
- package/dist/core/utils/__tests__/writeFileIfChanged.test.d.ts.map +1 -0
- package/dist/core/utils/__tests__/writeFileIfChanged.test.js +30 -0
- package/dist/core/utils/writeClientCore.d.ts +2 -0
- package/dist/core/utils/writeClientCore.d.ts.map +1 -1
- package/dist/core/utils/writeClientCore.js +5 -4
- package/dist/core/utils/writeClientServices.d.ts +2 -0
- package/dist/core/utils/writeClientServices.d.ts.map +1 -1
- package/dist/core/utils/writeClientServices.js +2 -1
- package/dist/core/utils/writeFileIfChanged.d.ts +3 -0
- package/dist/core/utils/writeFileIfChanged.d.ts.map +1 -0
- package/dist/core/utils/writeFileIfChanged.js +22 -0
- package/dist/templatesCompiled/cli/customRequest.d.ts +6 -2
- package/dist/templatesCompiled/cli/customRequest.d.ts.map +1 -1
- package/dist/templatesCompiled/cli/customRequest.js +28 -8
- package/dist/templatesCompiled/cli/customRequestExecutor.d.ts +3 -0
- package/dist/templatesCompiled/cli/customRequestExecutor.d.ts.map +1 -1
- package/dist/templatesCompiled/cli/customRequestExecutor.js +28 -5
- package/dist/templatesCompiled/client/core/axios/request.d.ts +6 -2
- package/dist/templatesCompiled/client/core/axios/request.d.ts.map +1 -1
- package/dist/templatesCompiled/client/core/axios/request.js +22 -2
- package/dist/templatesCompiled/client/core/executor/createExecutorAdapter.d.ts +5 -2
- package/dist/templatesCompiled/client/core/executor/createExecutorAdapter.d.ts.map +1 -1
- package/dist/templatesCompiled/client/core/executor/createExecutorAdapter.js +42 -12
- package/dist/templatesCompiled/client/core/executor/requestExecutor.d.ts +2 -0
- package/dist/templatesCompiled/client/core/executor/requestExecutor.d.ts.map +1 -1
- package/dist/templatesCompiled/client/core/executor/requestExecutor.js +11 -3
- package/dist/templatesCompiled/client/core/fetch/request.d.ts +6 -2
- package/dist/templatesCompiled/client/core/fetch/request.d.ts.map +1 -1
- package/dist/templatesCompiled/client/core/fetch/request.js +22 -2
- package/dist/templatesCompiled/client/core/interceptors/withInterceptors.d.ts +2 -0
- package/dist/templatesCompiled/client/core/interceptors/withInterceptors.d.ts.map +1 -1
- package/dist/templatesCompiled/client/core/interceptors/withInterceptors.js +11 -3
- package/dist/templatesCompiled/client/core/node/request.d.ts +6 -2
- package/dist/templatesCompiled/client/core/node/request.d.ts.map +1 -1
- package/dist/templatesCompiled/client/core/node/request.js +22 -2
- package/dist/templatesCompiled/client/core/xhr/request.d.ts +6 -2
- package/dist/templatesCompiled/client/core/xhr/request.d.ts.map +1 -1
- package/dist/templatesCompiled/client/core/xhr/request.js +22 -2
- package/dist/templatesCompiled/client/exportService.d.ts +11 -9
- package/dist/templatesCompiled/client/exportService.d.ts.map +1 -1
- package/dist/templatesCompiled/client/exportService.js +82 -64
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
- Supports strict OpenAPI diagnostics with JSON reports (`--strict-openapi`, `--report-file`)
|
|
31
31
|
- Supports generator plugins (`plugins`) including built-in `x-typescript-type`
|
|
32
32
|
- Supports binary request/response generation (`format: binary` -> `Blob`)
|
|
33
|
+
- Supports opt-in generation cache and incremental writes (`--cache`, `--cachePath`, `--cacheStrategy`, `--cacheDebug`)
|
|
33
34
|
|
|
34
35
|
## Install
|
|
35
36
|
|
|
@@ -43,6 +44,8 @@ npm install ts-openapi-codegen --save-dev
|
|
|
43
44
|
- [Configuration file](docs/en/configuration.md)
|
|
44
45
|
- [Examples](docs/en/examples.md)
|
|
45
46
|
- [Features](docs/en/features.md)
|
|
47
|
+
- [Plugins](docs/en/plugins.md)
|
|
48
|
+
- [Plugin API v2 (RFC)](docs/en/plugin-api-v2.md)
|
|
46
49
|
- [Русская версия README](README.rus.md)
|
|
47
50
|
- [Русская документация](docs/ru/usage.md)
|
|
48
51
|
|
package/README.rus.md
CHANGED
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
- Поддерживает strict-диагностику OpenAPI с JSON-отчетом (`--strict-openapi`, `--report-file`)
|
|
31
31
|
- Поддерживает плагины генератора (`plugins`), включая встроенный `x-typescript-type`
|
|
32
32
|
- Поддерживает генерацию бинарных request/response (`format: binary` -> `Blob`)
|
|
33
|
+
- Поддерживает opt-in кэш генерации и инкрементальную запись (`--cache`, `--cachePath`, `--cacheStrategy`, `--cacheDebug`)
|
|
33
34
|
|
|
34
35
|
## Установка
|
|
35
36
|
|
|
@@ -43,6 +44,8 @@ npm install ts-openapi-codegen --save-dev
|
|
|
43
44
|
- [Файл конфигурации](docs/ru/configuration.md)
|
|
44
45
|
- [Примеры](docs/ru/examples.md)
|
|
45
46
|
- [Возможности](docs/ru/features.md)
|
|
47
|
+
- [Плагины](docs/ru/plugins.md)
|
|
48
|
+
- [Plugin API v2 (RFC)](docs/ru/plugin-api-v2.md)
|
|
46
49
|
- [English README](README.md)
|
|
47
50
|
- [English docs](docs/en/usage.md)
|
|
48
51
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkConfig.test.d.ts","sourceRoot":"","sources":["../../../../src/cli/checkAndUpdateConfig/__tests__/checkConfig.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
7
|
+
const promises_1 = require("node:fs/promises");
|
|
8
|
+
const node_os_1 = require("node:os");
|
|
9
|
+
const node_path_1 = require("node:path");
|
|
10
|
+
const node_test_1 = require("node:test");
|
|
11
|
+
const Consts_1 = require("../../../common/Consts");
|
|
12
|
+
const HttpClient_enum_1 = require("../../../core/types/enums/HttpClient.enum");
|
|
13
|
+
const checkConfig_1 = require("../checkConfig");
|
|
14
|
+
class ProcessExitError extends Error {
|
|
15
|
+
exitCode;
|
|
16
|
+
constructor(exitCode) {
|
|
17
|
+
super(`process.exit(${exitCode})`);
|
|
18
|
+
this.exitCode = exitCode;
|
|
19
|
+
this.name = 'ProcessExitError';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/** Config without schema-default fields so checkConfig does not open enquirer. */
|
|
23
|
+
const flatConfig = {
|
|
24
|
+
input: './test/spec/v3.json',
|
|
25
|
+
output: './test/generated',
|
|
26
|
+
httpClient: HttpClient_enum_1.HttpClient.AXIOS,
|
|
27
|
+
};
|
|
28
|
+
const mockProcessExit = () => node_test_1.mock.method(process, 'exit', (code) => {
|
|
29
|
+
throw new ProcessExitError(Number(code ?? 0));
|
|
30
|
+
});
|
|
31
|
+
async function writeConfig(dir, content) {
|
|
32
|
+
const configPath = (0, node_path_1.join)(dir, 'openapi.config.json');
|
|
33
|
+
await (0, promises_1.writeFile)(configPath, JSON.stringify(content, null, 2), 'utf8');
|
|
34
|
+
return configPath;
|
|
35
|
+
}
|
|
36
|
+
(0, node_test_1.describe)('@unit: checkConfig', () => {
|
|
37
|
+
(0, node_test_1.test)('exits when options fail schema validation', async () => {
|
|
38
|
+
const exitMock = mockProcessExit();
|
|
39
|
+
const shutdownMock = node_test_1.mock.method(Consts_1.APP_LOGGER, 'shutdownLoggerAsync', async () => undefined);
|
|
40
|
+
const errorMock = node_test_1.mock.method(Consts_1.APP_LOGGER, 'error', () => undefined);
|
|
41
|
+
await node_assert_1.default.rejects(() => (0, checkConfig_1.checkConfig)({ openapiConfig: 123 }), ProcessExitError);
|
|
42
|
+
exitMock.mock.restore();
|
|
43
|
+
shutdownMock.mock.restore();
|
|
44
|
+
errorMock.mock.restore();
|
|
45
|
+
});
|
|
46
|
+
(0, node_test_1.test)('exits when config file is missing', async () => {
|
|
47
|
+
const dir = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'check-config-'));
|
|
48
|
+
const configPath = (0, node_path_1.join)(dir, 'missing.json');
|
|
49
|
+
const exitMock = mockProcessExit();
|
|
50
|
+
const shutdownMock = node_test_1.mock.method(Consts_1.APP_LOGGER, 'shutdownLoggerAsync', async () => undefined);
|
|
51
|
+
await node_assert_1.default.rejects(() => (0, checkConfig_1.checkConfig)({ openapiConfig: configPath }), ProcessExitError);
|
|
52
|
+
exitMock.mock.restore();
|
|
53
|
+
shutdownMock.mock.restore();
|
|
54
|
+
});
|
|
55
|
+
(0, node_test_1.test)('reports valid config without prompting when up to date', async () => {
|
|
56
|
+
const dir = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'check-config-'));
|
|
57
|
+
const configPath = await writeConfig(dir, flatConfig);
|
|
58
|
+
const infoMock = node_test_1.mock.method(Consts_1.APP_LOGGER, 'info', () => undefined);
|
|
59
|
+
await (0, checkConfig_1.checkConfig)({ openapiConfig: configPath });
|
|
60
|
+
node_assert_1.default.strictEqual(infoMock.mock.callCount(), 1);
|
|
61
|
+
infoMock.mock.restore();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"updateConfig.test.d.ts","sourceRoot":"","sources":["../../../../src/cli/checkAndUpdateConfig/__tests__/updateConfig.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
7
|
+
const promises_1 = require("node:fs/promises");
|
|
8
|
+
const node_os_1 = require("node:os");
|
|
9
|
+
const node_path_1 = require("node:path");
|
|
10
|
+
const node_test_1 = require("node:test");
|
|
11
|
+
const Consts_1 = require("../../../common/Consts");
|
|
12
|
+
const HttpClient_enum_1 = require("../../../core/types/enums/HttpClient.enum");
|
|
13
|
+
const updateConfig_1 = require("../updateConfig");
|
|
14
|
+
class ProcessExitError extends Error {
|
|
15
|
+
exitCode;
|
|
16
|
+
constructor(exitCode) {
|
|
17
|
+
super(`process.exit(${exitCode})`);
|
|
18
|
+
this.exitCode = exitCode;
|
|
19
|
+
this.name = 'ProcessExitError';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const flatConfig = {
|
|
23
|
+
input: './test/spec/v3.json',
|
|
24
|
+
output: './test/generated',
|
|
25
|
+
httpClient: HttpClient_enum_1.HttpClient.FETCH,
|
|
26
|
+
};
|
|
27
|
+
const mockProcessExit = () => node_test_1.mock.method(process, 'exit', (code) => {
|
|
28
|
+
throw new ProcessExitError(Number(code ?? 0));
|
|
29
|
+
});
|
|
30
|
+
async function writeConfig(dir, content) {
|
|
31
|
+
const configPath = (0, node_path_1.join)(dir, 'openapi.config.json');
|
|
32
|
+
await (0, promises_1.writeFile)(configPath, JSON.stringify(content, null, 2), 'utf8');
|
|
33
|
+
return configPath;
|
|
34
|
+
}
|
|
35
|
+
(0, node_test_1.describe)('@unit: updateConfig', () => {
|
|
36
|
+
(0, node_test_1.test)('exits when options fail schema validation', async () => {
|
|
37
|
+
const exitMock = mockProcessExit();
|
|
38
|
+
const shutdownMock = node_test_1.mock.method(Consts_1.APP_LOGGER, 'shutdownLoggerAsync', async () => undefined);
|
|
39
|
+
const errorMock = node_test_1.mock.method(Consts_1.APP_LOGGER, 'error', () => undefined);
|
|
40
|
+
await node_assert_1.default.rejects(() => (0, updateConfig_1.updateConfig)({ openapiConfig: 123 }), ProcessExitError);
|
|
41
|
+
exitMock.mock.restore();
|
|
42
|
+
shutdownMock.mock.restore();
|
|
43
|
+
errorMock.mock.restore();
|
|
44
|
+
});
|
|
45
|
+
(0, node_test_1.test)('exits when config file is missing', async () => {
|
|
46
|
+
const dir = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'update-config-'));
|
|
47
|
+
const configPath = (0, node_path_1.join)(dir, 'missing.json');
|
|
48
|
+
const exitMock = mockProcessExit();
|
|
49
|
+
const shutdownMock = node_test_1.mock.method(Consts_1.APP_LOGGER, 'shutdownLoggerAsync', async () => undefined);
|
|
50
|
+
await node_assert_1.default.rejects(() => (0, updateConfig_1.updateConfig)({ openapiConfig: configPath }), ProcessExitError);
|
|
51
|
+
exitMock.mock.restore();
|
|
52
|
+
shutdownMock.mock.restore();
|
|
53
|
+
});
|
|
54
|
+
(0, node_test_1.test)('logs up to date when config is current', async () => {
|
|
55
|
+
const dir = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'update-config-'));
|
|
56
|
+
const configPath = await writeConfig(dir, flatConfig);
|
|
57
|
+
const infoMock = node_test_1.mock.method(Consts_1.APP_LOGGER, 'info', () => undefined);
|
|
58
|
+
await (0, updateConfig_1.updateConfig)({ openapiConfig: configPath });
|
|
59
|
+
node_assert_1.default.strictEqual(infoMock.mock.callCount(), 1);
|
|
60
|
+
infoMock.mock.restore();
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepareConfigData.test.d.ts","sourceRoot":"","sources":["../../../../../src/cli/checkAndUpdateConfig/utils/__tests__/prepareConfigData.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
7
|
+
const node_test_1 = require("node:test");
|
|
8
|
+
const prepareConfigData_1 = require("../prepareConfigData");
|
|
9
|
+
(0, node_test_1.describe)('@unit: prepareConfigData', () => {
|
|
10
|
+
(0, node_test_1.test)('serializes and formats config as JSON string', async () => {
|
|
11
|
+
const formatted = await (0, prepareConfigData_1.prepareConfigData)({
|
|
12
|
+
input: './test/spec/v3.json',
|
|
13
|
+
output: './generated',
|
|
14
|
+
});
|
|
15
|
+
node_assert_1.default.match(formatted, /"input":\s*"\.\/test\/spec\/v3\.json"/);
|
|
16
|
+
node_assert_1.default.match(formatted, /"output":\s*"\.\/generated"/);
|
|
17
|
+
node_assert_1.default.ok(formatted.trim().startsWith('{'));
|
|
18
|
+
node_assert_1.default.ok(formatted.trim().endsWith('}'));
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeDefaultConfigValues.test.d.ts","sourceRoot":"","sources":["../../../../../src/cli/checkAndUpdateConfig/utils/__tests__/removeDefaultConfigValues.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
7
|
+
const node_test_1 = require("node:test");
|
|
8
|
+
const Consts_1 = require("../../../../common/Consts");
|
|
9
|
+
const HttpClient_enum_1 = require("../../../../core/types/enums/HttpClient.enum");
|
|
10
|
+
const removeDefaultConfigValues_1 = require("../removeDefaultConfigValues");
|
|
11
|
+
(0, node_test_1.describe)('@unit: removeDefaultConfigValues', () => {
|
|
12
|
+
(0, node_test_1.test)('removes keys that match COMMON_DEFAULT_OPTIONS_VALUES', () => {
|
|
13
|
+
const cleaned = (0, removeDefaultConfigValues_1.removeDefaultConfigValues)({
|
|
14
|
+
input: './spec.json',
|
|
15
|
+
output: './generated',
|
|
16
|
+
httpClient: Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.httpClient,
|
|
17
|
+
sortByRequired: Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.sortByRequired,
|
|
18
|
+
});
|
|
19
|
+
node_assert_1.default.deepStrictEqual(cleaned, {
|
|
20
|
+
input: './spec.json',
|
|
21
|
+
output: './generated',
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
(0, node_test_1.test)('keeps custom values that differ from defaults', () => {
|
|
25
|
+
const cleaned = (0, removeDefaultConfigValues_1.removeDefaultConfigValues)({
|
|
26
|
+
input: './spec.json',
|
|
27
|
+
output: './generated',
|
|
28
|
+
httpClient: HttpClient_enum_1.HttpClient.AXIOS,
|
|
29
|
+
interfacePrefix: 'Api',
|
|
30
|
+
});
|
|
31
|
+
node_assert_1.default.strictEqual(cleaned.httpClient, HttpClient_enum_1.HttpClient.AXIOS);
|
|
32
|
+
node_assert_1.default.strictEqual(cleaned.interfacePrefix, 'Api');
|
|
33
|
+
node_assert_1.default.strictEqual(cleaned.input, './spec.json');
|
|
34
|
+
});
|
|
35
|
+
});
|
package/dist/cli/checkAndUpdateConfig/utils/__tests__/validateAndMigrateConfigData.test.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validateAndMigrateConfigData.test.d.ts","sourceRoot":"","sources":["../../../../../src/cli/checkAndUpdateConfig/utils/__tests__/validateAndMigrateConfigData.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
7
|
+
const node_test_1 = require("node:test");
|
|
8
|
+
const Consts_1 = require("../../../../common/Consts");
|
|
9
|
+
const HttpClient_enum_1 = require("../../../../core/types/enums/HttpClient.enum");
|
|
10
|
+
const validateAndMigrateConfigData_1 = require("../validateAndMigrateConfigData");
|
|
11
|
+
const flatConfig = {
|
|
12
|
+
input: './test/spec/v3.json',
|
|
13
|
+
output: './generated',
|
|
14
|
+
httpClient: HttpClient_enum_1.HttpClient.FETCH,
|
|
15
|
+
};
|
|
16
|
+
(0, node_test_1.describe)('@unit: validateAndMigrateConfigData', () => {
|
|
17
|
+
(0, node_test_1.test)('accepts current flat object config', () => {
|
|
18
|
+
const result = (0, validateAndMigrateConfigData_1.validateAndMigrateConfigData)({ ...flatConfig });
|
|
19
|
+
node_assert_1.default.strictEqual(result.isActualConfigVersion, true);
|
|
20
|
+
node_assert_1.default.strictEqual(result.migratedData.input, flatConfig.input);
|
|
21
|
+
node_assert_1.default.strictEqual(result.migratedData.output, flatConfig.output);
|
|
22
|
+
});
|
|
23
|
+
(0, node_test_1.test)('marks deprecated array format as outdated', () => {
|
|
24
|
+
const warnMock = node_test_1.mock.method(Consts_1.APP_LOGGER, 'warn', () => undefined);
|
|
25
|
+
const legacyArray = [
|
|
26
|
+
{ input: './a.json', output: './generated/a', httpClient: HttpClient_enum_1.HttpClient.AXIOS, useOptions: true },
|
|
27
|
+
{ input: './b.json', output: './generated/b', httpClient: HttpClient_enum_1.HttpClient.AXIOS, useOptions: true },
|
|
28
|
+
];
|
|
29
|
+
const result = (0, validateAndMigrateConfigData_1.validateAndMigrateConfigData)(legacyArray);
|
|
30
|
+
node_assert_1.default.strictEqual(result.isActualConfigVersion, false);
|
|
31
|
+
node_assert_1.default.ok(Array.isArray(result.migratedData.items));
|
|
32
|
+
node_assert_1.default.strictEqual(result.migratedData.items.length, 2);
|
|
33
|
+
node_assert_1.default.strictEqual(warnMock.mock.callCount(), 1);
|
|
34
|
+
warnMock.mock.restore();
|
|
35
|
+
});
|
|
36
|
+
(0, node_test_1.test)('migrates multi-options config with items', () => {
|
|
37
|
+
const multiConfig = {
|
|
38
|
+
items: [
|
|
39
|
+
{ input: './api/v1.json', output: './generated/v1' },
|
|
40
|
+
{ input: './api/v2.json', output: './generated/v2' },
|
|
41
|
+
],
|
|
42
|
+
httpClient: HttpClient_enum_1.HttpClient.AXIOS,
|
|
43
|
+
};
|
|
44
|
+
const result = (0, validateAndMigrateConfigData_1.validateAndMigrateConfigData)(multiConfig);
|
|
45
|
+
node_assert_1.default.ok(result.migratedData.items);
|
|
46
|
+
node_assert_1.default.strictEqual(result.migratedData.items.length, 2);
|
|
47
|
+
node_assert_1.default.strictEqual(result.migratedData.httpClient, HttpClient_enum_1.HttpClient.AXIOS);
|
|
48
|
+
});
|
|
49
|
+
(0, node_test_1.test)('detects default values when config matches defaults', () => {
|
|
50
|
+
const withDefaults = {
|
|
51
|
+
...flatConfig,
|
|
52
|
+
httpClient: HttpClient_enum_1.HttpClient.FETCH,
|
|
53
|
+
sortByRequired: false,
|
|
54
|
+
};
|
|
55
|
+
const result = (0, validateAndMigrateConfigData_1.validateAndMigrateConfigData)(withDefaults);
|
|
56
|
+
node_assert_1.default.strictEqual(result.hasDefaultValues, true);
|
|
57
|
+
node_assert_1.default.strictEqual(result.migratedData.httpClient, undefined);
|
|
58
|
+
});
|
|
59
|
+
});
|
package/dist/cli/index.js
CHANGED
|
@@ -60,6 +60,7 @@ program
|
|
|
60
60
|
.option('--enumPrefix <value>', 'Prefix for enum model(default: "E")', 'E')
|
|
61
61
|
.option('--typePrefix <value>', 'Prefix for type model(default: "T")', 'T')
|
|
62
62
|
.option('--useCancelableRequest', 'Use cancelled promise as returned data type in request (default: false)')
|
|
63
|
+
.option('--useRequestRaw [value]', 'Generate requestRaw methods and raw HTTP stack (default: true)', (value) => value === undefined || value === 'true' || value === true)
|
|
63
64
|
.addOption(new commander_1.Option('-l, --logLevel <level>', 'Logging level').choices([...Object.values(Enums_1.ELogLevel)]).default(Enums_1.ELogLevel.ERROR))
|
|
64
65
|
.addOption(new commander_1.Option('-t, --logTarget <target>', 'Target of logging').choices([...Object.values(Enums_1.ELogOutput)]).default(Enums_1.ELogOutput.CONSOLE))
|
|
65
66
|
.option('-s, --sortByRequired', 'Property sorting strategy: simplified or extended')
|
|
@@ -116,6 +117,7 @@ program
|
|
|
116
117
|
.option('-sd, --specs-dir <value>', 'Путь до директории с файлами спецификации', './openapi')
|
|
117
118
|
.option('--request <value>', 'Path to custom request file')
|
|
118
119
|
.option('--useCancelableRequest', 'Use cancelled promise as returned data type in request (default: false)')
|
|
120
|
+
.option('--useRequestRaw [value]', 'Generate requestRaw methods and raw HTTP stack (default: true)', (value) => value === undefined || value === true || value === 'true')
|
|
119
121
|
.option('--useInteractiveMode', 'Использовать интерактивный режим команды. В терминале будут задаваться вопросы (default: false)')
|
|
120
122
|
.hook('preAction', async () => {
|
|
121
123
|
await updateNotifier.checkAndNotify();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"init.test.d.ts","sourceRoot":"","sources":["../../../../src/cli/initOpenApiConfig/__tests__/init.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
7
|
+
const node_test_1 = require("node:test");
|
|
8
|
+
const Consts_1 = require("../../../common/Consts");
|
|
9
|
+
const init_1 = require("../init");
|
|
10
|
+
class ProcessExitError extends Error {
|
|
11
|
+
exitCode;
|
|
12
|
+
constructor(exitCode) {
|
|
13
|
+
super(`process.exit(${exitCode})`);
|
|
14
|
+
this.exitCode = exitCode;
|
|
15
|
+
this.name = 'ProcessExitError';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
(0, node_test_1.describe)('@unit: init', () => {
|
|
19
|
+
(0, node_test_1.test)('exits when options fail schema validation', async () => {
|
|
20
|
+
const exitMock = node_test_1.mock.method(process, 'exit', (code) => {
|
|
21
|
+
throw new ProcessExitError(Number(code ?? 0));
|
|
22
|
+
});
|
|
23
|
+
const shutdownMock = node_test_1.mock.method(Consts_1.APP_LOGGER, 'shutdownLoggerAsync', async () => undefined);
|
|
24
|
+
const errorMock = node_test_1.mock.method(Consts_1.APP_LOGGER, 'error', () => undefined);
|
|
25
|
+
await node_assert_1.default.rejects(() => (0, init_1.init)({ specsDir: 123 }), ProcessExitError);
|
|
26
|
+
exitMock.mock.restore();
|
|
27
|
+
shutdownMock.mock.restore();
|
|
28
|
+
errorMock.mock.restore();
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initConfig.test.d.ts","sourceRoot":"","sources":["../../../../src/cli/initOpenApiConfig/__tests__/initConfig.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
7
|
+
const promises_1 = require("node:fs/promises");
|
|
8
|
+
const node_os_1 = require("node:os");
|
|
9
|
+
const node_path_1 = require("node:path");
|
|
10
|
+
const node_test_1 = require("node:test");
|
|
11
|
+
const Consts_1 = require("../../../common/Consts");
|
|
12
|
+
const initConfig_1 = require("../initConfig");
|
|
13
|
+
const registerHandlebarTemplates_1 = require("../utils/registerHandlebarTemplates");
|
|
14
|
+
(0, node_test_1.describe)('@unit: initConfig', () => {
|
|
15
|
+
(0, node_test_1.test)('leaves existing config unchanged in non-interactive mode', async () => {
|
|
16
|
+
const dir = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'init-config-'));
|
|
17
|
+
const configPath = (0, node_path_1.join)(dir, 'openapi.config.json');
|
|
18
|
+
await (0, promises_1.writeFile)(configPath, '{"input":"./x.json","output":"./out"}', 'utf8');
|
|
19
|
+
const warnMock = node_test_1.mock.method(Consts_1.APP_LOGGER, 'warn', () => undefined);
|
|
20
|
+
const infoMock = node_test_1.mock.method(Consts_1.APP_LOGGER, 'info', () => undefined);
|
|
21
|
+
const templates = (0, registerHandlebarTemplates_1.registerHandlebarTemplates)();
|
|
22
|
+
await (0, initConfig_1.initConfig)({
|
|
23
|
+
openapiConfig: configPath,
|
|
24
|
+
specsDir: dir,
|
|
25
|
+
templates,
|
|
26
|
+
useInteractiveMode: false,
|
|
27
|
+
});
|
|
28
|
+
node_assert_1.default.strictEqual(warnMock.mock.callCount(), 1);
|
|
29
|
+
node_assert_1.default.strictEqual(infoMock.mock.callCount(), 1);
|
|
30
|
+
warnMock.mock.restore();
|
|
31
|
+
infoMock.mock.restore();
|
|
32
|
+
});
|
|
33
|
+
(0, node_test_1.test)('writes example config when no specs are found', async () => {
|
|
34
|
+
const dir = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'init-config-'));
|
|
35
|
+
const configPath = (0, node_path_1.join)(dir, 'new-openapi.config.json');
|
|
36
|
+
const templates = (0, registerHandlebarTemplates_1.registerHandlebarTemplates)();
|
|
37
|
+
await (0, initConfig_1.initConfig)({
|
|
38
|
+
openapiConfig: configPath,
|
|
39
|
+
specsDir: (0, node_path_1.join)(dir, 'empty-specs'),
|
|
40
|
+
templates,
|
|
41
|
+
useInteractiveMode: false,
|
|
42
|
+
});
|
|
43
|
+
const written = await (0, promises_1.readFile)(configPath, 'utf8');
|
|
44
|
+
node_assert_1.default.match(written, /"input"/);
|
|
45
|
+
node_assert_1.default.match(written, /"output"/);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/cli/initOpenApiConfig/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAWzC;;GAEG;AACH,wBAAsB,IAAI,CAAC,OAAO,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/cli/initOpenApiConfig/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAWzC;;GAEG;AACH,wBAAsB,IAAI,CAAC,OAAO,EAAE,YAAY,iBA0D/C"}
|
|
@@ -43,6 +43,7 @@ async function init(options) {
|
|
|
43
43
|
await (0, initCustomRequest_1.initCustomRequest)({
|
|
44
44
|
templates,
|
|
45
45
|
useCancelableRequest: validatedOptions?.useCancelableRequest,
|
|
46
|
+
useRequestRaw: validatedOptions?.useRequestRaw,
|
|
46
47
|
customRequestPath: validatedOptions.request,
|
|
47
48
|
useInteractiveMode: validatedOptions.useInteractiveMode,
|
|
48
49
|
});
|
|
@@ -59,6 +60,7 @@ async function init(options) {
|
|
|
59
60
|
await (0, initCustomRequest_1.initCustomRequest)({
|
|
60
61
|
templates,
|
|
61
62
|
useCancelableRequest: validatedOptions?.useCancelableRequest,
|
|
63
|
+
useRequestRaw: validatedOptions?.useRequestRaw,
|
|
62
64
|
customRequestPath: validatedOptions.request,
|
|
63
65
|
useInteractiveMode: validatedOptions.useInteractiveMode,
|
|
64
66
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initCustomRequest.d.ts","sourceRoot":"","sources":["../../../src/cli/initOpenApiConfig/initCustomRequest.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,KAAK,uBAAuB,GAAG;IAC3B,SAAS,EAAE,YAAY,CAAC;IACxB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAEF,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"initCustomRequest.d.ts","sourceRoot":"","sources":["../../../src/cli/initOpenApiConfig/initCustomRequest.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,KAAK,uBAAuB,GAAG;IAC3B,SAAS,EAAE,YAAY,CAAC;IACxB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAEF,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,uBAAuB,GAAG,OAAO,CAAC,IAAI,CAAC,CAmDtF"}
|
|
@@ -12,7 +12,7 @@ const format_1 = require("../../common/utils/format");
|
|
|
12
12
|
const pathHelpers_1 = require("../../common/utils/pathHelpers");
|
|
13
13
|
const confirmDialog_1 = require("../interactive/confirmDialog");
|
|
14
14
|
async function initCustomRequest(params) {
|
|
15
|
-
const { templates, useCancelableRequest, customRequestPath, useInteractiveMode } = params;
|
|
15
|
+
const { templates, useCancelableRequest, useRequestRaw, customRequestPath, useInteractiveMode } = params;
|
|
16
16
|
if (!customRequestPath) {
|
|
17
17
|
Consts_1.APP_LOGGER.warn(LoggerMessages_1.LOGGER_MESSAGES.CUSTOM_REQUEST.PATH_NOT_PROVIDED);
|
|
18
18
|
return;
|
|
@@ -25,6 +25,7 @@ async function initCustomRequest(params) {
|
|
|
25
25
|
: false;
|
|
26
26
|
const artifacts = {
|
|
27
27
|
useCancelableRequest,
|
|
28
|
+
useRequestRaw,
|
|
28
29
|
};
|
|
29
30
|
const file = (0, pathHelpers_1.resolveHelper)(process.cwd(), customRequestPath);
|
|
30
31
|
const fileDir = path_1.default.dirname(file);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildConfig.test.d.ts","sourceRoot":"","sources":["../../../../../src/cli/initOpenApiConfig/utils/__tests__/buildConfig.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
7
|
+
const node_test_1 = require("node:test");
|
|
8
|
+
const Consts_1 = require("../../../../common/Consts");
|
|
9
|
+
const buildConfig_1 = require("../buildConfig");
|
|
10
|
+
const createMockSpec = (relativePath = './test/spec.yml') => ({
|
|
11
|
+
relativePath,
|
|
12
|
+
path: '',
|
|
13
|
+
});
|
|
14
|
+
(0, node_test_1.describe)('@unit: buildConfig', () => {
|
|
15
|
+
(0, node_test_1.test)('creates items array for multiple specs in multi-option mode', async () => {
|
|
16
|
+
const validatedSpecs = [
|
|
17
|
+
createMockSpec('./api/v1.yml'),
|
|
18
|
+
createMockSpec('./api/v2.yml'),
|
|
19
|
+
];
|
|
20
|
+
const result = await (0, buildConfig_1.buildConfig)(validatedSpecs, true);
|
|
21
|
+
node_assert_1.default.strictEqual(result.items?.length, 2);
|
|
22
|
+
node_assert_1.default.strictEqual(result.items?.[0].input, './api/v1.yml');
|
|
23
|
+
node_assert_1.default.strictEqual(result.items?.[1].input, './api/v2.yml');
|
|
24
|
+
node_assert_1.default.strictEqual(result.items?.[0].output, Consts_1.DEFAULT_OUTPUT_API_DIR);
|
|
25
|
+
node_assert_1.default.strictEqual(result.items?.[1].output, Consts_1.DEFAULT_OUTPUT_API_DIR);
|
|
26
|
+
});
|
|
27
|
+
(0, node_test_1.test)('includes per-item request when perSpecRequest is enabled', async () => {
|
|
28
|
+
const validatedSpecs = [createMockSpec()];
|
|
29
|
+
const customRequest = './custom/request.ts';
|
|
30
|
+
const result = await (0, buildConfig_1.buildConfig)(validatedSpecs, true, customRequest, true);
|
|
31
|
+
node_assert_1.default.strictEqual(result.items?.[0].request, customRequest);
|
|
32
|
+
node_assert_1.default.strictEqual(result.request, undefined);
|
|
33
|
+
});
|
|
34
|
+
(0, node_test_1.test)('includes root request when perSpecRequest is disabled', async () => {
|
|
35
|
+
const validatedSpecs = [createMockSpec()];
|
|
36
|
+
const customRequest = './custom/request.ts';
|
|
37
|
+
const result = await (0, buildConfig_1.buildConfig)(validatedSpecs, true, customRequest, false);
|
|
38
|
+
node_assert_1.default.strictEqual(result.items?.[0].request, undefined);
|
|
39
|
+
node_assert_1.default.strictEqual(result.request, customRequest);
|
|
40
|
+
});
|
|
41
|
+
(0, node_test_1.test)('sets default values from COMMON_DEFAULT_OPTIONS_VALUES in multi mode', async () => {
|
|
42
|
+
const result = await (0, buildConfig_1.buildConfig)([createMockSpec()], true);
|
|
43
|
+
node_assert_1.default.strictEqual(result.httpClient, Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.httpClient);
|
|
44
|
+
node_assert_1.default.strictEqual(result.sortByRequired, Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.sortByRequired);
|
|
45
|
+
node_assert_1.default.strictEqual(result.enumPrefix, Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.enumPrefix);
|
|
46
|
+
node_assert_1.default.strictEqual(result.excludeCoreServiceFiles, Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.excludeCoreServiceFiles);
|
|
47
|
+
node_assert_1.default.strictEqual(result.interfacePrefix, Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.interfacePrefix);
|
|
48
|
+
node_assert_1.default.strictEqual(result.typePrefix, Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.typePrefix);
|
|
49
|
+
node_assert_1.default.strictEqual(result.useCancelableRequest, Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.useCancelableRequest);
|
|
50
|
+
node_assert_1.default.strictEqual(result.useOptions, Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.useOptions);
|
|
51
|
+
node_assert_1.default.strictEqual(result.useSeparatedIndexes, Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.useSeparatedIndexes);
|
|
52
|
+
node_assert_1.default.strictEqual(result.useUnionTypes, Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.useUnionTypes);
|
|
53
|
+
node_assert_1.default.strictEqual(result.modelsMode, Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.modelsMode);
|
|
54
|
+
node_assert_1.default.strictEqual(result.useHistory, Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.useHistory);
|
|
55
|
+
node_assert_1.default.strictEqual(result.diffReport, Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.diffReport);
|
|
56
|
+
});
|
|
57
|
+
(0, node_test_1.test)('uses first spec for flat config', async () => {
|
|
58
|
+
const validatedSpecs = [
|
|
59
|
+
createMockSpec('./api/v1.yml'),
|
|
60
|
+
createMockSpec('./api/v2.yml'),
|
|
61
|
+
];
|
|
62
|
+
const result = await (0, buildConfig_1.buildConfig)(validatedSpecs, false);
|
|
63
|
+
node_assert_1.default.strictEqual(result.input, './api/v1.yml');
|
|
64
|
+
node_assert_1.default.strictEqual(result.output, Consts_1.DEFAULT_OUTPUT_API_DIR);
|
|
65
|
+
});
|
|
66
|
+
(0, node_test_1.test)('throws when no validated specs in flat mode', async () => {
|
|
67
|
+
await node_assert_1.default.rejects(() => (0, buildConfig_1.buildConfig)([], false), /No validated spec files found/);
|
|
68
|
+
});
|
|
69
|
+
(0, node_test_1.test)('includes request in flat mode', async () => {
|
|
70
|
+
const customRequest = './custom/request.ts';
|
|
71
|
+
const result = await (0, buildConfig_1.buildConfig)([createMockSpec()], false, customRequest);
|
|
72
|
+
node_assert_1.default.strictEqual(result.request, customRequest);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
(0, node_test_1.describe)('@unit: buildExampleConfig', () => {
|
|
76
|
+
(0, node_test_1.test)('creates multi-option example with placeholder spec path', () => {
|
|
77
|
+
const result = (0, buildConfig_1.buildExampleConfig)(true);
|
|
78
|
+
node_assert_1.default.strictEqual(result.items?.length, 1);
|
|
79
|
+
node_assert_1.default.strictEqual(result.items?.[0].input, './openapi/spec.yml');
|
|
80
|
+
node_assert_1.default.strictEqual(result.items?.[0].output, Consts_1.DEFAULT_OUTPUT_API_DIR);
|
|
81
|
+
});
|
|
82
|
+
(0, node_test_1.test)('creates flat example with placeholder spec path', () => {
|
|
83
|
+
const result = (0, buildConfig_1.buildExampleConfig)(false);
|
|
84
|
+
node_assert_1.default.strictEqual(result.input, './openapi/spec.yml');
|
|
85
|
+
node_assert_1.default.strictEqual(result.output, Consts_1.DEFAULT_OUTPUT_API_DIR);
|
|
86
|
+
});
|
|
87
|
+
(0, node_test_1.test)('includes root request for multi-option when not perSpecRequest', () => {
|
|
88
|
+
const customRequest = './custom/request.ts';
|
|
89
|
+
const result = (0, buildConfig_1.buildExampleConfig)(true, customRequest, false);
|
|
90
|
+
node_assert_1.default.strictEqual(result.request, customRequest);
|
|
91
|
+
node_assert_1.default.strictEqual(result.items?.[0].request, undefined);
|
|
92
|
+
});
|
|
93
|
+
(0, node_test_1.test)('includes per-item request when perSpecRequest is true', () => {
|
|
94
|
+
const customRequest = './custom/request.ts';
|
|
95
|
+
const result = (0, buildConfig_1.buildExampleConfig)(true, customRequest, true);
|
|
96
|
+
node_assert_1.default.strictEqual(result.request, undefined);
|
|
97
|
+
node_assert_1.default.strictEqual(result.items?.[0].request, customRequest);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findSpecFiles.test.d.ts","sourceRoot":"","sources":["../../../../../src/cli/initOpenApiConfig/utils/__tests__/findSpecFiles.test.ts"],"names":[],"mappings":""}
|