ts-openapi-codegen 1.0.0 → 2.0.0-beta.1

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.
Files changed (84) hide show
  1. package/README.md +74 -0
  2. package/README.rus.md +73 -0
  3. package/dist/cli/generate/runGenerateOpenApi.d.ts.map +1 -1
  4. package/dist/cli/generate/runGenerateOpenApi.js +10 -25
  5. package/dist/common/Consts.d.ts +2 -21
  6. package/dist/common/Consts.d.ts.map +1 -1
  7. package/dist/common/Consts.js +5 -2
  8. package/dist/common/Logger.d.ts.map +1 -1
  9. package/dist/common/Logger.js +3 -2
  10. package/dist/common/LoggerMessages.d.ts +64 -0
  11. package/dist/common/LoggerMessages.d.ts.map +1 -0
  12. package/dist/common/LoggerMessages.js +82 -0
  13. package/dist/common/TRawOptions.d.ts +40 -0
  14. package/dist/common/TRawOptions.d.ts.map +1 -0
  15. package/dist/common/VersionedSchema/AllVersionedSchemas/AllMigrationPlans.d.ts +8 -0
  16. package/dist/common/VersionedSchema/AllVersionedSchemas/AllMigrationPlans.d.ts.map +1 -0
  17. package/dist/common/VersionedSchema/AllVersionedSchemas/AllMigrationPlans.js +31 -0
  18. package/dist/common/VersionedSchema/AllVersionedSchemas/AllVersionedSchemas.d.ts +8 -0
  19. package/dist/common/VersionedSchema/AllVersionedSchemas/AllVersionedSchemas.d.ts.map +1 -0
  20. package/dist/common/VersionedSchema/AllVersionedSchemas/AllVersionedSchemas.js +33 -0
  21. package/dist/common/VersionedSchema/Enums.d.ts +2 -1
  22. package/dist/common/VersionedSchema/Enums.d.ts.map +1 -1
  23. package/dist/common/VersionedSchema/Enums.js +1 -0
  24. package/dist/common/VersionedSchema/MultiOptionsVersioned/MultiOptionsMigrationPlan.d.ts.map +1 -1
  25. package/dist/common/VersionedSchema/MultiOptionsVersioned/MultiOptionsMigrationPlan.js +10 -19
  26. package/dist/common/VersionedSchema/OptionsVersioned/OptionsMigrationPlans.d.ts.map +1 -1
  27. package/dist/common/VersionedSchema/OptionsVersioned/OptionsMigrationPlans.js +10 -10
  28. package/dist/common/VersionedSchema/Types.d.ts +5 -0
  29. package/dist/common/VersionedSchema/Types.d.ts.map +1 -1
  30. package/dist/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsMigrationPlan.d.ts +3 -0
  31. package/dist/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsMigrationPlan.d.ts.map +1 -0
  32. package/dist/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsMigrationPlan.js +28 -0
  33. package/dist/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsSchemaV1.d.ts +7 -0
  34. package/dist/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsSchemaV1.d.ts.map +1 -0
  35. package/dist/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsSchemaV1.js +42 -0
  36. package/dist/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsVersionedSchemas.d.ts +3 -0
  37. package/dist/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsVersionedSchemas.d.ts.map +1 -0
  38. package/dist/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsVersionedSchemas.js +10 -0
  39. package/dist/common/VersionedSchema/Utils/createDefaultFieldsMigration.d.ts +11 -0
  40. package/dist/common/VersionedSchema/Utils/createDefaultFieldsMigration.d.ts.map +1 -0
  41. package/dist/common/VersionedSchema/Utils/createDefaultFieldsMigration.js +19 -0
  42. package/dist/common/VersionedSchema/Utils/createTrivialMigration.d.ts +7 -0
  43. package/dist/common/VersionedSchema/Utils/createTrivialMigration.d.ts.map +1 -0
  44. package/dist/common/VersionedSchema/Utils/createTrivialMigration.js +15 -0
  45. package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.d.ts.map +1 -1
  46. package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.js +11 -4
  47. package/dist/core/OpenApiClient.d.ts +13 -0
  48. package/dist/core/OpenApiClient.d.ts.map +1 -0
  49. package/dist/core/OpenApiClient.js +175 -0
  50. package/dist/core/WriteClient.d.ts +1 -1
  51. package/dist/core/WriteClient.d.ts.map +1 -1
  52. package/dist/core/WriteClient.js +2 -2
  53. package/dist/core/__tests__/WriteClient.test.js +2 -0
  54. package/dist/core/index.d.ts +2 -6
  55. package/dist/core/index.d.ts.map +1 -1
  56. package/dist/core/index.js +6 -168
  57. package/dist/core/utils/__mocks__/templates.d.ts +3 -0
  58. package/dist/core/utils/__mocks__/templates.d.ts.map +1 -0
  59. package/dist/core/utils/__mocks__/templates.js +29 -0
  60. package/dist/core/utils/__tests__/writeClientCore.test.js +2 -25
  61. package/dist/core/utils/__tests__/writeClientFullIndex.test.js +2 -25
  62. package/dist/core/utils/__tests__/writeClientModels.test.js +2 -25
  63. package/dist/core/utils/__tests__/writeClientSchemas.test.js +2 -25
  64. package/dist/core/utils/__tests__/writeClientServices.test.js +2 -25
  65. package/dist/core/utils/registerHandlebarTemplates.d.ts +2 -0
  66. package/dist/core/utils/registerHandlebarTemplates.d.ts.map +1 -1
  67. package/dist/core/utils/registerHandlebarTemplates.js +4 -0
  68. package/dist/core/utils/writeClientCore.d.ts.map +1 -1
  69. package/dist/core/utils/writeClientCore.js +3 -0
  70. package/dist/templatesCompiled/client/core/legacy-request-adapter.d.ts +8 -0
  71. package/dist/templatesCompiled/client/core/legacy-request-adapter.d.ts.map +1 -0
  72. package/dist/templatesCompiled/client/core/legacy-request-adapter.js +18 -0
  73. package/dist/templatesCompiled/client/core/request-executor.d.ts +7 -0
  74. package/dist/templatesCompiled/client/core/request-executor.d.ts.map +1 -0
  75. package/dist/templatesCompiled/client/core/request-executor.js +11 -0
  76. package/dist/templatesCompiled/client/exportService.d.ts.map +1 -1
  77. package/dist/templatesCompiled/client/exportService.js +46 -50
  78. package/package.json +1 -1
  79. package/dist/common/Options.d.ts +0 -26
  80. package/dist/common/Options.d.ts.map +0 -1
  81. package/dist/core/utils/prepareOptions.d.ts +0 -8
  82. package/dist/core/utils/prepareOptions.d.ts.map +0 -1
  83. package/dist/core/utils/prepareOptions.js +0 -31
  84. /package/dist/common/{Options.js → TRawOptions.js} +0 -0
