ts-openapi-codegen 2.0.0-beta.9 → 2.0.0
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 +88 -18
- package/README.rus.md +88 -21
- package/dist/cli/checkAndUpdateConfig/utils/validateAndMigrateConfigData.d.ts.map +1 -1
- package/dist/cli/checkAndUpdateConfig/utils/validateAndMigrateConfigData.js +5 -0
- package/dist/cli/generateOpenApiClient/generateOpenApiClient.d.ts.map +1 -1
- package/dist/cli/generateOpenApiClient/generateOpenApiClient.js +20 -8
- package/dist/cli/index.js +5 -3
- package/dist/cli/previewChanges/previewChanges.d.ts.map +1 -1
- package/dist/cli/previewChanges/previewChanges.js +116 -32
- package/dist/cli/previewChanges/utils/updateOutputPaths.d.ts.map +1 -1
- package/dist/cli/previewChanges/utils/updateOutputPaths.js +6 -0
- package/dist/common/Consts.d.ts.map +1 -1
- package/dist/common/Consts.js +4 -1
- package/dist/common/LoggerMessages.d.ts +1 -0
- package/dist/common/LoggerMessages.d.ts.map +1 -1
- package/dist/common/LoggerMessages.js +1 -0
- package/dist/common/VersionedSchema/AllVersionedSchemas/AllMigrationPlans.d.ts +1 -1
- package/dist/common/VersionedSchema/AllVersionedSchemas/AllMigrationPlans.d.ts.map +1 -1
- package/dist/common/VersionedSchema/AllVersionedSchemas/AllMigrationPlans.js +14 -4
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV1.d.ts +2 -2
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV2.d.ts +2 -2
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV3.d.ts +2 -2
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV4.d.ts +42 -0
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV4.d.ts.map +1 -0
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedOptionsSchemaV4.js +38 -0
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedVersionedSchemas.d.ts +155 -28
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedVersionedSchemas.d.ts.map +1 -1
- package/dist/common/VersionedSchema/AllVersionedSchemas/UnifiedVersionedSchemas.js +13 -17
- package/dist/common/VersionedSchema/CommonSchemas.d.ts +12 -4
- package/dist/common/VersionedSchema/CommonSchemas.d.ts.map +1 -1
- package/dist/common/VersionedSchema/CommonSchemas.js +15 -7
- package/dist/common/VersionedSchema/MultiOptionsVersioned/MultiOptionsSchemaV1.d.ts +2 -2
- package/dist/common/VersionedSchema/MultiOptionsVersioned/MultiOptionsSchemaV4.d.ts +2 -2
- package/dist/common/VersionedSchema/MultiOptionsVersioned/MultiOptionsSchemaV5.d.ts +2 -2
- package/dist/common/VersionedSchema/OptionsVersioned/OptionsSchemaV1.d.ts +2 -2
- package/dist/common/VersionedSchema/OptionsVersioned/OptionsSchemaV4.d.ts +2 -2
- package/dist/common/VersionedSchema/Utils/__mocks__/compatibilityCases.d.ts.map +1 -1
- package/dist/common/VersionedSchema/Utils/__mocks__/compatibilityCases.js +19 -0
- package/dist/common/VersionedSchema/Utils/__tests__/allUtils.test.d.ts +2 -0
- package/dist/common/VersionedSchema/Utils/__tests__/allUtils.test.d.ts.map +1 -0
- package/dist/common/VersionedSchema/Utils/__tests__/allUtils.test.js +185 -0
- package/dist/common/VersionedSchema/Utils/__tests__/compareShapes.test.js +20 -3
- package/dist/common/VersionedSchema/Utils/__tests__/migrateDataToLatestSchemaVersion.test.js +19 -1
- package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.d.ts +4 -0
- package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.d.ts.map +1 -1
- package/dist/common/VersionedSchema/Utils/determineBestMatchingSchemaVersion.js +68 -23
- package/dist/common/VersionedSchema/Utils/getUniqueKeysFromSchemas.d.ts +1 -1
- package/dist/common/VersionedSchema/Utils/getUniqueKeysFromSchemas.js +1 -1
- package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.d.ts +10 -0
- package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.d.ts.map +1 -1
- package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.js +33 -15
- package/dist/common/utils/__tests__/convertArrayToObject.test.js +64 -169
- package/dist/common/utils/convertArrayToObject.d.ts.map +1 -1
- package/dist/common/utils/convertArrayToObject.js +51 -14
- package/dist/core/OpenApiClient.d.ts.map +1 -1
- package/dist/core/OpenApiClient.js +12 -1
- package/dist/core/WriteClient.d.ts +8 -1
- package/dist/core/WriteClient.d.ts.map +1 -1
- package/dist/core/WriteClient.js +48 -7
- package/dist/core/__tests__/WriteClient.test.js +2 -0
- package/dist/core/api/v2/parser/getType.d.ts.map +1 -1
- package/dist/core/api/v2/parser/getType.js +2 -1
- package/dist/core/api/v3/parser/getType.d.ts.map +1 -1
- package/dist/core/api/v3/parser/getType.js +2 -1
- package/dist/core/types/base/Templates.model.d.ts +1 -1
- package/dist/core/types/base/Templates.model.d.ts.map +1 -1
- package/dist/core/types/enums/EmptySchemaStrategy.enum.d.ts +6 -0
- package/dist/core/types/enums/EmptySchemaStrategy.enum.d.ts.map +1 -0
- package/dist/core/types/enums/EmptySchemaStrategy.enum.js +9 -0
- package/dist/core/utils/__tests__/getRelativeModelPath.test.d.ts +2 -0
- package/dist/core/utils/__tests__/getRelativeModelPath.test.d.ts.map +1 -0
- package/dist/core/utils/__tests__/getRelativeModelPath.test.js +27 -0
- package/dist/core/utils/__tests__/modelHelpers.test.d.ts +2 -0
- package/dist/core/utils/__tests__/modelHelpers.test.d.ts.map +1 -0
- package/dist/core/utils/__tests__/modelHelpers.test.js +151 -0
- package/dist/core/utils/__tests__/postProcessModelImports.test.d.ts +2 -0
- package/dist/core/utils/__tests__/postProcessModelImports.test.d.ts.map +1 -0
- package/dist/core/utils/__tests__/postProcessModelImports.test.js +67 -0
- package/dist/core/utils/__tests__/postProcessServiceImports.test.d.ts +2 -0
- package/dist/core/utils/__tests__/postProcessServiceImports.test.d.ts.map +1 -0
- package/dist/core/utils/__tests__/postProcessServiceImports.test.js +26 -0
- package/dist/core/utils/__tests__/resolveRefPath.test.d.ts +2 -0
- package/dist/core/utils/__tests__/resolveRefPath.test.d.ts.map +1 -0
- package/dist/core/utils/__tests__/resolveRefPath.test.js +22 -0
- package/dist/core/utils/__tests__/serviceHelpers.test.d.ts +2 -0
- package/dist/core/utils/__tests__/serviceHelpers.test.d.ts.map +1 -0
- package/dist/core/utils/__tests__/serviceHelpers.test.js +121 -0
- package/dist/core/utils/__tests__/writeClientExecutor.test.d.ts +2 -0
- package/dist/core/utils/__tests__/writeClientExecutor.test.d.ts.map +1 -0
- package/dist/core/utils/__tests__/writeClientExecutor.test.js +20 -0
- package/dist/core/utils/__tests__/writeClientSchemas.test.js +2 -0
- package/dist/core/utils/getOpenApiSpec.d.ts.map +1 -1
- package/dist/core/utils/getOpenApiSpec.js +14 -1
- package/dist/core/utils/getRelativeModelPath.d.ts +9 -0
- package/dist/core/utils/getRelativeModelPath.d.ts.map +1 -0
- package/dist/core/utils/getRelativeModelPath.js +37 -0
- package/dist/core/utils/modelHelpers.d.ts.map +1 -1
- package/dist/core/utils/modelHelpers.js +37 -3
- package/dist/core/utils/postProcessModelImports.d.ts.map +1 -1
- package/dist/core/utils/postProcessModelImports.js +14 -1
- package/dist/core/utils/postProcessServiceImports.d.ts.map +1 -1
- package/dist/core/utils/postProcessServiceImports.js +1 -2
- package/dist/core/utils/precompileTemplates.js +1 -0
- package/dist/core/utils/registerHandlebarHelpers.d.ts.map +1 -1
- package/dist/core/utils/registerHandlebarHelpers.js +25 -0
- package/dist/core/utils/registerHandlebarTemplates.d.ts.map +1 -1
- package/dist/core/utils/registerHandlebarTemplates.js +42 -41
- package/dist/core/utils/resolveRefPath.d.ts.map +1 -1
- package/dist/core/utils/resolveRefPath.js +1 -4
- package/dist/core/utils/writeClientExecutor.d.ts +4 -1
- package/dist/core/utils/writeClientExecutor.d.ts.map +1 -1
- package/dist/core/utils/writeClientExecutor.js +17 -2
- package/dist/core/utils/writeClientSchemas.d.ts +4 -1
- package/dist/core/utils/writeClientSchemas.d.ts.map +1 -1
- package/dist/core/utils/writeClientSchemas.js +11 -2
- package/dist/templatesCompiled/client/core/ApiError.js +1 -1
- package/dist/templatesCompiled/client/core/ApiResult.js +1 -1
- package/dist/templatesCompiled/client/core/axios/request.js +3 -3
- package/dist/templatesCompiled/client/core/executor/createExecutorAdapter.d.ts +2 -0
- package/dist/templatesCompiled/client/core/executor/createExecutorAdapter.d.ts.map +1 -1
- package/dist/templatesCompiled/client/core/executor/createExecutorAdapter.js +13 -8
- package/dist/templatesCompiled/client/core/executor/requestExecutor.js +1 -1
- package/dist/templatesCompiled/client/core/fetch/request.js +3 -3
- package/dist/templatesCompiled/client/core/functions/catchErrors.js +1 -1
- package/dist/templatesCompiled/client/core/interceptors/withInterceptors.js +1 -1
- package/dist/templatesCompiled/client/core/node/request.js +3 -3
- package/dist/templatesCompiled/client/core/xhr/request.js +3 -3
- package/dist/templatesCompiled/client/exportClient.d.ts +4 -0
- package/dist/templatesCompiled/client/exportClient.d.ts.map +1 -1
- package/dist/templatesCompiled/client/exportClient.js +51 -13
- package/dist/templatesCompiled/client/exportSchema.d.ts +5 -1
- package/dist/templatesCompiled/client/exportSchema.d.ts.map +1 -1
- package/dist/templatesCompiled/client/exportSchema.js +37 -7
- package/dist/templatesCompiled/client/exportService.d.ts +2 -0
- package/dist/templatesCompiled/client/exportService.d.ts.map +1 -1
- package/dist/templatesCompiled/client/exportService.js +70 -30
- package/dist/templatesCompiled/client/indexFull.d.ts +1 -0
- package/dist/templatesCompiled/client/indexFull.d.ts.map +1 -1
- package/dist/templatesCompiled/client/indexFull.js +4 -1
- package/dist/templatesCompiled/client/indexSimple.d.ts +1 -0
- package/dist/templatesCompiled/client/indexSimple.d.ts.map +1 -1
- package/dist/templatesCompiled/client/indexSimple.js +4 -1
- package/dist/templatesCompiled/client/joi/exportSchema.js +5 -5
- package/dist/templatesCompiled/client/joi/partials/joiSchema.js +7 -7
- package/dist/templatesCompiled/client/joi/partials/joiSchemaComposition.js +4 -4
- package/dist/templatesCompiled/client/joi/partials/joiSchemaInterface.d.ts +5 -3
- package/dist/templatesCompiled/client/joi/partials/joiSchemaInterface.d.ts.map +1 -1
- package/dist/templatesCompiled/client/joi/partials/joiSchemaInterface.js +39 -12
- package/dist/templatesCompiled/client/jsonschema/exportSchema.js +5 -5
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchema.js +7 -7
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaArray.js +5 -5
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaComposition.js +2 -2
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaDictionary.js +5 -5
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaInterface.d.ts +3 -1
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaInterface.d.ts.map +1 -1
- package/dist/templatesCompiled/client/jsonschema/partials/jsonschemaSchemaInterface.js +45 -15
- package/dist/templatesCompiled/client/yup/exportSchema.js +3 -3
- package/dist/templatesCompiled/client/yup/partials/yupSchema.js +7 -7
- package/dist/templatesCompiled/client/yup/partials/yupSchemaComposition.js +4 -4
- package/dist/templatesCompiled/client/yup/partials/yupSchemaInterface.d.ts +5 -3
- package/dist/templatesCompiled/client/yup/partials/yupSchemaInterface.d.ts.map +1 -1
- package/dist/templatesCompiled/client/yup/partials/yupSchemaInterface.js +39 -12
- package/dist/templatesCompiled/client/zod/exportSchema.js +3 -3
- package/dist/templatesCompiled/client/zod/partials/zodSchema.js +7 -7
- package/dist/templatesCompiled/client/zod/partials/zodSchemaArray.d.ts +5 -6
- package/dist/templatesCompiled/client/zod/partials/zodSchemaArray.d.ts.map +1 -1
- package/dist/templatesCompiled/client/zod/partials/zodSchemaArray.js +14 -28
- package/dist/templatesCompiled/client/zod/partials/zodSchemaComposition.d.ts +3 -0
- package/dist/templatesCompiled/client/zod/partials/zodSchemaComposition.d.ts.map +1 -1
- package/dist/templatesCompiled/client/zod/partials/zodSchemaComposition.js +32 -8
- package/dist/templatesCompiled/client/zod/partials/zodSchemaDictionary.d.ts +3 -4
- package/dist/templatesCompiled/client/zod/partials/zodSchemaDictionary.d.ts.map +1 -1
- package/dist/templatesCompiled/client/zod/partials/zodSchemaDictionary.js +9 -23
- package/dist/templatesCompiled/client/zod/partials/zodSchemaInterface.d.ts +4 -2
- package/dist/templatesCompiled/client/zod/partials/zodSchemaInterface.d.ts.map +1 -1
- package/dist/templatesCompiled/client/zod/partials/zodSchemaInterface.js +18 -7
- package/package.json +2 -2
- package/dist/common/defaultOptions.d.ts +0 -3
- package/dist/common/defaultOptions.d.ts.map +0 -1
- package/dist/common/defaultOptions.js +0 -28
- package/dist/core/utils/advancedDeduplicatePath.d.ts +0 -5
- package/dist/core/utils/advancedDeduplicatePath.d.ts.map +0 -1
- package/dist/core/utils/advancedDeduplicatePath.js +0 -29
|
@@ -7,67 +7,71 @@ const node_assert_1 = __importDefault(require("node:assert"));
|
|
|
7
7
|
const node_test_1 = require("node:test");
|
|
8
8
|
const convertArrayToObject_1 = require("../convertArrayToObject");
|
|
9
9
|
(0, node_test_1.describe)('@unit: convertArrayToObject', () => {
|
|
10
|
-
(0, node_test_1.test)('
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
const expected = {
|
|
10
|
+
(0, node_test_1.test)('returns default shape for null', () => {
|
|
11
|
+
const result = (0, convertArrayToObject_1.convertArrayToObject)(null);
|
|
12
|
+
node_assert_1.default.deepStrictEqual(result, {
|
|
14
13
|
items: [],
|
|
15
14
|
excludeCoreServiceFiles: undefined,
|
|
16
15
|
request: undefined,
|
|
16
|
+
customExecutorPath: undefined,
|
|
17
17
|
useOptions: undefined,
|
|
18
18
|
useCancelableRequest: undefined,
|
|
19
|
-
};
|
|
20
|
-
|
|
19
|
+
});
|
|
20
|
+
});
|
|
21
|
+
(0, node_test_1.test)('returns default shape for empty array', () => {
|
|
22
|
+
const result = (0, convertArrayToObject_1.convertArrayToObject)([]);
|
|
23
|
+
node_assert_1.default.deepStrictEqual(result, {
|
|
24
|
+
items: [],
|
|
25
|
+
excludeCoreServiceFiles: undefined,
|
|
26
|
+
request: undefined,
|
|
27
|
+
customExecutorPath: undefined,
|
|
28
|
+
useOptions: undefined,
|
|
29
|
+
useCancelableRequest: undefined,
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
(0, node_test_1.test)('passes through object config unchanged', () => {
|
|
33
|
+
const input = { input: './spec.json', output: './generated', httpClient: 'axios' };
|
|
34
|
+
const result = (0, convertArrayToObject_1.convertArrayToObject)(input);
|
|
35
|
+
node_assert_1.default.strictEqual(result, input);
|
|
21
36
|
});
|
|
22
|
-
(0, node_test_1.test)('
|
|
37
|
+
(0, node_test_1.test)('converts legacy array and keeps per-item request/customExecutorPath', () => {
|
|
23
38
|
const input = [
|
|
24
39
|
{
|
|
25
40
|
input: 'url1',
|
|
26
41
|
output: 'res1',
|
|
27
|
-
exportCore: true,
|
|
28
42
|
request: 'req1',
|
|
43
|
+
customExecutorPath: 'exec-1',
|
|
44
|
+
httpClient: 'axios',
|
|
45
|
+
useOptions: true,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
input: 'url2',
|
|
49
|
+
output: 'res2',
|
|
50
|
+
request: 'req2',
|
|
51
|
+
customExecutorPath: 'exec-2',
|
|
52
|
+
httpClient: 'axios',
|
|
29
53
|
useOptions: true,
|
|
30
54
|
},
|
|
31
55
|
];
|
|
32
|
-
const
|
|
33
|
-
|
|
56
|
+
const result = (0, convertArrayToObject_1.convertArrayToObject)(input);
|
|
57
|
+
node_assert_1.default.deepStrictEqual(result, {
|
|
58
|
+
httpClient: 'axios',
|
|
59
|
+
useOptions: true,
|
|
60
|
+
useUnionTypes: undefined,
|
|
34
61
|
excludeCoreServiceFiles: undefined,
|
|
35
|
-
|
|
62
|
+
includeSchemasFiles: undefined,
|
|
36
63
|
interfacePrefix: undefined,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
output: 'res1',
|
|
41
|
-
outputCore: undefined,
|
|
42
|
-
outputServices: undefined,
|
|
43
|
-
outputModels: undefined,
|
|
44
|
-
outputSchemas: undefined,
|
|
45
|
-
},
|
|
46
|
-
],
|
|
64
|
+
enumPrefix: undefined,
|
|
65
|
+
typePrefix: undefined,
|
|
66
|
+
useCancelableRequest: undefined,
|
|
47
67
|
logLevel: undefined,
|
|
48
68
|
logTarget: undefined,
|
|
49
|
-
request: 'req1',
|
|
50
69
|
sortByRequired: undefined,
|
|
51
|
-
typePrefix: undefined,
|
|
52
|
-
useCancelableRequest: undefined,
|
|
53
|
-
useOptions: true,
|
|
54
70
|
useSeparatedIndexes: undefined,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
node_assert_1.default.deepStrictEqual(result, expected);
|
|
60
|
-
});
|
|
61
|
-
(0, node_test_1.test)('Multiple elements with the same outer margins', () => {
|
|
62
|
-
const input = [
|
|
63
|
-
{ input: 'url1', output: 'res1', exportCore: true, request: 'req1', useOptions: true },
|
|
64
|
-
{ input: 'url2', output: 'res2', exportCore: true, request: 'req1', useOptions: true },
|
|
65
|
-
];
|
|
66
|
-
const expected = {
|
|
67
|
-
enumPrefix: undefined,
|
|
68
|
-
excludeCoreServiceFiles: undefined,
|
|
69
|
-
httpClient: undefined,
|
|
70
|
-
interfacePrefix: undefined,
|
|
71
|
+
validationLibrary: undefined,
|
|
72
|
+
emptySchemaStrategy: undefined,
|
|
73
|
+
request: undefined,
|
|
74
|
+
customExecutorPath: undefined,
|
|
71
75
|
items: [
|
|
72
76
|
{
|
|
73
77
|
input: 'url1',
|
|
@@ -76,6 +80,8 @@ const convertArrayToObject_1 = require("../convertArrayToObject");
|
|
|
76
80
|
outputServices: undefined,
|
|
77
81
|
outputModels: undefined,
|
|
78
82
|
outputSchemas: undefined,
|
|
83
|
+
request: 'req1',
|
|
84
|
+
customExecutorPath: 'exec-1',
|
|
79
85
|
},
|
|
80
86
|
{
|
|
81
87
|
input: 'url2',
|
|
@@ -84,146 +90,35 @@ const convertArrayToObject_1 = require("../convertArrayToObject");
|
|
|
84
90
|
outputServices: undefined,
|
|
85
91
|
outputModels: undefined,
|
|
86
92
|
outputSchemas: undefined,
|
|
93
|
+
request: 'req2',
|
|
94
|
+
customExecutorPath: 'exec-2',
|
|
87
95
|
},
|
|
88
96
|
],
|
|
89
|
-
|
|
90
|
-
logTarget: undefined,
|
|
91
|
-
request: 'req1',
|
|
92
|
-
sortByRequired: undefined,
|
|
93
|
-
typePrefix: undefined,
|
|
94
|
-
useCancelableRequest: undefined,
|
|
95
|
-
useOptions: true,
|
|
96
|
-
useSeparatedIndexes: undefined,
|
|
97
|
-
useUnionTypes: undefined,
|
|
98
|
-
validationLibrary: undefined
|
|
99
|
-
};
|
|
100
|
-
const result = (0, convertArrayToObject_1.convertArrayToObject)(input);
|
|
101
|
-
node_assert_1.default.deepStrictEqual(result, expected);
|
|
97
|
+
});
|
|
102
98
|
});
|
|
103
|
-
(0, node_test_1.test)('
|
|
99
|
+
(0, node_test_1.test)('promotes request/customExecutorPath to root when they are equal for all items', () => {
|
|
104
100
|
const input = [
|
|
105
|
-
{ input: 'url1', output: 'res1',
|
|
106
|
-
{ input: 'url2', output: 'res2',
|
|
101
|
+
{ input: 'url1', output: 'res1', request: 'req', customExecutorPath: 'exec' },
|
|
102
|
+
{ input: 'url2', output: 'res2', request: 'req', customExecutorPath: 'exec' },
|
|
107
103
|
];
|
|
108
|
-
const expected = {
|
|
109
|
-
enumPrefix: undefined,
|
|
110
|
-
excludeCoreServiceFiles: undefined,
|
|
111
|
-
httpClient: undefined,
|
|
112
|
-
interfacePrefix: undefined,
|
|
113
|
-
items: [
|
|
114
|
-
{
|
|
115
|
-
input: 'url1',
|
|
116
|
-
output: 'res1',
|
|
117
|
-
outputCore: undefined,
|
|
118
|
-
outputServices: undefined,
|
|
119
|
-
outputModels: undefined,
|
|
120
|
-
outputSchemas: undefined,
|
|
121
|
-
},
|
|
122
|
-
{
|
|
123
|
-
input: 'url2',
|
|
124
|
-
output: 'res2',
|
|
125
|
-
outputCore: undefined,
|
|
126
|
-
outputServices: undefined,
|
|
127
|
-
outputModels: undefined,
|
|
128
|
-
outputSchemas: undefined,
|
|
129
|
-
},
|
|
130
|
-
],
|
|
131
|
-
logLevel: undefined,
|
|
132
|
-
logTarget: undefined,
|
|
133
|
-
request: 'req1',
|
|
134
|
-
sortByRequired: undefined,
|
|
135
|
-
typePrefix: undefined,
|
|
136
|
-
useCancelableRequest: undefined,
|
|
137
|
-
useOptions: true,
|
|
138
|
-
useSeparatedIndexes: undefined,
|
|
139
|
-
useUnionTypes: undefined,
|
|
140
|
-
validationLibrary: undefined
|
|
141
|
-
};
|
|
142
104
|
const result = (0, convertArrayToObject_1.convertArrayToObject)(input);
|
|
143
|
-
node_assert_1.default.
|
|
105
|
+
node_assert_1.default.strictEqual(result.request, 'req');
|
|
106
|
+
node_assert_1.default.strictEqual(result.customExecutorPath, 'exec');
|
|
144
107
|
});
|
|
145
|
-
(0, node_test_1.test)('
|
|
108
|
+
(0, node_test_1.test)('supports legacy "client" alias by normalizing it to httpClient', () => {
|
|
146
109
|
const input = [
|
|
147
|
-
{ input: 'url1', output: 'res1' },
|
|
148
|
-
{ input: 'url2', output: 'res2' },
|
|
110
|
+
{ input: 'url1', output: 'res1', client: 'axios', useOptions: true },
|
|
111
|
+
{ input: 'url2', output: 'res2', client: 'axios', useOptions: true },
|
|
149
112
|
];
|
|
150
|
-
const expected = {
|
|
151
|
-
enumPrefix: undefined,
|
|
152
|
-
excludeCoreServiceFiles: undefined,
|
|
153
|
-
httpClient: undefined,
|
|
154
|
-
interfacePrefix: undefined,
|
|
155
|
-
items: [
|
|
156
|
-
{
|
|
157
|
-
input: 'url1',
|
|
158
|
-
output: 'res1',
|
|
159
|
-
outputCore: undefined,
|
|
160
|
-
outputServices: undefined,
|
|
161
|
-
outputModels: undefined,
|
|
162
|
-
outputSchemas: undefined,
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
input: 'url2',
|
|
166
|
-
output: 'res2',
|
|
167
|
-
outputCore: undefined,
|
|
168
|
-
outputServices: undefined,
|
|
169
|
-
outputModels: undefined,
|
|
170
|
-
outputSchemas: undefined,
|
|
171
|
-
},
|
|
172
|
-
],
|
|
173
|
-
logLevel: undefined,
|
|
174
|
-
logTarget: undefined,
|
|
175
|
-
request: undefined,
|
|
176
|
-
sortByRequired: undefined,
|
|
177
|
-
typePrefix: undefined,
|
|
178
|
-
useCancelableRequest: undefined,
|
|
179
|
-
useOptions: undefined,
|
|
180
|
-
useSeparatedIndexes: undefined,
|
|
181
|
-
useUnionTypes: undefined,
|
|
182
|
-
validationLibrary: undefined
|
|
183
|
-
};
|
|
184
113
|
const result = (0, convertArrayToObject_1.convertArrayToObject)(input);
|
|
185
|
-
node_assert_1.default.
|
|
114
|
+
node_assert_1.default.strictEqual(result.httpClient, 'axios');
|
|
115
|
+
node_assert_1.default.strictEqual(result.useOptions, true);
|
|
186
116
|
});
|
|
187
|
-
(0, node_test_1.test)('
|
|
117
|
+
(0, node_test_1.test)('throws on conflicting root-driven fields', () => {
|
|
188
118
|
const input = [
|
|
189
|
-
{ input: 'url1', output: 'res1',
|
|
190
|
-
{ input: 'url2', output: 'res2',
|
|
119
|
+
{ input: 'url1', output: 'res1', useOptions: true },
|
|
120
|
+
{ input: 'url2', output: 'res2', useOptions: false },
|
|
191
121
|
];
|
|
192
|
-
|
|
193
|
-
enumPrefix: undefined,
|
|
194
|
-
excludeCoreServiceFiles: undefined,
|
|
195
|
-
httpClient: undefined,
|
|
196
|
-
interfacePrefix: undefined,
|
|
197
|
-
items: [
|
|
198
|
-
{
|
|
199
|
-
input: 'url1',
|
|
200
|
-
output: 'res1',
|
|
201
|
-
outputCore: undefined,
|
|
202
|
-
outputServices: undefined,
|
|
203
|
-
outputModels: undefined,
|
|
204
|
-
outputSchemas: undefined,
|
|
205
|
-
},
|
|
206
|
-
{
|
|
207
|
-
input: 'url2',
|
|
208
|
-
output: 'res2',
|
|
209
|
-
outputCore: undefined,
|
|
210
|
-
outputServices: undefined,
|
|
211
|
-
outputModels: undefined,
|
|
212
|
-
outputSchemas: undefined,
|
|
213
|
-
},
|
|
214
|
-
],
|
|
215
|
-
logLevel: undefined,
|
|
216
|
-
logTarget: undefined,
|
|
217
|
-
request: undefined,
|
|
218
|
-
sortByRequired: undefined,
|
|
219
|
-
typePrefix: undefined,
|
|
220
|
-
useCancelableRequest: undefined,
|
|
221
|
-
useOptions: undefined,
|
|
222
|
-
useSeparatedIndexes: undefined,
|
|
223
|
-
useUnionTypes: undefined,
|
|
224
|
-
validationLibrary: undefined
|
|
225
|
-
};
|
|
226
|
-
const result = (0, convertArrayToObject_1.convertArrayToObject)(input);
|
|
227
|
-
node_assert_1.default.deepStrictEqual(result, expected);
|
|
122
|
+
node_assert_1.default.throws(() => (0, convertArrayToObject_1.convertArrayToObject)(input), /conflicting "useOptions" values/);
|
|
228
123
|
});
|
|
229
124
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"convertArrayToObject.d.ts","sourceRoot":"","sources":["../../../src/common/utils/convertArrayToObject.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,
|
|
1
|
+
{"version":3,"file":"convertArrayToObject.d.ts","sourceRoot":"","sources":["../../../src/common/utils/convertArrayToObject.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,GAAG,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CA6GxH"}
|
|
@@ -6,6 +6,7 @@ function convertArrayToObject(optionsArr) {
|
|
|
6
6
|
items: [],
|
|
7
7
|
excludeCoreServiceFiles: undefined,
|
|
8
8
|
request: undefined,
|
|
9
|
+
customExecutorPath: undefined,
|
|
9
10
|
useOptions: undefined,
|
|
10
11
|
useCancelableRequest: undefined,
|
|
11
12
|
};
|
|
@@ -16,21 +17,12 @@ function convertArrayToObject(optionsArr) {
|
|
|
16
17
|
if (optionsArr.length === 0) {
|
|
17
18
|
return emptyResult;
|
|
18
19
|
}
|
|
19
|
-
const
|
|
20
|
-
input: item.input,
|
|
21
|
-
output: item.output,
|
|
22
|
-
outputCore: item.outputCore,
|
|
23
|
-
outputServices: item.outputServices,
|
|
24
|
-
outputModels: item.outputModels,
|
|
25
|
-
outputSchemas: item.outputSchemas,
|
|
26
|
-
}));
|
|
27
|
-
const firstItem = optionsArr[0];
|
|
28
|
-
const fieldsToExtract = [
|
|
20
|
+
const rootDrivenFields = [
|
|
29
21
|
'httpClient',
|
|
30
22
|
'useOptions',
|
|
31
23
|
'useUnionTypes',
|
|
32
24
|
'excludeCoreServiceFiles',
|
|
33
|
-
'
|
|
25
|
+
'includeSchemasFiles',
|
|
34
26
|
'interfacePrefix',
|
|
35
27
|
'enumPrefix',
|
|
36
28
|
'typePrefix',
|
|
@@ -40,13 +32,58 @@ function convertArrayToObject(optionsArr) {
|
|
|
40
32
|
'sortByRequired',
|
|
41
33
|
'useSeparatedIndexes',
|
|
42
34
|
'validationLibrary',
|
|
35
|
+
'emptySchemaStrategy',
|
|
43
36
|
];
|
|
44
|
-
const
|
|
37
|
+
const getNormalizedFieldValue = (item, field) => {
|
|
38
|
+
if (field === 'httpClient') {
|
|
39
|
+
return item.httpClient ?? item.client;
|
|
40
|
+
}
|
|
41
|
+
return item[field];
|
|
42
|
+
};
|
|
43
|
+
const getRootValueOrThrow = (field) => {
|
|
44
|
+
const definedValues = optionsArr
|
|
45
|
+
.map(item => getNormalizedFieldValue(item, field))
|
|
46
|
+
.filter(value => value !== undefined);
|
|
47
|
+
if (definedValues.length === 0) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
const firstValue = definedValues[0];
|
|
51
|
+
const hasConflict = definedValues.some(value => value !== firstValue);
|
|
52
|
+
if (hasConflict) {
|
|
53
|
+
throw new Error(`Legacy array config has conflicting "${field}" values. ` +
|
|
54
|
+
`This option must have the same value for all array items.`);
|
|
55
|
+
}
|
|
56
|
+
return firstValue;
|
|
57
|
+
};
|
|
58
|
+
const getCommonOptionalRootValue = (field) => {
|
|
59
|
+
const definedValues = optionsArr
|
|
60
|
+
.map(item => item[field])
|
|
61
|
+
.filter(value => value !== undefined);
|
|
62
|
+
if (definedValues.length === 0) {
|
|
63
|
+
return undefined;
|
|
64
|
+
}
|
|
65
|
+
const firstValue = definedValues[0];
|
|
66
|
+
const hasConflict = definedValues.some(value => value !== firstValue);
|
|
67
|
+
return hasConflict ? undefined : firstValue;
|
|
68
|
+
};
|
|
69
|
+
const items = optionsArr.map(item => ({
|
|
70
|
+
input: item.input,
|
|
71
|
+
output: item.output,
|
|
72
|
+
outputCore: item.outputCore,
|
|
73
|
+
outputServices: item.outputServices,
|
|
74
|
+
outputModels: item.outputModels,
|
|
75
|
+
outputSchemas: item.outputSchemas,
|
|
76
|
+
request: item.request,
|
|
77
|
+
customExecutorPath: item.customExecutorPath,
|
|
78
|
+
}));
|
|
79
|
+
const extractedRootFields = rootDrivenFields.reduce((acc, field) => ({
|
|
45
80
|
...acc,
|
|
46
|
-
[field]:
|
|
81
|
+
[field]: getRootValueOrThrow(field),
|
|
47
82
|
}), {});
|
|
48
83
|
return {
|
|
49
|
-
...
|
|
84
|
+
...extractedRootFields,
|
|
85
|
+
request: getCommonOptionalRootValue('request'),
|
|
86
|
+
customExecutorPath: getCommonOptionalRootValue('customExecutorPath'),
|
|
50
87
|
items,
|
|
51
88
|
};
|
|
52
89
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenApiClient.d.ts","sourceRoot":"","sources":["../../src/core/OpenApiClient.ts"],"names":[],"mappings":"AAGA,OAAO,EAAgB,WAAW,EAAsB,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"OpenApiClient.d.ts","sourceRoot":"","sources":["../../src/core/OpenApiClient.ts"],"names":[],"mappings":"AAGA,OAAO,EAAgB,WAAW,EAAsB,MAAM,uBAAuB,CAAC;AAgBtF,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,qBAAa,aAAa;IACtB,OAAO,CAAC,YAAY,CAA4B;IAEhD,IAAW,WAAW,gBAKrB;IAED,OAAO,CAAC,gBAAgB;IAuDxB,OAAO,CAAC,gBAAgB;YA4BV,sBAAsB;YAUtB,oBAAoB;YAmCpB,cAAc;IAwFtB,QAAQ,CAAC,UAAU,EAAE,WAAW;CAWzC"}
|
|
@@ -9,6 +9,7 @@ const pathHelpers_1 = require("../common/utils/pathHelpers");
|
|
|
9
9
|
const Parser_1 = require("./api/v2/Parser");
|
|
10
10
|
const Parser_2 = require("./api/v3/Parser");
|
|
11
11
|
const Context_1 = require("./Context");
|
|
12
|
+
const EmptySchemaStrategy_enum_1 = require("./types/enums/EmptySchemaStrategy.enum");
|
|
12
13
|
const ValidationLibrary_enum_1 = require("./types/enums/ValidationLibrary.enum");
|
|
13
14
|
const getOpenApiSpec_1 = require("./utils/getOpenApiSpec");
|
|
14
15
|
const getOpenApiVersion_1 = require("./utils/getOpenApiVersion");
|
|
@@ -31,6 +32,7 @@ class OpenApiClient {
|
|
|
31
32
|
...item,
|
|
32
33
|
httpClient: rawOptions.httpClient,
|
|
33
34
|
request: item.request ?? rawOptions.request, // ?? для fallback на глобальный
|
|
35
|
+
customExecutorPath: rawOptions.customExecutorPath,
|
|
34
36
|
useOptions: rawOptions.useOptions,
|
|
35
37
|
useUnionTypes: rawOptions.useUnionTypes,
|
|
36
38
|
includeSchemasFiles: rawOptions.includeSchemasFiles,
|
|
@@ -44,6 +46,7 @@ class OpenApiClient {
|
|
|
44
46
|
sortByRequired: rawOptions.sortByRequired,
|
|
45
47
|
useSeparatedIndexes: rawOptions.useSeparatedIndexes,
|
|
46
48
|
validationLibrary: rawOptions.validationLibrary,
|
|
49
|
+
emptySchemaStrategy: rawOptions.emptySchemaStrategy,
|
|
47
50
|
}));
|
|
48
51
|
}
|
|
49
52
|
else {
|
|
@@ -62,6 +65,7 @@ class OpenApiClient {
|
|
|
62
65
|
includeSchemasFiles: rawOptions.includeSchemasFiles,
|
|
63
66
|
excludeCoreServiceFiles: rawOptions.excludeCoreServiceFiles,
|
|
64
67
|
request: rawOptions.request,
|
|
68
|
+
customExecutorPath: rawOptions.customExecutorPath,
|
|
65
69
|
interfacePrefix: rawOptions.interfacePrefix,
|
|
66
70
|
enumPrefix: rawOptions.enumPrefix,
|
|
67
71
|
typePrefix: rawOptions.typePrefix,
|
|
@@ -71,6 +75,7 @@ class OpenApiClient {
|
|
|
71
75
|
sortByRequired: rawOptions.sortByRequired,
|
|
72
76
|
useSeparatedIndexes: rawOptions.useSeparatedIndexes,
|
|
73
77
|
validationLibrary: rawOptions.validationLibrary,
|
|
78
|
+
emptySchemaStrategy: rawOptions.emptySchemaStrategy,
|
|
74
79
|
},
|
|
75
80
|
];
|
|
76
81
|
}
|
|
@@ -89,6 +94,7 @@ class OpenApiClient {
|
|
|
89
94
|
includeSchemasFiles: item.includeSchemasFiles ?? Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.includeSchemasFiles,
|
|
90
95
|
excludeCoreServiceFiles: item.excludeCoreServiceFiles ?? Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.excludeCoreServiceFiles,
|
|
91
96
|
request: item.request || Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.request,
|
|
97
|
+
customExecutorPath: item.customExecutorPath || Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.customExecutorPath,
|
|
92
98
|
interfacePrefix: item.interfacePrefix || Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.interfacePrefix,
|
|
93
99
|
enumPrefix: item.enumPrefix || Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.enumPrefix,
|
|
94
100
|
typePrefix: item.typePrefix || Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.typePrefix,
|
|
@@ -98,6 +104,7 @@ class OpenApiClient {
|
|
|
98
104
|
sortByRequired: item.sortByRequired ?? Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.sortByRequired,
|
|
99
105
|
useSeparatedIndexes: item.useSeparatedIndexes ?? Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.useSeparatedIndexes,
|
|
100
106
|
validationLibrary: item.validationLibrary ?? Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.validationLibrary,
|
|
107
|
+
emptySchemaStrategy: item.emptySchemaStrategy ?? Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.emptySchemaStrategy,
|
|
101
108
|
};
|
|
102
109
|
}
|
|
103
110
|
async cleanOutputDirectories(option) {
|
|
@@ -142,7 +149,7 @@ class OpenApiClient {
|
|
|
142
149
|
this.writeClient.logger.shutdownLogger();
|
|
143
150
|
}
|
|
144
151
|
async generateSingle(item) {
|
|
145
|
-
const { input, output, outputCore, outputServices, outputModels, outputSchemas, httpClient, useOptions, useUnionTypes, excludeCoreServiceFiles, request, interfacePrefix, enumPrefix, typePrefix, useCancelableRequest, sortByRequired, useSeparatedIndexes, validationLibrary = ValidationLibrary_enum_1.ValidationLibrary.NONE, } = item;
|
|
152
|
+
const { input, output, outputCore, outputServices, outputModels, outputSchemas, httpClient, useOptions, useUnionTypes, excludeCoreServiceFiles, request, customExecutorPath, interfacePrefix, enumPrefix, typePrefix, useCancelableRequest, sortByRequired, useSeparatedIndexes, validationLibrary = ValidationLibrary_enum_1.ValidationLibrary.NONE, emptySchemaStrategy = EmptySchemaStrategy_enum_1.EmptySchemaStrategy.KEEP, } = item;
|
|
146
153
|
const outputPaths = (0, getOutputPaths_1.getOutputPaths)({
|
|
147
154
|
output,
|
|
148
155
|
outputCore,
|
|
@@ -175,9 +182,11 @@ class OpenApiClient {
|
|
|
175
182
|
useUnionTypes,
|
|
176
183
|
excludeCoreServiceFiles,
|
|
177
184
|
request,
|
|
185
|
+
customExecutorPath,
|
|
178
186
|
useCancelableRequest,
|
|
179
187
|
useSeparatedIndexes,
|
|
180
188
|
validationLibrary,
|
|
189
|
+
emptySchemaStrategy,
|
|
181
190
|
});
|
|
182
191
|
break;
|
|
183
192
|
}
|
|
@@ -194,9 +203,11 @@ class OpenApiClient {
|
|
|
194
203
|
useUnionTypes,
|
|
195
204
|
excludeCoreServiceFiles,
|
|
196
205
|
request,
|
|
206
|
+
customExecutorPath,
|
|
197
207
|
useCancelableRequest,
|
|
198
208
|
useSeparatedIndexes,
|
|
199
209
|
validationLibrary,
|
|
210
|
+
emptySchemaStrategy,
|
|
200
211
|
});
|
|
201
212
|
break;
|
|
202
213
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Logger } from '../common/Logger';
|
|
2
2
|
import { OutputPaths } from './types/base/OutputPaths.model';
|
|
3
3
|
import { Templates } from './types/base/Templates.model';
|
|
4
|
+
import { EmptySchemaStrategy } from './types/enums/EmptySchemaStrategy.enum';
|
|
4
5
|
import { HttpClient } from './types/enums/HttpClient.enum';
|
|
5
6
|
import { ValidationLibrary } from './types/enums/ValidationLibrary.enum';
|
|
6
7
|
import type { Client } from './types/shared/Client.model';
|
|
8
|
+
import type { Model } from './types/shared/Model.model';
|
|
7
9
|
import { writeClientCore } from './utils/writeClientCore';
|
|
8
10
|
import { writeClientCoreIndex } from './utils/writeClientCoreIndex';
|
|
9
11
|
import { writeClientExecutor } from './utils/writeClientExecutor';
|
|
@@ -37,11 +39,15 @@ type TWriteClientProps = {
|
|
|
37
39
|
useUnionTypes: boolean;
|
|
38
40
|
excludeCoreServiceFiles: boolean;
|
|
39
41
|
request?: string;
|
|
42
|
+
customExecutorPath?: string;
|
|
40
43
|
useCancelableRequest?: boolean;
|
|
41
44
|
useSeparatedIndexes?: boolean;
|
|
42
45
|
validationLibrary?: ValidationLibrary;
|
|
46
|
+
emptySchemaStrategy: EmptySchemaStrategy;
|
|
47
|
+
};
|
|
48
|
+
type TAPIClientGeneratorConfig = Omit<TWriteClientProps, 'httpClient' | 'useOptions' | 'request' | 'useCancelableRequest' | 'useSeparatedIndexes'> & {
|
|
49
|
+
schemaModels: Model[];
|
|
43
50
|
};
|
|
44
|
-
type TAPIClientGeneratorConfig = Omit<TWriteClientProps, 'httpClient' | 'useOptions' | 'request' | 'useCancelableRequest' | 'useSeparatedIndexes'>;
|
|
45
51
|
/**
|
|
46
52
|
* The client which is writing all items and keep the parameters to write index file
|
|
47
53
|
*/
|
|
@@ -53,6 +59,7 @@ export declare class WriteClient {
|
|
|
53
59
|
* Write our OpenAPI client, using the given templates at the given output
|
|
54
60
|
*/
|
|
55
61
|
writeClient(options: TWriteClientProps): Promise<void>;
|
|
62
|
+
private writeModelsAndFinalize;
|
|
56
63
|
/**
|
|
57
64
|
* Method keeps all options that is need to create index file
|
|
58
65
|
* @param config
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WriteClient.d.ts","sourceRoot":"","sources":["../../src/core/WriteClient.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAM1C,OAAO,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAE7D,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"WriteClient.d.ts","sourceRoot":"","sources":["../../src/core/WriteClient.ts"],"names":[],"mappings":"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"}
|
package/dist/core/WriteClient.js
CHANGED
|
@@ -39,7 +39,7 @@ class WriteClient {
|
|
|
39
39
|
* Write our OpenAPI client, using the given templates at the given output
|
|
40
40
|
*/
|
|
41
41
|
async writeClient(options) {
|
|
42
|
-
const { client, templates, outputPaths, httpClient, useOptions, useUnionTypes, excludeCoreServiceFiles = false, request, useCancelableRequest = false, useSeparatedIndexes = false, validationLibrary = ValidationLibrary_enum_1.ValidationLibrary.NONE, } = options;
|
|
42
|
+
const { client, templates, outputPaths, httpClient, useOptions, useUnionTypes, excludeCoreServiceFiles = false, request, customExecutorPath, useCancelableRequest = false, useSeparatedIndexes = false, validationLibrary = ValidationLibrary_enum_1.ValidationLibrary.NONE, emptySchemaStrategy, } = options;
|
|
43
43
|
if (!excludeCoreServiceFiles) {
|
|
44
44
|
const executorPath = (0, pathHelpers_1.resolveHelper)(outputPaths.outputCore, 'executor');
|
|
45
45
|
const interceptorsPath = (0, pathHelpers_1.resolveHelper)(outputPaths.outputCore, 'interceptors');
|
|
@@ -79,6 +79,8 @@ class WriteClient {
|
|
|
79
79
|
outputCorePath: (0, pathHelpers_1.relativeHelper)(outputPaths.output, outputCore),
|
|
80
80
|
services: client.services,
|
|
81
81
|
templates,
|
|
82
|
+
request,
|
|
83
|
+
customExecutorPath,
|
|
82
84
|
});
|
|
83
85
|
}
|
|
84
86
|
/**
|
|
@@ -87,21 +89,58 @@ class WriteClient {
|
|
|
87
89
|
*/
|
|
88
90
|
if (validationLibrary !== ValidationLibrary_enum_1.ValidationLibrary.NONE) {
|
|
89
91
|
await fileSystemHelpers_1.fileSystemHelpers.mkdir(outputPaths.outputSchemas);
|
|
90
|
-
await this.writeClientSchemas({
|
|
92
|
+
const schemaModels = await this.writeClientSchemas({
|
|
91
93
|
models: client.models,
|
|
92
94
|
templates,
|
|
93
95
|
outputSchemasPath: outputPaths.outputSchemas,
|
|
94
96
|
httpClient,
|
|
95
97
|
useUnionTypes,
|
|
96
98
|
validationLibrary,
|
|
99
|
+
emptySchemaStrategy,
|
|
97
100
|
});
|
|
98
101
|
await this.writeClientSchemasIndex({
|
|
99
|
-
models:
|
|
102
|
+
models: schemaModels,
|
|
100
103
|
templates,
|
|
101
104
|
outputSchemasPath: outputPaths.outputSchemas,
|
|
102
105
|
useSeparatedIndexes,
|
|
103
106
|
});
|
|
107
|
+
await this.writeModelsAndFinalize({
|
|
108
|
+
client,
|
|
109
|
+
templates,
|
|
110
|
+
outputPaths,
|
|
111
|
+
httpClient,
|
|
112
|
+
useOptions,
|
|
113
|
+
useUnionTypes,
|
|
114
|
+
excludeCoreServiceFiles,
|
|
115
|
+
request,
|
|
116
|
+
customExecutorPath,
|
|
117
|
+
useCancelableRequest,
|
|
118
|
+
useSeparatedIndexes,
|
|
119
|
+
validationLibrary,
|
|
120
|
+
emptySchemaStrategy,
|
|
121
|
+
schemaModels,
|
|
122
|
+
});
|
|
123
|
+
return;
|
|
104
124
|
}
|
|
125
|
+
await this.writeModelsAndFinalize({
|
|
126
|
+
client,
|
|
127
|
+
templates,
|
|
128
|
+
outputPaths,
|
|
129
|
+
httpClient,
|
|
130
|
+
useOptions,
|
|
131
|
+
useUnionTypes,
|
|
132
|
+
excludeCoreServiceFiles,
|
|
133
|
+
request,
|
|
134
|
+
customExecutorPath,
|
|
135
|
+
useCancelableRequest,
|
|
136
|
+
useSeparatedIndexes,
|
|
137
|
+
validationLibrary,
|
|
138
|
+
emptySchemaStrategy,
|
|
139
|
+
schemaModels: [],
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
async writeModelsAndFinalize(config) {
|
|
143
|
+
const { client, templates, outputPaths, httpClient, useUnionTypes, useSeparatedIndexes, excludeCoreServiceFiles, validationLibrary, emptySchemaStrategy, schemaModels } = config;
|
|
105
144
|
await fileSystemHelpers_1.fileSystemHelpers.mkdir(outputPaths.outputModels);
|
|
106
145
|
await this.writeClientModels({
|
|
107
146
|
models: client.models,
|
|
@@ -124,6 +163,8 @@ class WriteClient {
|
|
|
124
163
|
useUnionTypes,
|
|
125
164
|
excludeCoreServiceFiles,
|
|
126
165
|
validationLibrary,
|
|
166
|
+
emptySchemaStrategy,
|
|
167
|
+
schemaModels,
|
|
127
168
|
});
|
|
128
169
|
}
|
|
129
170
|
/**
|
|
@@ -155,7 +196,7 @@ class WriteClient {
|
|
|
155
196
|
const result = new Map();
|
|
156
197
|
for (const [key, value] of this.config.entries()) {
|
|
157
198
|
for (const item of value) {
|
|
158
|
-
const { outputPaths, templates, excludeCoreServiceFiles, validationLibrary } = item;
|
|
199
|
+
const { outputPaths, templates, excludeCoreServiceFiles, validationLibrary, schemaModels } = item;
|
|
159
200
|
const outputCore = this.getOutputPath(outputPaths?.outputCore, key, 'core');
|
|
160
201
|
const outputModels = this.getOutputPath(outputPaths?.outputModels, key, 'models');
|
|
161
202
|
const outputSchemas = this.getOutputPath(outputPaths?.outputSchemas, key, 'schemas');
|
|
@@ -175,7 +216,7 @@ class WriteClient {
|
|
|
175
216
|
if (!clientIndex.models.includes(relativePathModel)) {
|
|
176
217
|
clientIndex.models.push(relativePathModel);
|
|
177
218
|
}
|
|
178
|
-
if (validationLibrary !== ValidationLibrary_enum_1.ValidationLibrary.NONE) {
|
|
219
|
+
if (validationLibrary !== ValidationLibrary_enum_1.ValidationLibrary.NONE && schemaModels.length > 0) {
|
|
179
220
|
const relativePathSchema = (0, pathHelpers_1.relativeHelper)(key, outputSchemas);
|
|
180
221
|
if (!clientIndex.schemas.includes(relativePathSchema)) {
|
|
181
222
|
clientIndex.schemas.push(relativePathSchema);
|
|
@@ -189,7 +230,7 @@ class WriteClient {
|
|
|
189
230
|
const result = new Map();
|
|
190
231
|
for (const [key, value] of this.config.entries()) {
|
|
191
232
|
for (const item of value) {
|
|
192
|
-
const { outputPaths, client, templates, useUnionTypes, excludeCoreServiceFiles, validationLibrary } = item;
|
|
233
|
+
const { outputPaths, client, templates, useUnionTypes, excludeCoreServiceFiles, validationLibrary, schemaModels } = item;
|
|
193
234
|
const outputCore = this.getOutputPath(outputPaths?.outputCore, key, 'core');
|
|
194
235
|
const outputModels = this.getOutputPath(outputPaths?.outputModels, key, 'models');
|
|
195
236
|
const outputSchemas = this.getOutputPath(outputPaths?.outputSchemas, key, 'schemas');
|
|
@@ -225,7 +266,7 @@ class WriteClient {
|
|
|
225
266
|
if (!clientIndex.models.some(m => this.isSameModel(m, modelFinal))) {
|
|
226
267
|
clientIndex.models.push(modelFinal);
|
|
227
268
|
}
|
|
228
|
-
if (validationLibrary !== ValidationLibrary_enum_1.ValidationLibrary.NONE) {
|
|
269
|
+
if (validationLibrary !== ValidationLibrary_enum_1.ValidationLibrary.NONE && schemaModels.some(schemaModel => schemaModel.name === model.name && schemaModel.path === model.path)) {
|
|
229
270
|
const schema = { ...modelFinal, package: relativePathSchema };
|
|
230
271
|
if (!clientIndex.schemas.some(s => this.isSameShema(s, schema))) {
|
|
231
272
|
clientIndex.schemas.push(schema);
|