ts-openapi-codegen 2.1.0-beta.4 → 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 +11 -957
- package/README.rus.md +11 -957
- 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
|
@@ -0,0 +1,97 @@
|
|
|
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_fs_1 = __importDefault(require("node:fs"));
|
|
8
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
9
|
+
const node_test_1 = require("node:test");
|
|
10
|
+
const Enums_1 = require("../../../common/Enums");
|
|
11
|
+
const Logger_1 = require("../../../common/Logger");
|
|
12
|
+
const loadDiffReport_1 = require("../loadDiffReport");
|
|
13
|
+
const createTempDir = (t, prefix) => {
|
|
14
|
+
const root = node_path_1.default.join(__dirname, 'generated');
|
|
15
|
+
node_fs_1.default.mkdirSync(root, { recursive: true });
|
|
16
|
+
const tempDir = node_fs_1.default.mkdtempSync(node_path_1.default.join(root, prefix));
|
|
17
|
+
t.after(() => {
|
|
18
|
+
node_fs_1.default.rmSync(tempDir, { recursive: true, force: true });
|
|
19
|
+
});
|
|
20
|
+
return tempDir;
|
|
21
|
+
};
|
|
22
|
+
const createLogger = () => new Logger_1.Logger({
|
|
23
|
+
instanceId: 'load-diff-report-test',
|
|
24
|
+
level: Enums_1.ELogLevel.ERROR,
|
|
25
|
+
logOutput: Enums_1.ELogOutput.CONSOLE,
|
|
26
|
+
disableColors: true,
|
|
27
|
+
});
|
|
28
|
+
(0, node_test_1.describe)('@unit: loadDiffReport', () => {
|
|
29
|
+
(0, node_test_1.test)('returns null when history and diffReport path are disabled', () => {
|
|
30
|
+
const result = (0, loadDiffReport_1.loadDiffReport)({
|
|
31
|
+
useHistory: false,
|
|
32
|
+
logger: createLogger(),
|
|
33
|
+
});
|
|
34
|
+
node_assert_1.default.strictEqual(result, null);
|
|
35
|
+
});
|
|
36
|
+
(0, node_test_1.test)('returns null when report file is missing', () => {
|
|
37
|
+
const result = (0, loadDiffReport_1.loadDiffReport)({
|
|
38
|
+
useHistory: true,
|
|
39
|
+
diffReport: node_path_1.default.join(__dirname, 'missing-report.json'),
|
|
40
|
+
logger: createLogger(),
|
|
41
|
+
});
|
|
42
|
+
node_assert_1.default.strictEqual(result, null);
|
|
43
|
+
});
|
|
44
|
+
(0, node_test_1.test)('loads report with diff entries', async (t) => {
|
|
45
|
+
const dir = createTempDir(t, 'diff-report-');
|
|
46
|
+
const reportPath = node_path_1.default.join(dir, 'report.json');
|
|
47
|
+
const report = {
|
|
48
|
+
diff: {
|
|
49
|
+
all: [{ action: 'changed', path: '$.info.version', severity: 'info', from: '1', to: '2' }],
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
node_fs_1.default.writeFileSync(reportPath, JSON.stringify(report), 'utf-8');
|
|
53
|
+
const loaded = (0, loadDiffReport_1.loadDiffReport)({
|
|
54
|
+
diffReport: reportPath,
|
|
55
|
+
logger: createLogger(),
|
|
56
|
+
});
|
|
57
|
+
node_assert_1.default.ok(loaded);
|
|
58
|
+
node_assert_1.default.strictEqual(loaded?.diff?.all?.length, 1);
|
|
59
|
+
});
|
|
60
|
+
(0, node_test_1.test)('returns null for empty report without diff or miracles', async (t) => {
|
|
61
|
+
const dir = createTempDir(t, 'diff-report-empty-');
|
|
62
|
+
const reportPath = node_path_1.default.join(dir, 'empty.json');
|
|
63
|
+
node_fs_1.default.writeFileSync(reportPath, JSON.stringify({ diff: { all: [] }, miracles: [] }), 'utf-8');
|
|
64
|
+
const loaded = (0, loadDiffReport_1.loadDiffReport)({
|
|
65
|
+
diffReport: reportPath,
|
|
66
|
+
logger: createLogger(),
|
|
67
|
+
});
|
|
68
|
+
node_assert_1.default.strictEqual(loaded, null);
|
|
69
|
+
});
|
|
70
|
+
(0, node_test_1.test)('returns null when report is older than input spec', async (t) => {
|
|
71
|
+
const dir = createTempDir(t, 'diff-report-stale-');
|
|
72
|
+
const reportPath = node_path_1.default.join(dir, 'report.json');
|
|
73
|
+
const inputPath = node_path_1.default.join(dir, 'spec.json');
|
|
74
|
+
node_fs_1.default.writeFileSync(reportPath, JSON.stringify({
|
|
75
|
+
diff: { all: [{ action: 'changed', path: '$.info.version', severity: 'info' }] },
|
|
76
|
+
}), 'utf-8');
|
|
77
|
+
const past = Date.now() - 60_000;
|
|
78
|
+
node_fs_1.default.utimesSync(reportPath, past / 1000, past / 1000);
|
|
79
|
+
node_fs_1.default.writeFileSync(inputPath, '{"openapi":"3.0.0"}', 'utf-8');
|
|
80
|
+
const loaded = (0, loadDiffReport_1.loadDiffReport)({
|
|
81
|
+
diffReport: reportPath,
|
|
82
|
+
inputPath,
|
|
83
|
+
logger: createLogger(),
|
|
84
|
+
});
|
|
85
|
+
node_assert_1.default.strictEqual(loaded, null);
|
|
86
|
+
});
|
|
87
|
+
(0, node_test_1.test)('returns null when report JSON is invalid', async (t) => {
|
|
88
|
+
const dir = createTempDir(t, 'diff-report-broken-');
|
|
89
|
+
const reportPath = node_path_1.default.join(dir, 'broken.json');
|
|
90
|
+
node_fs_1.default.writeFileSync(reportPath, '{ not-json', 'utf-8');
|
|
91
|
+
const loaded = (0, loadDiffReport_1.loadDiffReport)({
|
|
92
|
+
diffReport: reportPath,
|
|
93
|
+
logger: createLogger(),
|
|
94
|
+
});
|
|
95
|
+
node_assert_1.default.strictEqual(loaded, null);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templateRendering.test.d.ts","sourceRoot":"","sources":["../../../../src/core/utils/__tests__/templateRendering.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,119 @@
|
|
|
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 HttpClient_enum_1 = require("../../types/enums/HttpClient.enum");
|
|
9
|
+
const ModelsMode_enum_1 = require("../../types/enums/ModelsMode.enum");
|
|
10
|
+
const ValidationLibrary_enum_1 = require("../../types/enums/ValidationLibrary.enum");
|
|
11
|
+
const registerHandlebarTemplates_1 = require("../registerHandlebarTemplates");
|
|
12
|
+
const requestContext = {
|
|
13
|
+
httpClient: HttpClient_enum_1.HttpClient.FETCH,
|
|
14
|
+
server: 'https://api.example.com',
|
|
15
|
+
version: '1.0.0',
|
|
16
|
+
useCancelableRequest: false,
|
|
17
|
+
useSeparatedIndexes: false,
|
|
18
|
+
};
|
|
19
|
+
const schemaModel = {
|
|
20
|
+
name: 'UserSchema',
|
|
21
|
+
alias: '',
|
|
22
|
+
path: 'schemas',
|
|
23
|
+
export: 'interface',
|
|
24
|
+
type: 'UserSchema',
|
|
25
|
+
base: 'UserSchema',
|
|
26
|
+
template: null,
|
|
27
|
+
link: null,
|
|
28
|
+
description: null,
|
|
29
|
+
isDefinition: true,
|
|
30
|
+
isReadOnly: false,
|
|
31
|
+
isRequired: false,
|
|
32
|
+
isNullable: false,
|
|
33
|
+
imports: [],
|
|
34
|
+
enum: [],
|
|
35
|
+
enums: [],
|
|
36
|
+
properties: [
|
|
37
|
+
{
|
|
38
|
+
name: 'id',
|
|
39
|
+
alias: '',
|
|
40
|
+
path: 'schemas',
|
|
41
|
+
export: 'generic',
|
|
42
|
+
type: 'string',
|
|
43
|
+
base: 'string',
|
|
44
|
+
template: null,
|
|
45
|
+
link: null,
|
|
46
|
+
description: null,
|
|
47
|
+
isDefinition: false,
|
|
48
|
+
isReadOnly: false,
|
|
49
|
+
isRequired: true,
|
|
50
|
+
isNullable: false,
|
|
51
|
+
imports: [],
|
|
52
|
+
enum: [],
|
|
53
|
+
enums: [],
|
|
54
|
+
properties: [],
|
|
55
|
+
},
|
|
56
|
+
],
|
|
57
|
+
};
|
|
58
|
+
const exportClientContext = {
|
|
59
|
+
outputCore: './generated/core',
|
|
60
|
+
useCustomRequest: false,
|
|
61
|
+
services: [],
|
|
62
|
+
};
|
|
63
|
+
const exportModelsContext = {
|
|
64
|
+
models: [schemaModel],
|
|
65
|
+
httpClient: HttpClient_enum_1.HttpClient.FETCH,
|
|
66
|
+
useUnionTypes: false,
|
|
67
|
+
useOptions: false,
|
|
68
|
+
outputCore: '../core',
|
|
69
|
+
modelsMode: ModelsMode_enum_1.ModelsMode.CLASSES,
|
|
70
|
+
};
|
|
71
|
+
(0, node_test_1.describe)('@unit: templateRendering', () => {
|
|
72
|
+
for (const httpClient of Object.values(HttpClient_enum_1.HttpClient)) {
|
|
73
|
+
for (const useCancelableRequest of [false, true]) {
|
|
74
|
+
(0, node_test_1.test)(`renders request template for ${httpClient} (cancelable=${useCancelableRequest})`, () => {
|
|
75
|
+
const templates = (0, registerHandlebarTemplates_1.registerHandlebarTemplates)({
|
|
76
|
+
httpClient,
|
|
77
|
+
useOptions: false,
|
|
78
|
+
useUnionTypes: false,
|
|
79
|
+
validationLibrary: ValidationLibrary_enum_1.ValidationLibrary.NONE,
|
|
80
|
+
});
|
|
81
|
+
const output = templates.core.request({
|
|
82
|
+
...requestContext,
|
|
83
|
+
httpClient,
|
|
84
|
+
useCancelableRequest,
|
|
85
|
+
});
|
|
86
|
+
node_assert_1.default.ok(output.length > 100);
|
|
87
|
+
node_assert_1.default.match(output, /function request/i);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
(0, node_test_1.test)('renders exportClient and exportModels templates', () => {
|
|
92
|
+
const templates = (0, registerHandlebarTemplates_1.registerHandlebarTemplates)({
|
|
93
|
+
httpClient: HttpClient_enum_1.HttpClient.FETCH,
|
|
94
|
+
useOptions: false,
|
|
95
|
+
useUnionTypes: false,
|
|
96
|
+
validationLibrary: ValidationLibrary_enum_1.ValidationLibrary.NONE,
|
|
97
|
+
});
|
|
98
|
+
const clientOutput = templates.exports.client(exportClientContext);
|
|
99
|
+
const modelsOutput = templates.exports.models(exportModelsContext);
|
|
100
|
+
node_assert_1.default.match(clientOutput, /createClient|RequestExecutor/i);
|
|
101
|
+
node_assert_1.default.match(modelsOutput, /BaseDto|fromArray/);
|
|
102
|
+
});
|
|
103
|
+
(0, node_test_1.test)('renders schema export with validation library context', () => {
|
|
104
|
+
const templates = (0, registerHandlebarTemplates_1.registerHandlebarTemplates)({
|
|
105
|
+
httpClient: HttpClient_enum_1.HttpClient.FETCH,
|
|
106
|
+
useOptions: false,
|
|
107
|
+
useUnionTypes: false,
|
|
108
|
+
validationLibrary: ValidationLibrary_enum_1.ValidationLibrary.ZOD,
|
|
109
|
+
});
|
|
110
|
+
const output = templates.exports.schema({
|
|
111
|
+
...schemaModel,
|
|
112
|
+
httpClient: HttpClient_enum_1.HttpClient.FETCH,
|
|
113
|
+
useUnionTypes: false,
|
|
114
|
+
validationLibrary: ValidationLibrary_enum_1.ValidationLibrary.ZOD,
|
|
115
|
+
});
|
|
116
|
+
node_assert_1.default.ok(output.length > 20);
|
|
117
|
+
node_assert_1.default.match(output, /UserSchema/i);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
@@ -38,6 +38,7 @@ const templates_1 = require("../__mocks__/templates");
|
|
|
38
38
|
useUnionTypes: false,
|
|
39
39
|
useOptions: false,
|
|
40
40
|
useCancelableRequest: false,
|
|
41
|
+
useRequestRaw: true,
|
|
41
42
|
});
|
|
42
43
|
node_assert_1.default.ok(writeFileCalls.some(([filePath, content]) => filePath.toString().includes('MyService.ts') && content.toString().includes('service')), 'Expected writeFile to be called with service content for MyService.ts');
|
|
43
44
|
// Restoring the original function
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writeFileIfChanged.test.d.ts","sourceRoot":"","sources":["../../../../src/core/utils/__tests__/writeFileIfChanged.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 strict_1 = __importDefault(require("node:assert/strict"));
|
|
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 writeFileIfChanged_1 = require("../writeFileIfChanged");
|
|
12
|
+
(0, node_test_1.describe)('@unit: writeFileIfChanged', () => {
|
|
13
|
+
(0, node_test_1.test)('writes new file and skips unchanged content', async () => {
|
|
14
|
+
const dir = await (0, promises_1.mkdtemp)((0, node_path_1.join)((0, node_os_1.tmpdir)(), 'openapi-codegen-'));
|
|
15
|
+
const file = (0, node_path_1.join)(dir, 'index.ts');
|
|
16
|
+
try {
|
|
17
|
+
const firstResult = await (0, writeFileIfChanged_1.writeFileIfChanged)(file, 'export const a = 1;\n');
|
|
18
|
+
const secondResult = await (0, writeFileIfChanged_1.writeFileIfChanged)(file, 'export const a = 1;\n');
|
|
19
|
+
const thirdResult = await (0, writeFileIfChanged_1.writeFileIfChanged)(file, 'export const a = 2;\n');
|
|
20
|
+
const content = await (0, promises_1.readFile)(file, 'utf8');
|
|
21
|
+
strict_1.default.equal(firstResult, 'written');
|
|
22
|
+
strict_1.default.equal(secondResult, 'unchanged');
|
|
23
|
+
strict_1.default.equal(thirdResult, 'written');
|
|
24
|
+
strict_1.default.equal(content, 'export const a = 2;\n');
|
|
25
|
+
}
|
|
26
|
+
finally {
|
|
27
|
+
await (0, promises_1.rm)(dir, { recursive: true, force: true });
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -10,6 +10,7 @@ import { WriteClient } from '../WriteClient';
|
|
|
10
10
|
* @param httpClient The selected httpClient (fetch, xhr or node)
|
|
11
11
|
* @param request: Path to custom request file
|
|
12
12
|
* @param useCancelableRequest Use cancelable request type
|
|
13
|
+
* @param useRequestRaw Generate requestRaw and raw service methods
|
|
13
14
|
*/
|
|
14
15
|
interface IWriteClientCore {
|
|
15
16
|
client: Client;
|
|
@@ -18,6 +19,7 @@ interface IWriteClientCore {
|
|
|
18
19
|
httpClient: HttpClient;
|
|
19
20
|
request?: string;
|
|
20
21
|
useCancelableRequest?: boolean;
|
|
22
|
+
useRequestRaw?: boolean;
|
|
21
23
|
useSeparatedIndexes?: boolean;
|
|
22
24
|
modelsMode?: ModelsMode;
|
|
23
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeClientCore.d.ts","sourceRoot":"","sources":["../../../src/core/utils/writeClientCore.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C
|
|
1
|
+
{"version":3,"file":"writeClientCore.d.ts","sourceRoot":"","sources":["../../../src/core/utils/writeClientCore.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;;;;;GAQG;AACH,UAAU,gBAAgB;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,SAAS,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,UAAU,EAAE,UAAU,CAAC;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,UAAU,CAAC,EAAE,UAAU,CAAC;CAC3B;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CA+CjG"}
|
|
@@ -14,12 +14,13 @@ const ModelsMode_enum_1 = require("../types/enums/ModelsMode.enum");
|
|
|
14
14
|
* @param useCancelableRequest Use cancelable request type
|
|
15
15
|
*/
|
|
16
16
|
async function writeClientCore(options) {
|
|
17
|
-
const { client, templates, outputCorePath, httpClient, request, useCancelableRequest, useSeparatedIndexes, modelsMode } = options;
|
|
17
|
+
const { client, templates, outputCorePath, httpClient, request, useCancelableRequest, useRequestRaw = true, useSeparatedIndexes, modelsMode } = options;
|
|
18
18
|
const context = {
|
|
19
19
|
httpClient,
|
|
20
20
|
server: client.server,
|
|
21
21
|
version: client.version,
|
|
22
22
|
useCancelableRequest,
|
|
23
|
+
useRequestRaw,
|
|
23
24
|
useSeparatedIndexes,
|
|
24
25
|
};
|
|
25
26
|
this.logger.info("The recording of the kernel files begins");
|
|
@@ -37,11 +38,11 @@ async function writeClientCore(options) {
|
|
|
37
38
|
}
|
|
38
39
|
await fileSystemHelpers_1.fileSystemHelpers.writeFile((0, pathHelpers_1.resolveHelper)(outputCorePath, 'HttpStatusCode.ts'), templates.core.httpStatusCode({}));
|
|
39
40
|
await fileSystemHelpers_1.fileSystemHelpers.writeFile((0, pathHelpers_1.resolveHelper)(outputCorePath, 'request.ts'), templates.core.request(context));
|
|
40
|
-
await fileSystemHelpers_1.fileSystemHelpers.writeFile((0, pathHelpers_1.resolveHelper)(outputCorePath, 'executor/requestExecutor.ts'), templates.core.requestExecutor({}));
|
|
41
|
-
await fileSystemHelpers_1.fileSystemHelpers.writeFile((0, pathHelpers_1.resolveHelper)(outputCorePath, 'executor/createExecutorAdapter.ts'), templates.core.createExecutorAdapter({ useCustomRequest: hasCustomRequest }));
|
|
41
|
+
await fileSystemHelpers_1.fileSystemHelpers.writeFile((0, pathHelpers_1.resolveHelper)(outputCorePath, 'executor/requestExecutor.ts'), templates.core.requestExecutor({ useRequestRaw }));
|
|
42
|
+
await fileSystemHelpers_1.fileSystemHelpers.writeFile((0, pathHelpers_1.resolveHelper)(outputCorePath, 'executor/createExecutorAdapter.ts'), templates.core.createExecutorAdapter({ useCustomRequest: hasCustomRequest, useRequestRaw }));
|
|
42
43
|
await fileSystemHelpers_1.fileSystemHelpers.writeFile((0, pathHelpers_1.resolveHelper)(outputCorePath, 'interceptors/interceptors.ts'), templates.core.interceptors({}));
|
|
43
44
|
await fileSystemHelpers_1.fileSystemHelpers.writeFile((0, pathHelpers_1.resolveHelper)(outputCorePath, 'interceptors/apiErrorInterceptor.ts'), templates.core.apiErrorInterceptor({}));
|
|
44
|
-
await fileSystemHelpers_1.fileSystemHelpers.writeFile((0, pathHelpers_1.resolveHelper)(outputCorePath, 'interceptors/withInterceptors.ts'), templates.core.withInterceptors({}));
|
|
45
|
+
await fileSystemHelpers_1.fileSystemHelpers.writeFile((0, pathHelpers_1.resolveHelper)(outputCorePath, 'interceptors/withInterceptors.ts'), templates.core.withInterceptors({ useRequestRaw }));
|
|
45
46
|
if (hasCustomRequest) {
|
|
46
47
|
const requestFile = (0, pathHelpers_1.resolveHelper)(process.cwd(), request);
|
|
47
48
|
const requestFileExists = await fileSystemHelpers_1.fileSystemHelpers.exists(requestFile);
|
|
@@ -12,6 +12,7 @@ type TServeceOutputsPath = Omit<OutputPaths, 'output' | 'outputSchemas'>;
|
|
|
12
12
|
* @param useUnionTypes Use union types instead of enums
|
|
13
13
|
* @param useOptions Use options or arguments functions
|
|
14
14
|
* @param useCancelableRequest Use cancelable request type
|
|
15
|
+
* @param useRequestRaw Generate *Raw service methods
|
|
15
16
|
*/
|
|
16
17
|
interface IWriteClientServices {
|
|
17
18
|
services: Service[];
|
|
@@ -21,6 +22,7 @@ interface IWriteClientServices {
|
|
|
21
22
|
useUnionTypes: boolean;
|
|
22
23
|
useOptions: boolean;
|
|
23
24
|
useCancelableRequest: boolean;
|
|
25
|
+
useRequestRaw: boolean;
|
|
24
26
|
useProjectPrettier?: boolean;
|
|
25
27
|
useEslintFix?: boolean;
|
|
26
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeClientServices.d.ts","sourceRoot":"","sources":["../../../src/core/utils/writeClientServices.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,KAAK,mBAAmB,GAAG,IAAI,CAAC,WAAW,EAAE,QAAQ,GAAG,eAAe,CAAC,CAAC;AAEzE
|
|
1
|
+
{"version":3,"file":"writeClientServices.d.ts","sourceRoot":"","sources":["../../../src/core/utils/writeClientServices.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,KAAK,mBAAmB,GAAG,IAAI,CAAC,WAAW,EAAE,QAAQ,GAAG,eAAe,CAAC,CAAC;AAEzE;;;;;;;;;GASG;AACH,UAAU,oBAAoB;IAC1B,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,SAAS,EAAE,SAAS,CAAC;IACrB,WAAW,EAAE,mBAAmB,CAAC;IACjC,UAAU,EAAE,UAAU,CAAC;IACvB,aAAa,EAAE,OAAO,CAAC;IACvB,UAAU,EAAE,OAAO,CAAC;IACpB,oBAAoB,EAAE,OAAO,CAAC;IAC9B,aAAa,EAAE,OAAO,CAAC;IACvB,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,YAAY,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CA8BzG"}
|
|
@@ -15,7 +15,7 @@ const pathHelpers_1 = require("../../common/utils/pathHelpers");
|
|
|
15
15
|
* @param useOptions Use options or arguments functions
|
|
16
16
|
*/
|
|
17
17
|
async function writeClientServices(options) {
|
|
18
|
-
const { services, templates, outputPaths, httpClient, useUnionTypes, useOptions, useCancelableRequest, useProjectPrettier, useEslintFix } = options;
|
|
18
|
+
const { services, templates, outputPaths, httpClient, useUnionTypes, useOptions, useCancelableRequest, useRequestRaw, useProjectPrettier, useEslintFix } = options;
|
|
19
19
|
this.logger.info('Recording of service files begins');
|
|
20
20
|
for (const service of services) {
|
|
21
21
|
const file = (0, pathHelpers_1.resolveHelper)(outputPaths.outputServices, `${service.name}.ts`);
|
|
@@ -28,6 +28,7 @@ async function writeClientServices(options) {
|
|
|
28
28
|
outputCore: outputPaths.outputCore,
|
|
29
29
|
outputModels: outputPaths.outputModels,
|
|
30
30
|
useCancelableRequest,
|
|
31
|
+
useRequestRaw,
|
|
31
32
|
});
|
|
32
33
|
const formattedValue = await (0, format_1.format)(templateResult, undefined, useProjectPrettier);
|
|
33
34
|
await fileSystemHelpers_1.fileSystemHelpers.writeFile(file, formattedValue);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"writeFileIfChanged.d.ts","sourceRoot":"","sources":["../../../src/core/utils/writeFileIfChanged.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,wBAAwB,GAAG,SAAS,GAAG,WAAW,CAAC;AAE/D,wBAAsB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAiBjH"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writeFileIfChanged = writeFileIfChanged;
|
|
4
|
+
const fileSystemHelpers_1 = require("../../common/utils/fileSystemHelpers");
|
|
5
|
+
async function writeFileIfChanged(filePath, nextContent) {
|
|
6
|
+
try {
|
|
7
|
+
const fileExists = await fileSystemHelpers_1.fileSystemHelpers.exists(filePath);
|
|
8
|
+
if (fileExists) {
|
|
9
|
+
const currentContent = await fileSystemHelpers_1.fileSystemHelpers.readFile(filePath, 'utf8');
|
|
10
|
+
if (currentContent === nextContent) {
|
|
11
|
+
return 'unchanged';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
catch (error) {
|
|
16
|
+
if (error?.code !== 'ENOENT') {
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
await fileSystemHelpers_1.fileSystemHelpers.writeFile(filePath, nextContent);
|
|
21
|
+
return 'written';
|
|
22
|
+
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
2
|
"1": (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
|
|
3
|
-
"3": (container: any, depth0: any, helpers: any, partials: any, data: any) =>
|
|
4
|
-
"
|
|
3
|
+
"3": (container: any, depth0: any, helpers: any, partials: any, data: any) => any;
|
|
4
|
+
"4": (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
|
|
5
|
+
"6": (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
|
|
6
|
+
"8": (container: any, depth0: any, helpers: any, partials: any, data: any) => any;
|
|
7
|
+
"9": (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
|
|
8
|
+
"11": (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
|
|
5
9
|
compiler: (string | number)[];
|
|
6
10
|
main: (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
|
|
7
11
|
usePartial: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customRequest.d.ts","sourceRoot":"","sources":["../../../src/templatesCompiled/cli/customRequest.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"customRequest.d.ts","sourceRoot":"","sources":["../../../src/templatesCompiled/cli/customRequest.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAMA,wBAyCmC"}
|
|
@@ -7,11 +7,31 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
/* eslint: disable */
|
|
8
8
|
// @ts-nocheck
|
|
9
9
|
exports.default = { "1": function (container, depth0, helpers, partials, data) {
|
|
10
|
-
return "import
|
|
10
|
+
return "import { CancelablePromise } from './CancelablePromise';\n";
|
|
11
11
|
}, "3": function (container, depth0, helpers, partials, data) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
var stack1, lookupProperty = container.lookupProperty || function (parent, propertyName) {
|
|
13
|
+
if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
|
|
14
|
+
return parent[propertyName];
|
|
15
|
+
}
|
|
16
|
+
return undefined;
|
|
17
|
+
};
|
|
18
|
+
return ((stack1 = lookupProperty(helpers, "if").call(depth0 != null ? depth0 : (container.nullContext || {}), lookupProperty(depth0, "useRequestRaw"), { "name": "if", "hash": {}, "fn": container.program(4, data, 0), "inverse": container.program(6, data, 0), "data": data, "loc": { "start": { "line": 15, "column": 0 }, "end": { "line": 77, "column": 7 } } })) != null ? stack1 : "");
|
|
19
|
+
}, "4": function (container, depth0, helpers, partials, data) {
|
|
20
|
+
return "export function requestRaw<T>(options: ApiRequestOptions, config: TOpenAPIConfig): CancelablePromise<ApiResult<T>> {\n return new CancelablePromise(async (resolve, reject, onCancel) => {\n try {\n if (onCancel.isCancelled) {\n return;\n }\n\n const url = `${config.BASE}${options.path}`.replace('{api-version}', config.VERSION);\n const response = await fetch(url, {\n method: options.method,\n headers: options.headers as Record<string, string> | undefined,\n body: options.body ? JSON.stringify(options.body) : undefined,\n });\n\n const body = (await response.json()) as T;\n resolve({\n url,\n ok: response.ok,\n status: response.status,\n statusText: response.statusText,\n body,\n });\n } catch (error) {\n reject(error);\n }\n });\n}\n\nexport function request<T>(options: ApiRequestOptions, config: TOpenAPIConfig): CancelablePromise<T> {\n return new CancelablePromise(async (resolve, reject, onCancel) => {\n try {\n const result = await requestRaw<T>(options, config);\n if (!onCancel.isCancelled) {\n resolve(result.body);\n }\n } catch (error) {\n reject(error);\n }\n });\n}\n";
|
|
21
|
+
}, "6": function (container, depth0, helpers, partials, data) {
|
|
22
|
+
return "export function request<T>(options: ApiRequestOptions, config: TOpenAPIConfig): CancelablePromise<T> {\n return new CancelablePromise(async (resolve, reject, onCancel) => {\n try {\n if (onCancel.isCancelled) {\n return;\n }\n\n const url = `${config.BASE}${options.path}`.replace('{api-version}', config.VERSION);\n const response = await fetch(url, {\n method: options.method,\n headers: options.headers as Record<string, string> | undefined,\n body: options.body ? JSON.stringify(options.body) : undefined,\n });\n\n resolve((await response.json()) as T);\n } catch (error) {\n reject(error);\n }\n });\n}\n";
|
|
23
|
+
}, "8": function (container, depth0, helpers, partials, data) {
|
|
24
|
+
var stack1, lookupProperty = container.lookupProperty || function (parent, propertyName) {
|
|
25
|
+
if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
|
|
26
|
+
return parent[propertyName];
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
};
|
|
30
|
+
return ((stack1 = lookupProperty(helpers, "if").call(depth0 != null ? depth0 : (container.nullContext || {}), lookupProperty(depth0, "useRequestRaw"), { "name": "if", "hash": {}, "fn": container.program(9, data, 0), "inverse": container.program(11, data, 0), "data": data, "loc": { "start": { "line": 79, "column": 0 }, "end": { "line": 113, "column": 7 } } })) != null ? stack1 : "");
|
|
31
|
+
}, "9": function (container, depth0, helpers, partials, data) {
|
|
32
|
+
return "export async function requestRaw<T>(options: ApiRequestOptions, config: TOpenAPIConfig): Promise<ApiResult<T>> {\n const url = `${config.BASE}${options.path}`.replace('{api-version}', config.VERSION);\n const response = await fetch(url, {\n method: options.method,\n headers: options.headers as Record<string, string> | undefined,\n body: options.body ? JSON.stringify(options.body) : undefined,\n });\n\n const body = (await response.json()) as T;\n return {\n url,\n ok: response.ok,\n status: response.status,\n statusText: response.statusText,\n body,\n };\n}\n\nexport async function request<T>(options: ApiRequestOptions, config: TOpenAPIConfig): Promise<T> {\n const result = await requestRaw<T>(options, config);\n return result.body;\n}\n";
|
|
33
|
+
}, "11": function (container, depth0, helpers, partials, data) {
|
|
34
|
+
return "export async function request<T>(options: ApiRequestOptions, config: TOpenAPIConfig): Promise<T> {\n const url = `${config.BASE}${options.path}`.replace('{api-version}', config.VERSION);\n const response = await fetch(url, {\n method: options.method,\n headers: options.headers as Record<string, string> | undefined,\n body: options.body ? JSON.stringify(options.body) : undefined,\n });\n\n return (await response.json()) as T;\n}\n";
|
|
15
35
|
}, "compiler": [8, ">= 4.3.0"], "main": function (container, depth0, helpers, partials, data) {
|
|
16
36
|
var stack1, alias1 = depth0 != null ? depth0 : (container.nullContext || {}), lookupProperty = container.lookupProperty || function (parent, propertyName) {
|
|
17
37
|
if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
|
|
@@ -20,8 +40,8 @@ exports.default = { "1": function (container, depth0, helpers, partials, data) {
|
|
|
20
40
|
return undefined;
|
|
21
41
|
};
|
|
22
42
|
return ((stack1 = container.invokePartial(lookupProperty(partials, "header"), depth0, { "name": "header", "data": data, "helpers": helpers, "partials": partials, "decorators": container.decorators })) != null ? stack1 : "")
|
|
23
|
-
+ "\nimport type {
|
|
24
|
-
+ ((stack1 = lookupProperty(helpers, "if").call(alias1, lookupProperty(depth0, "useCancelableRequest"), { "name": "if", "hash": {}, "fn": container.program(1, data, 0), "inverse": container.noop, "data": data, "loc": { "start": { "line":
|
|
25
|
-
+ "\n/**\n *
|
|
26
|
-
+ ((stack1 = lookupProperty(helpers, "if").call(alias1, lookupProperty(depth0, "useCancelableRequest"), { "name": "if", "hash": {}, "fn": container.program(3, data, 0), "inverse": container.program(
|
|
43
|
+
+ "\nimport type { ApiRequestOptions } from './ApiRequestOptions';\nimport type { ApiResult } from './ApiResult';\nimport type { TOpenAPIConfig } from './OpenAPI';\n"
|
|
44
|
+
+ ((stack1 = lookupProperty(helpers, "if").call(alias1, lookupProperty(depth0, "useCancelableRequest"), { "name": "if", "hash": {}, "fn": container.program(1, data, 0), "inverse": container.noop, "data": data, "loc": { "start": { "line": 6, "column": 0 }, "end": { "line": 8, "column": 7 } } })) != null ? stack1 : "")
|
|
45
|
+
+ "\n/**\n * Custom request implementation.\n * Wire this file via `request` in openapi.config.json.\n */\n"
|
|
46
|
+
+ ((stack1 = lookupProperty(helpers, "if").call(alias1, lookupProperty(depth0, "useCancelableRequest"), { "name": "if", "hash": {}, "fn": container.program(3, data, 0), "inverse": container.program(8, data, 0), "data": data, "loc": { "start": { "line": 14, "column": 0 }, "end": { "line": 114, "column": 7 } } })) != null ? stack1 : "");
|
|
27
47
|
}, "usePartial": true, "useData": true };
|
|
@@ -2,6 +2,9 @@ declare const _default: {
|
|
|
2
2
|
"1": (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
|
|
3
3
|
"3": (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
|
|
4
4
|
"5": (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
|
|
5
|
+
"6": (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
|
|
6
|
+
"8": (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
|
|
7
|
+
"9": (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
|
|
5
8
|
compiler: (string | number)[];
|
|
6
9
|
main: (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
|
|
7
10
|
usePartial: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"customRequestExecutor.d.ts","sourceRoot":"","sources":["../../../src/templatesCompiled/cli/customRequestExecutor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"customRequestExecutor.d.ts","sourceRoot":"","sources":["../../../src/templatesCompiled/cli/customRequestExecutor.ts"],"names":[],"mappings":";;;;;;;;;;;;AAMA,wBA4CmC"}
|
|
@@ -7,11 +7,33 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
7
7
|
/* eslint: disable */
|
|
8
8
|
// @ts-nocheck
|
|
9
9
|
exports.default = { "1": function (container, depth0, helpers, partials, data) {
|
|
10
|
-
return "import type {
|
|
10
|
+
return "import type { ApiResult } from './ApiResult';\n";
|
|
11
11
|
}, "3": function (container, depth0, helpers, partials, data) {
|
|
12
|
-
return "
|
|
12
|
+
return "import type { CancelablePromise } from './CancelablePromise';\n";
|
|
13
13
|
}, "5": function (container, depth0, helpers, partials, data) {
|
|
14
|
-
|
|
14
|
+
var stack1, lookupProperty = container.lookupProperty || function (parent, propertyName) {
|
|
15
|
+
if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
|
|
16
|
+
return parent[propertyName];
|
|
17
|
+
}
|
|
18
|
+
return undefined;
|
|
19
|
+
};
|
|
20
|
+
return "export const customExecutor: RequestExecutor<MyCustomOptions> = {\n"
|
|
21
|
+
+ ((stack1 = lookupProperty(helpers, "if").call(depth0 != null ? depth0 : (container.nullContext || {}), lookupProperty(depth0, "useRequestRaw"), { "name": "if", "hash": {}, "fn": container.program(6, data, 0), "inverse": container.noop, "data": data, "loc": { "start": { "line": 33, "column": 4 }, "end": { "line": 70, "column": 11 } } })) != null ? stack1 : "")
|
|
22
|
+
+ " request<TResponse>(config: RequestConfig, options?: MyCustomOptions): CancelablePromise<TResponse> {\n return new CancelablePromise(async (resolve, reject, onCancel) => {\n try {\n const abortController = new AbortController();\n\n if (options?.timeout) {\n const timeoutId = setTimeout(() => abortController.abort(), options.timeout);\n onCancel(() => clearTimeout(timeoutId));\n }\n\n onCancel(() => abortController.abort());\n\n if (onCancel.isCancelled) {\n return;\n }\n\n const response = await fetch(`${config.path}`, {\n method: config.method,\n headers: config.headers,\n body: config.body ? JSON.stringify(config.body) : undefined,\n signal: abortController.signal,\n });\n\n if (!response.ok) {\n throw new Error(`Request failed: ${response.statusText}`);\n }\n\n resolve((await response.json()) as TResponse);\n } catch (error) {\n reject(error);\n }\n });\n },\n};\n";
|
|
23
|
+
}, "6": function (container, depth0, helpers, partials, data) {
|
|
24
|
+
return " requestRaw<TResponse>(config: RequestConfig, options?: MyCustomOptions): CancelablePromise<ApiResult<TResponse>> {\n return new CancelablePromise(async (resolve, reject, onCancel) => {\n try {\n const abortController = new AbortController();\n\n if (options?.timeout) {\n const timeoutId = setTimeout(() => abortController.abort(), options.timeout);\n onCancel(() => clearTimeout(timeoutId));\n }\n\n onCancel(() => abortController.abort());\n\n if (onCancel.isCancelled) {\n return;\n }\n\n const response = await fetch(`${config.path}`, {\n method: config.method,\n headers: config.headers,\n body: config.body ? JSON.stringify(config.body) : undefined,\n signal: abortController.signal,\n });\n\n const body = (await response.json()) as TResponse;\n resolve({\n url: response.url,\n ok: response.ok,\n status: response.status,\n statusText: response.statusText,\n body,\n });\n } catch (error) {\n reject(error);\n }\n });\n },\n";
|
|
25
|
+
}, "8": function (container, depth0, helpers, partials, data) {
|
|
26
|
+
var stack1, lookupProperty = container.lookupProperty || function (parent, propertyName) {
|
|
27
|
+
if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
|
|
28
|
+
return parent[propertyName];
|
|
29
|
+
}
|
|
30
|
+
return undefined;
|
|
31
|
+
};
|
|
32
|
+
return "export const customExecutor: RequestExecutor<MyCustomOptions> = {\n"
|
|
33
|
+
+ ((stack1 = lookupProperty(helpers, "if").call(depth0 != null ? depth0 : (container.nullContext || {}), lookupProperty(depth0, "useRequestRaw"), { "name": "if", "hash": {}, "fn": container.program(9, data, 0), "inverse": container.noop, "data": data, "loc": { "start": { "line": 107, "column": 4 }, "end": { "line": 125, "column": 11 } } })) != null ? stack1 : "")
|
|
34
|
+
+ " async request<TResponse>(config: RequestConfig, options?: MyCustomOptions): Promise<TResponse> {\n const response = await fetch(`${config.path}`, {\n method: config.method,\n headers: config.headers,\n body: config.body ? JSON.stringify(config.body) : undefined,\n signal: options?.timeout ? AbortSignal.timeout(options.timeout) : undefined,\n });\n\n if (!response.ok) {\n throw new Error(`Request failed: ${response.statusText}`);\n }\n\n return response.json();\n },\n};\n";
|
|
35
|
+
}, "9": function (container, depth0, helpers, partials, data) {
|
|
36
|
+
return " async requestRaw<TResponse>(config: RequestConfig, options?: MyCustomOptions): Promise<ApiResult<TResponse>> {\n const response = await fetch(`${config.path}`, {\n method: config.method,\n headers: config.headers,\n body: config.body ? JSON.stringify(config.body) : undefined,\n signal: options?.timeout ? AbortSignal.timeout(options.timeout) : undefined,\n });\n\n const body = (await response.json()) as TResponse;\n return {\n url: response.url,\n ok: response.ok,\n status: response.status,\n statusText: response.statusText,\n body,\n };\n },\n";
|
|
15
37
|
}, "compiler": [8, ">= 4.3.0"], "main": function (container, depth0, helpers, partials, data) {
|
|
16
38
|
var stack1, alias1 = depth0 != null ? depth0 : (container.nullContext || {}), lookupProperty = container.lookupProperty || function (parent, propertyName) {
|
|
17
39
|
if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
|
|
@@ -21,7 +43,8 @@ exports.default = { "1": function (container, depth0, helpers, partials, data) {
|
|
|
21
43
|
};
|
|
22
44
|
return ((stack1 = container.invokePartial(lookupProperty(partials, "header"), depth0, { "name": "header", "data": data, "helpers": helpers, "partials": partials, "decorators": container.decorators })) != null ? stack1 : "")
|
|
23
45
|
+ "\nimport type { RequestExecutor, RequestConfig } from './request-executor';\n"
|
|
24
|
-
+ ((stack1 = lookupProperty(helpers, "if").call(alias1, lookupProperty(depth0, "
|
|
46
|
+
+ ((stack1 = lookupProperty(helpers, "if").call(alias1, lookupProperty(depth0, "useRequestRaw"), { "name": "if", "hash": {}, "fn": container.program(1, data, 0), "inverse": container.noop, "data": data, "loc": { "start": { "line": 4, "column": 0 }, "end": { "line": 6, "column": 7 } } })) != null ? stack1 : "")
|
|
47
|
+
+ ((stack1 = lookupProperty(helpers, "if").call(alias1, lookupProperty(depth0, "useCancelableRequest"), { "name": "if", "hash": {}, "fn": container.program(3, data, 0), "inverse": container.noop, "data": data, "loc": { "start": { "line": 7, "column": 0 }, "end": { "line": 9, "column": 7 } } })) != null ? stack1 : "")
|
|
25
48
|
+ "\n/**\n * Определите свой тип опций (опционально)\n * Измените этот интерфейс в соответствии с вашими потребностями\n */\ninterface MyCustomOptions {\n timeout?: number;\n retries?: number;\n}\n\n/**\n * Создайте пользовательский executor\n * Реализуйте свою логику запросов здесь\n *\n * @example Пример использования:\n * \n * import { SimpleService } from './generated/services/SimpleService';\n * \n * const simpleService = new SimpleService<MyCustomOptions>(customExecutor);\n * await simpleService.getCallWithoutParametersAndResponse({ timeout: 5000, retries: 3 });\n */\n"
|
|
26
|
-
+ ((stack1 = lookupProperty(helpers, "if").call(alias1, lookupProperty(depth0, "useCancelableRequest"), { "name": "if", "hash": {}, "fn": container.program(
|
|
49
|
+
+ ((stack1 = lookupProperty(helpers, "if").call(alias1, lookupProperty(depth0, "useCancelableRequest"), { "name": "if", "hash": {}, "fn": container.program(5, data, 0), "inverse": container.program(8, data, 0), "data": data, "loc": { "start": { "line": 31, "column": 0 }, "end": { "line": 141, "column": 7 } } })) != null ? stack1 : "");
|
|
27
50
|
}, "usePartial": true, "useData": true };
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
2
|
"1": (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
|
|
3
|
-
"3": (container: any, depth0: any, helpers: any, partials: any, data: any) =>
|
|
4
|
-
"
|
|
3
|
+
"3": (container: any, depth0: any, helpers: any, partials: any, data: any) => any;
|
|
4
|
+
"4": (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
|
|
5
|
+
"6": (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
|
|
6
|
+
"8": (container: any, depth0: any, helpers: any, partials: any, data: any) => any;
|
|
7
|
+
"9": (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
|
|
8
|
+
"11": (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
|
|
5
9
|
compiler: (string | number)[];
|
|
6
10
|
main: (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
|
|
7
11
|
usePartial: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../../../src/templatesCompiled/client/core/axios/request.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../../../src/templatesCompiled/client/core/axios/request.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAMA,wBAuEmC"}
|