@@ -2,172 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HttpClient = void 0;
4
4
  exports.generate = generate;
5
- const fileSystemHelpers_1 = require("../common/utils/fileSystemHelpers");
6
- const pathHelpers_1 = require("../common/utils/pathHelpers");
7
- const Parser_1 = require("./api/v2/Parser");
8
- const Parser_2 = require("./api/v3/Parser");
9
- const Context_1 = require("./Context");
10
- const HttpClient_enum_1 = require("./types/enums/HttpClient.enum");
11
- const getOpenApiSpec_1 = require("./utils/getOpenApiSpec");
12
- const getOpenApiVersion_1 = require("./utils/getOpenApiVersion");
13
- const getOutputPaths_1 = require("./utils/getOutputPaths");
14
- const isInstanceOfMultiOptions_1 = require("./utils/isInstanceOfMultiOptions");
15
- const isString_1 = require("./utils/isString");
16
- const postProcessClient_1 = require("./utils/postProcessClient");
17
- const prepareOptions_1 = require("./utils/prepareOptions");
18
- const registerHandlebarTemplates_1 = require("./utils/registerHandlebarTemplates");
19
- const WriteClient_1 = require("./WriteClient");
20
- var HttpClient_enum_2 = require("./types/enums/HttpClient.enum");
21
- Object.defineProperty(exports, "HttpClient", { enumerable: true, get: function () { return HttpClient_enum_2.HttpClient; } });
22
- /**
23
- * Generate the OpenAPI client. This method will read the OpenAPI specification and based on the
24
- * given language it will generate the client, including the typed models, validation schemas,
25
- * service layer, etc.
26
- * @param input: The relative location of the OpenAPI spec
27
- * @param output: The relative location of the output directory
28
- * @param outputCore: The relative location of the output directory for core
29
- * @param outputServices: The relative location of the output directory for services
30
- * @param outputModels: The relative location of the output directory for models
31
- * @param outputSchemas: The relative location of the output directory for schemas
32
- * @param httpClient: The selected httpClient (fetch or XHR)
33
- * @param useOptions: Use options or arguments functions
34
- * @param useUnionTypes: Use union types instead of enums
35
- * @param excludeCoreServiceFiles The generation of the core and services is excluded
36
- * @param includeSchemasFiles The generation of model validation schemes is enabled
37
- * @param request: Path to custom request file
38
- * @param write: Write the files to disk (true or false)
39
- * @param interfacePrefix: Prefix for interface model(I)
40
- * @param enumPrefix: Prefix for enum model(E)
41
- * @param typePrefix: Prefix for type model(T)
42
- * @param useCancelableRequest Use cancelable request type.
43
- * @param sortByRequired Property sorting strategy: simplified or extended
44
- * @param useSeparatedIndexes Use separate index files for the core, models, schemas, and services
45
- */
46
- async function generateFrom({ input, output, outputCore, outputServices, outputModels, outputSchemas, httpClient = HttpClient_enum_1.HttpClient.FETCH, useOptions = false, useUnionTypes = false, excludeCoreServiceFiles = false, includeSchemasFiles = false, request, write = true, interfacePrefix = 'I', enumPrefix = 'E', typePrefix = 'T', useCancelableRequest = false, sortByRequired = false, useSeparatedIndexes = false, }, writeClient) {
47
- const outputPaths = (0, getOutputPaths_1.getOutputPaths)({
48
- output,
49
- outputCore,
50
- outputServices,
51
- outputModels,
52
- outputSchemas,
53
- });
54
- const absoluteInput = (0, isString_1.isString)(input) ? (0, pathHelpers_1.resolveHelper)(process.cwd(), input) : input;
55
- const context = new Context_1.Context({ input: absoluteInput, output: outputPaths, prefix: { interface: interfacePrefix, enum: enumPrefix, type: typePrefix }, sortByRequired });
56
- const openApi = (0, isString_1.isString)(input) ? await (0, getOpenApiSpec_1.getOpenApiSpec)(context, input) : input;
57
- const openApiVersion = (0, getOpenApiVersion_1.getOpenApiVersion)(openApi);
58
- const templates = (0, registerHandlebarTemplates_1.registerHandlebarTemplates)({
59
- httpClient,
60
- useUnionTypes,
61
- useOptions,
62
- });
63
- writeClient.logger.info('Defining the version of the openapi specification (2 or 3)');
64
- switch (openApiVersion) {
65
- case getOpenApiVersion_1.OpenApiVersion.V2: {
66
- const client = new Parser_1.Parser(context).parse(openApi);
67
- const clientFinal = (0, postProcessClient_1.postProcessClient)(client);
68
- if (!write)
69
- break;
70
- writeClient.logger.info('Write our OpenAPI client version 2 to disk.');
71
- await writeClient.writeClient({
72
- client: clientFinal,
73
- templates,
74
- outputPaths,
75
- httpClient,
76
- useOptions,
77
- useUnionTypes,
78
- excludeCoreServiceFiles,
79
- includeSchemasFiles,
80
- request,
81
- useCancelableRequest,
82
- useSeparatedIndexes,
83
- });
84
- break;
85
- }
86
- case getOpenApiVersion_1.OpenApiVersion.V3: {
87
- const client = new Parser_2.Parser(context).parse(openApi);
88
- const clientFinal = (0, postProcessClient_1.postProcessClient)(client);
89
- if (!write)
90
- break;
91
- writeClient.logger.info('Write our OpenAPI client version 3 to disk.');
92
- await writeClient.writeClient({
93
- client: clientFinal,
94
- templates,
95
- outputPaths,
96
- httpClient,
97
- useOptions,
98
- useUnionTypes,
99
- excludeCoreServiceFiles,
100
- includeSchemasFiles,
101
- request,
102
- useCancelableRequest,
103
- useSeparatedIndexes,
104
- });
105
- break;
106
- }
107
- }
5
+ const OpenApiClient_1 = require("./OpenApiClient");
6
+ var HttpClient_enum_1 = require("./types/enums/HttpClient.enum");
7
+ Object.defineProperty(exports, "HttpClient", { enumerable: true, get: function () { return HttpClient_enum_1.HttpClient; } });
8
+ async function generate(rawOptions) {
9
+ const openApiClient = new OpenApiClient_1.OpenApiClient();
10
+ await openApiClient.generate(rawOptions);
108
11
  }
109
- /**
110
- * @throws {Error} If options validation fails or generation encounters an error
111
- * @returns {Promise<void>}
112
- */
113
- async function generate(options) {
114
- let preparedOptions = [];
115
- if (Array.isArray(options)) {
116
- preparedOptions = options;
117
- }
118
- else if ((0, isInstanceOfMultiOptions_1.isInstanceOfMultioptions)(options)) {
119
- const { items, ...otherProps } = options;
120
- preparedOptions = items.map(item => ({ ...item, ...otherProps }));
121
- }
122
- else {
123
- preparedOptions = Array.of(options);
124
- }
125
- const optionsFinal = preparedOptions.map(op => (0, prepareOptions_1.prepareOptions)(op));
126
- const writeClient = new WriteClient_1.WriteClient();
127
- writeClient.logger.forceInfo(`${GENERATION_MESSAGES.STARTED}. Total number of specification files: ${optionsFinal.length}`);
128
- if (optionsFinal.length === 0) {
129
- throw new Error('No options provided for generation');
130
- }
131
- try {
132
- const start = process.hrtime();
133
- for (const option of optionsFinal) {
134
- await cleanOutputDirectories(option);
135
- }
136
- for (const option of optionsFinal) {
137
- const fileStart = process.hrtime();
138
- await generateFrom(option, writeClient);
139
- const [fileSeconds, fileNanoseconds] = process.hrtime(fileStart);
140
- const fileDuration = fileSeconds + fileNanoseconds / 1e6;
141
- writeClient.logger.info(`Duration for "${option.input}": ${fileDuration.toFixed(2)} sec`);
142
- }
143
- if (optionsFinal[0]?.useSeparatedIndexes) {
144
- await writeClient.combineAndWrightSimple();
145
- }
146
- else {
147
- await writeClient.combineAndWrite();
148
- }
149
- writeClient.logger.forceInfo(GENERATION_MESSAGES.FINISHED);
150
- const [seconds, nanoseconds] = process.hrtime(start);
151
- const durationInMs = seconds + nanoseconds / 1e6;
152
- writeClient.logger.forceInfo(GENERATION_MESSAGES.DURATION(durationInMs));
153
- writeClient.logger.forceInfo(GENERATION_MESSAGES.FINISHED);
154
- }
155
- catch (error) {
156
- writeClient.logger.error(error.message);
157
- }
158
- writeClient.logger.shutdownLogger();
159
- }
160
- const cleanOutputDirectories = async (option) => {
161
- const outputDirs = [option.output, option.outputCore, option.outputSchemas, option.outputModels, option.outputServices];
162
- for (const dir of outputDirs) {
163
- if (dir) {
164
- await fileSystemHelpers_1.fileSystemHelpers.rmdir(dir);
165
- }
166
- }
167
- };
168
- const GENERATION_MESSAGES = {
169
- STARTED: 'Generation has begun',
170
- FINISHED: 'Generation from has been finished',
171
- FILE_FINISHED: (input) => `Generation from "${input}" was finished`,
172
- DURATION: (ms) => `Lead time: ${ms.toFixed(2)} sec`,
173
- };
@@ -0,0 +1,3 @@
1
+ import { Templates } from '../registerHandlebarTemplates';
2
+ export declare const templates: Templates;
3
+ //# sourceMappingURL=templates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../../../src/core/utils/__mocks__/templates.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAC;AAE1D,eAAO,MAAM,SAAS,EAAE,SAyBvB,CAAC"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.templates = void 0;
4
+ exports.templates = {
5
+ indexes: {
6
+ full: () => 'fullIndex',
7
+ simple: () => 'simpleIndex',
8
+ core: () => 'coreIndex',
9
+ models: () => 'modelsIndex',
10
+ schemas: () => 'schemasIndex',
11
+ services: () => 'servicesIndex',
12
+ },
13
+ exports: {
14
+ model: () => 'model',
15
+ schema: () => 'schema',
16
+ service: () => 'service',
17
+ },
18
+ core: {
19
+ settings: () => 'settings',
20
+ apiError: () => 'apiError',
21
+ apiRequestOptions: () => 'apiRequestOptions',
22
+ apiResult: () => 'apiResult',
23
+ request: () => 'request',
24
+ cancelablePromise: () => 'cancelablePromise',
25
+ httpStatusCode: () => 'httpStatusCode',
26
+ legacyRequestAdapter: () => 'legacyRequestAdapter',
27
+ requestExecutor: () => 'requestExecutor',
28
+ },
29
+ };
@@ -8,6 +8,7 @@ const node_test_1 = require("node:test");
8
8
  const fileSystemHelpers_1 = require("../../../common/utils/fileSystemHelpers");
9
9
  const HttpClient_enum_1 = require("../../types/enums/HttpClient.enum");
10
10
  const WriteClient_1 = require("../../WriteClient");
11
+ const templates_1 = require("../__mocks__/templates");
11
12
  (0, node_test_1.describe)('@unit: writeClientCore', () => {
12
13
  (0, node_test_1.test)('writes to filesystem', async () => {
13
14
  const writeFileCalls = [];
@@ -22,33 +23,9 @@ const WriteClient_1 = require("../../WriteClient");
22
23
  models: [],
23
24
  services: [],
24
25
  };
25
- const templates = {
26
- indexes: {
27
- full: () => 'fullIndex',
28
- simple: () => 'simpleIndex',
29
- core: () => 'coreIndex',
30
- models: () => 'modelsIndex',
31
- schemas: () => 'schemasIndex',
32
- services: () => 'servicesIndex',
33
- },
34
- exports: {
35
- model: () => 'model',
36
- schema: () => 'schema',
37
- service: () => 'service',
38
- },
39
- core: {
40
- settings: () => 'settings',
41
- apiError: () => 'apiError',
42
- apiRequestOptions: () => 'apiRequestOptions',
43
- apiResult: () => 'apiResult',
44
- request: () => 'request',
45
- cancelablePromise: () => 'cancelablePromise',
46
- httpStatusCode: () => 'httpStatusCode',
47
- },
48
- };
49
26
  const useCancelableRequest = true;
50
27
  const writeClient = new WriteClient_1.WriteClient();
51
- await writeClient.writeClientCore({ client, templates, outputCorePath: '/', httpClient: HttpClient_enum_1.HttpClient.FETCH, useCancelableRequest });
28
+ await writeClient.writeClientCore({ client, templates: templates_1.templates, outputCorePath: '/', httpClient: HttpClient_enum_1.HttpClient.FETCH, useCancelableRequest });
52
29
  node_assert_1.default.ok(writeFileCalls.some(([filePath, content]) => filePath.toString().includes('OpenAPI.ts') && content.toString().includes('settings')), 'Expected writeFile to be called with settings content for OpenAPI.ts');
53
30
  node_assert_1.default.ok(writeFileCalls.some(([filePath, content]) => filePath.toString().includes('ApiError.ts') && content.toString().includes('apiError')), 'Expected writeFile to be called with apiError content for ApiError.ts');
54
31
  node_assert_1.default.ok(writeFileCalls.some(([filePath, content]) => filePath.toString().includes('ApiRequestOptions.ts') && content.toString().includes('apiRequestOptions')), 'Expected writeFile to be called with apiRequestOptions content for ApiRequestOptions.ts');
@@ -7,6 +7,7 @@ const node_assert_1 = __importDefault(require("node:assert"));
7
7
  const node_test_1 = require("node:test");
8
8
  const fileSystemHelpers_1 = require("../../../common/utils/fileSystemHelpers");
9
9
  const WriteClient_1 = require("../../WriteClient");
10
+ const templates_1 = require("../__mocks__/templates");
10
11
  (0, node_test_1.describe)('@unit: writeClientFullIndex', () => {
11
12
  (0, node_test_1.test)('writes to filesystem', async () => {
12
13
  const writeFileCalls = [];
@@ -15,32 +16,8 @@ const WriteClient_1 = require("../../WriteClient");
15
16
  fileSystemHelpers_1.fileSystemHelpers.writeFile = async (path, content) => {
16
17
  writeFileCalls.push([path, content]);
17
18
  };
18
- const templates = {
19
- indexes: {
20
- full: () => 'fullIndex',
21
- simple: () => 'simpleIndex',
22
- core: () => 'coreIndex',
23
- models: () => 'modelsIndex',
24
- schemas: () => 'schemasIndex',
25
- services: () => 'servicesIndex',
26
- },
27
- exports: {
28
- model: () => 'model',
29
- schema: () => 'schema',
30
- service: () => 'service',
31
- },
32
- core: {
33
- settings: () => 'settings',
34
- apiError: () => 'apiError',
35
- apiRequestOptions: () => 'apiRequestOptions',
36
- apiResult: () => 'apiResult',
37
- request: () => 'request',
38
- cancelablePromise: () => 'cancelablePromise',
39
- httpStatusCode: () => 'httpStatusCode',
40
- },
41
- };
42
19
  const writeClient = new WriteClient_1.WriteClient();
43
- await writeClient.writeClientFullIndex({ templates, outputPath: '/', core: [], models: [], schemas: [], services: [] });
20
+ await writeClient.writeClientFullIndex({ templates: templates_1.templates, outputPath: '/', core: [], models: [], schemas: [], services: [] });
44
21
  node_assert_1.default.ok(writeFileCalls.some(([filePath, content]) => filePath.toString().includes('index.ts') && content.toString().includes('fullIndex')), 'Expected writeFile to be called with index content for index.ts');
45
22
  // Restoring the original function
46
23
  fileSystemHelpers_1.fileSystemHelpers.writeFile = originalWriteFile;
@@ -8,6 +8,7 @@ const node_test_1 = require("node:test");
8
8
  const fileSystemHelpers_1 = require("../../../common/utils/fileSystemHelpers");
9
9
  const HttpClient_enum_1 = require("../../types/enums/HttpClient.enum");
10
10
  const WriteClient_1 = require("../../WriteClient");
11
+ const templates_1 = require("../__mocks__/templates");
11
12
  (0, node_test_1.describe)('@unit: writeClientModels', () => {
12
13
  (0, node_test_1.test)('writes to filesystem', async () => {
13
14
  const writeFileCalls = [];
@@ -37,34 +38,10 @@ const WriteClient_1 = require("../../WriteClient");
37
38
  alias: '',
38
39
  },
39
40
  ];
40
- const templates = {
41
- indexes: {
42
- full: () => 'fullIndex',
43
- simple: () => 'simpleIndex',
44
- core: () => 'coreIndex',
45
- models: () => 'modelsIndex',
46
- schemas: () => 'schemasIndex',
47
- services: () => 'servicesIndex',
48
- },
49
- exports: {
50
- model: () => 'model',
51
- schema: () => 'schema',
52
- service: () => 'service',
53
- },
54
- core: {
55
- settings: () => 'settings',
56
- apiError: () => 'apiError',
57
- apiRequestOptions: () => 'apiRequestOptions',
58
- apiResult: () => 'apiResult',
59
- request: () => 'request',
60
- cancelablePromise: () => 'cancelablePromise',
61
- httpStatusCode: () => 'httpStatusCode',
62
- },
63
- };
64
41
  const writeClient = new WriteClient_1.WriteClient();
65
42
  await writeClient.writeClientModels({
66
43
  models,
67
- templates,
44
+ templates: templates_1.templates,
68
45
  outputModelsPath: '/',
69
46
  httpClient: HttpClient_enum_1.HttpClient.FETCH,
70
47
  useUnionTypes: false,
@@ -8,6 +8,7 @@ const node_test_1 = require("node:test");
8
8
  const fileSystemHelpers_1 = require("../../../common/utils/fileSystemHelpers");
9
9
  const HttpClient_enum_1 = require("../../types/enums/HttpClient.enum");
10
10
  const WriteClient_1 = require("../../WriteClient");
11
+ const templates_1 = require("../__mocks__/templates");
11
12
  (0, node_test_1.describe)('@unit: writeClientSchemas', () => {
12
13
  (0, node_test_1.test)('writes to filesystem', async () => {
13
14
  const writeFileCalls = [];
@@ -37,34 +38,10 @@ const WriteClient_1 = require("../../WriteClient");
37
38
  properties: [],
38
39
  },
39
40
  ];
40
- const templates = {
41
- indexes: {
42
- full: () => 'fullIndex',
43
- simple: () => 'simpleIndex',
44
- core: () => 'coreIndex',
45
- models: () => 'modelsIndex',
46
- schemas: () => 'schemasIndex',
47
- services: () => 'servicesIndex',
48
- },
49
- exports: {
50
- model: () => 'model',
51
- schema: () => 'schema',
52
- service: () => 'service',
53
- },
54
- core: {
55
- settings: () => 'settings',
56
- apiError: () => 'apiError',
57
- apiRequestOptions: () => 'apiRequestOptions',
58
- apiResult: () => 'apiResult',
59
- request: () => 'request',
60
- cancelablePromise: () => 'cancelablePromise',
61
- httpStatusCode: () => 'httpStatusCode',
62
- },
63
- };
64
41
  const writeClient = new WriteClient_1.WriteClient();
65
42
  await writeClient.writeClientSchemas({
66
43
  models,
67
- templates,
44
+ templates: templates_1.templates,
68
45
  outputSchemasPath: '/',
69
46
  httpClient: HttpClient_enum_1.HttpClient.FETCH,
70
47
  useUnionTypes: false,
@@ -8,6 +8,7 @@ const node_test_1 = require("node:test");
8
8
  const fileSystemHelpers_1 = require("../../../common/utils/fileSystemHelpers");
9
9
  const HttpClient_enum_1 = require("../../types/enums/HttpClient.enum");
10
10
  const WriteClient_1 = require("../../WriteClient");
11
+ const templates_1 = require("../__mocks__/templates");
11
12
  (0, node_test_1.describe)('@unit: writeClientServices', () => {
12
13
  (0, node_test_1.test)('writes to filesystem', async () => {
13
14
  const writeFileCalls = [];
@@ -24,34 +25,10 @@ const WriteClient_1 = require("../../WriteClient");
24
25
  imports: [],
25
26
  },
26
27
  ];
27
- const templates = {
28
- indexes: {
29
- full: () => 'fullIndex',
30
- simple: () => 'simpleIndex',
31
- core: () => 'coreIndex',
32
- models: () => 'modelsIndex',
33
- schemas: () => 'schemasIndex',
34
- services: () => 'servicesIndex',
35
- },
36
- exports: {
37
- model: () => 'model',
38
- schema: () => 'schema',
39
- service: () => 'service',
40
- },
41
- core: {
42
- settings: () => 'settings',
43
- apiError: () => 'apiError',
44
- apiRequestOptions: () => 'apiRequestOptions',
45
- apiResult: () => 'apiResult',
46
- request: () => 'request',
47
- cancelablePromise: () => 'cancelablePromise',
48
- httpStatusCode: () => 'httpStatusCode',
49
- },
50
- };
51
28
  const writeClient = new WriteClient_1.WriteClient();
52
29
  await writeClient.writeClientServices({
53
30
  services,
54
- templates,
31
+ templates: templates_1.templates,
55
32
  outputPaths: {
56
33
  outputCore: '/',
57
34
  outputModels: '/',
@@ -22,6 +22,8 @@ export interface Templates {
22
22
  request: Handlebars.TemplateDelegate;
23
23
  cancelablePromise: Handlebars.TemplateDelegate;
24
24
  httpStatusCode: Handlebars.TemplateDelegate;
25
+ requestExecutor: Handlebars.TemplateDelegate;
26
+ legacyRequestAdapter: Handlebars.TemplateDelegate;
25
27
  };
26
28
  }
27
29
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"registerHandlebarTemplates.d.ts","sourceRoot":"","sources":["../../../src/core/utils/registerHandlebarTemplates.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,oBAAoB,CAAC;AAuFjD,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAE5D,MAAM,WAAW,SAAS;IACtB,OAAO,EAAE;QACL,IAAI,EAAE,UAAU,CAAC,gBAAgB,CAAC;QAClC,MAAM,EAAE,UAAU,CAAC,gBAAgB,CAAC;QACpC,IAAI,EAAE,UAAU,CAAC,gBAAgB,CAAC;QAClC,MAAM,EAAE,UAAU,CAAC,gBAAgB,CAAC;QACpC,OAAO,EAAE,UAAU,CAAC,gBAAgB,CAAC;QACrC,QAAQ,EAAE,UAAU,CAAC,gBAAgB,CAAC;KACzC,CAAA;IACD,OAAO,EAAE;QACL,KAAK,EAAE,UAAU,CAAC,gBAAgB,CAAC;QACnC,MAAM,EAAE,UAAU,CAAC,gBAAgB,CAAC;QACpC,OAAO,EAAE,UAAU,CAAC,gBAAgB,CAAC;KACxC,CAAC;IACF,IAAI,EAAE;QACF,QAAQ,EAAE,UAAU,CAAC,gBAAgB,CAAC;QACtC,QAAQ,EAAE,UAAU,CAAC,gBAAgB,CAAC;QACtC,iBAAiB,EAAE,UAAU,CAAC,gBAAgB,CAAC;QAC/C,SAAS,EAAE,UAAU,CAAC,gBAAgB,CAAC;QACvC,OAAO,EAAE,UAAU,CAAC,gBAAgB,CAAC;QACrC,iBAAiB,EAAE,UAAU,CAAC,gBAAgB,CAAC;QAC/C,cAAc,EAAE,UAAU,CAAC,gBAAgB,CAAC;KAC/C,CAAC;CACL;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE;IAAE,UAAU,EAAE,UAAU,CAAC;IAAC,UAAU,EAAE,OAAO,CAAC;IAAC,aAAa,EAAE,OAAO,CAAA;CAAE,GAAG,SAAS,CA4GnI"}
1
+ {"version":3,"file":"registerHandlebarTemplates.d.ts","sourceRoot":"","sources":["../../../src/core/utils/registerHandlebarTemplates.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,UAAU,MAAM,oBAAoB,CAAC;AAyFjD,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAE5D,MAAM,WAAW,SAAS;IACtB,OAAO,EAAE;QACL,IAAI,EAAE,UAAU,CAAC,gBAAgB,CAAC;QAClC,MAAM,EAAE,UAAU,CAAC,gBAAgB,CAAC;QACpC,IAAI,EAAE,UAAU,CAAC,gBAAgB,CAAC;QAClC,MAAM,EAAE,UAAU,CAAC,gBAAgB,CAAC;QACpC,OAAO,EAAE,UAAU,CAAC,gBAAgB,CAAC;QACrC,QAAQ,EAAE,UAAU,CAAC,gBAAgB,CAAC;KACzC,CAAA;IACD,OAAO,EAAE;QACL,KAAK,EAAE,UAAU,CAAC,gBAAgB,CAAC;QACnC,MAAM,EAAE,UAAU,CAAC,gBAAgB,CAAC;QACpC,OAAO,EAAE,UAAU,CAAC,gBAAgB,CAAC;KACxC,CAAC;IACF,IAAI,EAAE;QACF,QAAQ,EAAE,UAAU,CAAC,gBAAgB,CAAC;QACtC,QAAQ,EAAE,UAAU,CAAC,gBAAgB,CAAC;QACtC,iBAAiB,EAAE,UAAU,CAAC,gBAAgB,CAAC;QAC/C,SAAS,EAAE,UAAU,CAAC,gBAAgB,CAAC;QACvC,OAAO,EAAE,UAAU,CAAC,gBAAgB,CAAC;QACrC,iBAAiB,EAAE,UAAU,CAAC,gBAAgB,CAAC;QAC/C,cAAc,EAAE,UAAU,CAAC,gBAAgB,CAAC;QAC5C,eAAe,EAAE,UAAU,CAAC,gBAAgB,CAAC;QAC7C,oBAAoB,EAAE,UAAU,CAAC,gBAAgB,CAAC;KACrD,CAAC;CACL;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE;IAAE,UAAU,EAAE,UAAU,CAAC;IAAC,UAAU,EAAE,OAAO,CAAC;IAAC,aAAa,EAAE,OAAO,CAAA;CAAE,GAAG,SAAS,CA8GnI"}
@@ -77,6 +77,8 @@ const sendRequest_3 = __importDefault(require("../../templatesCompiled/client/co
77
77
  const OpenAPI_1 = __importDefault(require("../../templatesCompiled/client/core/OpenAPI"));
78
78
  const CancelablePromise_1 = __importDefault(require("../../templatesCompiled/client/core/CancelablePromise"));
79
79
  const request_4 = __importDefault(require("../../templatesCompiled/client/core/request"));
80
+ const request_executor_1 = __importDefault(require("../../templatesCompiled/client/core/request-executor"));
81
+ const legacy_request_adapter_1 = __importDefault(require("../../templatesCompiled/client/core/legacy-request-adapter"));
80
82
  const getHeaders_4 = __importDefault(require("../../templatesCompiled/client/core/xhr/getHeaders"));
81
83
  const getRequestBody_4 = __importDefault(require("../../templatesCompiled/client/core/xhr/getRequestBody"));
82
84
  const getResponseBody_4 = __importDefault(require("../../templatesCompiled/client/core/xhr/getResponseBody"));
@@ -153,6 +155,8 @@ function registerHandlebarTemplates(root) {
153
155
  request: Handlebars.template(request_4.default),
154
156
  cancelablePromise: Handlebars.template(CancelablePromise_1.default),
155
157
  httpStatusCode: Handlebars.template(HttpStatusCode_1.default),
158
+ requestExecutor: Handlebars.template(request_executor_1.default),
159
+ legacyRequestAdapter: Handlebars.template(legacy_request_adapter_1.default),
156
160
  },
157
161
  };
158
162
  // Partials for the generations of the models, services, etc.
@@ -1 +1 @@
1
- {"version":3,"file":"writeClientCore.d.ts","sourceRoot":"","sources":["../../../src/core/utils/writeClientCore.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEzD;;;;;;;GAOG;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,mBAAmB,CAAC,EAAE,OAAO,CAAC;CACjC;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAgCjG"}
1
+ {"version":3,"file":"writeClientCore.d.ts","sourceRoot":"","sources":["../../../src/core/utils/writeClientCore.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEzD;;;;;;;GAOG;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,mBAAmB,CAAC,EAAE,OAAO,CAAC;CACjC;AAED;;;;;;;;GAQG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAmCjG"}
@@ -31,6 +31,9 @@ async function writeClientCore(options) {
31
31
  }
32
32
  await fileSystemHelpers_1.fileSystemHelpers.writeFile((0, pathHelpers_1.resolveHelper)(outputCorePath, 'HttpStatusCode.ts'), templates.core.httpStatusCode({}));
33
33
  await fileSystemHelpers_1.fileSystemHelpers.writeFile((0, pathHelpers_1.resolveHelper)(outputCorePath, 'request.ts'), templates.core.request(context));
34
+ await fileSystemHelpers_1.fileSystemHelpers.writeFile((0, pathHelpers_1.resolveHelper)(outputCorePath, 'request-executor.ts'), templates.core.requestExecutor({}));
35
+ // TODO: Добавлять только, если не выбран custom-ный request
36
+ await fileSystemHelpers_1.fileSystemHelpers.writeFile((0, pathHelpers_1.resolveHelper)(outputCorePath, 'legacy-request-adapter.ts'), templates.core.legacyRequestAdapter({}));
34
37
  if (request) {
35
38
  const requestFile = (0, pathHelpers_1.resolveHelper)(process.cwd(), request);
36
39
  const requestFileExists = await fileSystemHelpers_1.fileSystemHelpers.exists(requestFile);
@@ -0,0 +1,8 @@
1
+ declare const _default: {
2
+ compiler: (string | number)[];
3
+ main: (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
4
+ usePartial: boolean;
5
+ useData: boolean;
6
+ };
7
+ export default _default;
8
+ //# sourceMappingURL=legacy-request-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"legacy-request-adapter.d.ts","sourceRoot":"","sources":["../../../../src/templatesCompiled/client/core/legacy-request-adapter.ts"],"names":[],"mappings":";;;;;;AAMA,wBAUmC"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // This is an automatically generated file for the hbs template.
4
+ // You don't need to change it, run npm run build:hbs to update it.
5
+ /* istanbul ignore file */
6
+ /* tslint: disable */
7
+ /* eslint: disable */
8
+ // @ts-nocheck
9
+ exports.default = { "compiler": [8, ">= 4.3.0"], "main": function (container, depth0, helpers, partials, data) {
10
+ var stack1, lookupProperty = container.lookupProperty || function (parent, propertyName) {
11
+ if (Object.prototype.hasOwnProperty.call(parent, propertyName)) {
12
+ return parent[propertyName];
13
+ }
14
+ return undefined;
15
+ };
16
+ return ((stack1 = container.invokePartial(lookupProperty(partials, "header"), depth0, { "name": "header", "data": data, "helpers": helpers, "partials": partials, "decorators": container.decorators })) != null ? stack1 : "")
17
+ + "\nimport type { RequestExecutor, RequestConfig } from './request-executor';\nimport type { ApiRequestOptions } from './ApiRequestOptions';\nimport type { TOpenAPIConfig } from './OpenAPI';\nimport { OpenAPI } from './OpenAPI';\nimport { request as __request } from './request';\n\n/**\n * Legacy RequestExecutor-адаптер поверх существующего request(ApiRequestOptions, OpenAPI).\n *\n * TOptions — тип рантайм-опций транспорта (IXHROptions, IFetchOptions и т.п.).\n * mapOptions — опциональная функция, которая мапит TOptions → часть ApiRequestOptions.\n */\nexport function createLegacyExecutor<TOptions = unknown>(\n openApiConfig: TOpenAPIConfig = OpenAPI,\n mapOptions?: (options: TOptions | undefined) => Partial<ApiRequestOptions>,\n): RequestExecutor<TOptions> {\n return {\n request<TResponse>(config: RequestConfig, options?: TOptions): Promise<TResponse> {\n const baseOptions: ApiRequestOptions = {\n method: config.method as ApiRequestOptions['method'],\n path: config.url, // RequestConfig.url → ApiRequestOptions.path\n headers: config.headers,\n query: config.query,\n body: config.body,\n };\n\n const mergedOptions: ApiRequestOptions = {\n ...baseOptions,\n ...(mapOptions ? mapOptions(options) : {}),\n };\n\n return __request<TResponse>(mergedOptions, openApiConfig);\n },\n };\n}";
18
+ }, "usePartial": true, "useData": true };
@@ -0,0 +1,7 @@
1
+ declare const _default: {
2
+ compiler: (string | number)[];
3
+ main: (container: any, depth0: any, helpers: any, partials: any, data: any) => string;
4
+ useData: boolean;
5
+ };
6
+ export default _default;
7
+ //# sourceMappingURL=request-executor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-executor.d.ts","sourceRoot":"","sources":["../../../../src/templatesCompiled/client/core/request-executor.ts"],"names":[],"mappings":";;;;;AAMA,wBAEiB"}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // This is an automatically generated file for the hbs template.
4
+ // You don't need to change it, run npm run build:hbs to update it.
5
+ /* istanbul ignore file */
6
+ /* tslint: disable */
7
+ /* eslint: disable */
8
+ // @ts-nocheck
9
+ exports.default = { "compiler": [8, ">= 4.3.0"], "main": function (container, depth0, helpers, partials, data) {
10
+ return "export interface RequestConfig {\n method: string;\n url: string;\n headers?: Record<string, string>;\n query?: Record<string, any>;\n body?: unknown;\n}\n\nexport interface RequestExecutor<TOptions = unknown> {\n request<TResponse>(\n config: RequestConfig,\n options?: TOptions\n ): Promise<TResponse>;\n}";
11
+ }, "useData": true };
@@ -1 +1 @@
1
- {"version":3,"file":"exportService.d.ts","sourceRoot":"","sources":["../../../src/templatesCompiled/client/exportService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAMA,wBAqNoD"}
1
+ {"version":3,"file":"exportService.d.ts","sourceRoot":"","sources":["../../../src/templatesCompiled/client/exportService.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAMA,wBAiNoD"}