ts-openapi-codegen 1.0.0 → 2.0.0-beta.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/dist/cli/generate/runGenerateOpenApi.d.ts.map +1 -1
- package/dist/cli/generate/runGenerateOpenApi.js +10 -25
- package/dist/common/Consts.d.ts +2 -21
- package/dist/common/Consts.d.ts.map +1 -1
- package/dist/common/Consts.js +5 -2
- package/dist/common/Logger.d.ts.map +1 -1
- package/dist/common/Logger.js +3 -2
- package/dist/common/LoggerMessages.d.ts +64 -0
- package/dist/common/LoggerMessages.d.ts.map +1 -0
- package/dist/common/LoggerMessages.js +82 -0
- package/dist/common/TRawOptions.d.ts +40 -0
- package/dist/common/TRawOptions.d.ts.map +1 -0
- package/dist/common/VersionedSchema/AllVersionedSchemas/AllMigrationPlans.d.ts +8 -0
- package/dist/common/VersionedSchema/AllVersionedSchemas/AllMigrationPlans.d.ts.map +1 -0
- package/dist/common/VersionedSchema/AllVersionedSchemas/AllMigrationPlans.js +31 -0
- package/dist/common/VersionedSchema/AllVersionedSchemas/AllVersionedSchemas.d.ts +8 -0
- package/dist/common/VersionedSchema/AllVersionedSchemas/AllVersionedSchemas.d.ts.map +1 -0
- package/dist/common/VersionedSchema/AllVersionedSchemas/AllVersionedSchemas.js +33 -0
- package/dist/common/VersionedSchema/Enums.d.ts +2 -1
- package/dist/common/VersionedSchema/Enums.d.ts.map +1 -1
- package/dist/common/VersionedSchema/Enums.js +1 -0
- package/dist/common/VersionedSchema/MultiOptionsVersioned/MultiOptionsMigrationPlan.d.ts.map +1 -1
- package/dist/common/VersionedSchema/MultiOptionsVersioned/MultiOptionsMigrationPlan.js +10 -19
- package/dist/common/VersionedSchema/OptionsVersioned/OptionsMigrationPlans.d.ts.map +1 -1
- package/dist/common/VersionedSchema/OptionsVersioned/OptionsMigrationPlans.js +10 -10
- package/dist/common/VersionedSchema/Types.d.ts +5 -0
- package/dist/common/VersionedSchema/Types.d.ts.map +1 -1
- package/dist/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsMigrationPlan.d.ts +3 -0
- package/dist/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsMigrationPlan.d.ts.map +1 -0
- package/dist/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsMigrationPlan.js +28 -0
- package/dist/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsSchemaV1.d.ts +7 -0
- package/dist/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsSchemaV1.d.ts.map +1 -0
- package/dist/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsSchemaV1.js +42 -0
- package/dist/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsVersionedSchemas.d.ts +3 -0
- package/dist/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsVersionedSchemas.d.ts.map +1 -0
- package/dist/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsVersionedSchemas.js +10 -0
- package/dist/common/VersionedSchema/Utils/createDefaultFieldsMigration.d.ts +11 -0
- package/dist/common/VersionedSchema/Utils/createDefaultFieldsMigration.d.ts.map +1 -0
- package/dist/common/VersionedSchema/Utils/createDefaultFieldsMigration.js +19 -0
- package/dist/common/VersionedSchema/Utils/createTrivialMigration.d.ts +7 -0
- package/dist/common/VersionedSchema/Utils/createTrivialMigration.d.ts.map +1 -0
- package/dist/common/VersionedSchema/Utils/createTrivialMigration.js +15 -0
- package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.d.ts.map +1 -1
- package/dist/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.js +11 -4
- package/dist/core/OpenApiClient.d.ts +13 -0
- package/dist/core/OpenApiClient.d.ts.map +1 -0
- package/dist/core/OpenApiClient.js +175 -0
- package/dist/core/WriteClient.d.ts +1 -1
- package/dist/core/WriteClient.d.ts.map +1 -1
- package/dist/core/WriteClient.js +2 -2
- package/dist/core/index.d.ts +2 -6
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +6 -168
- package/package.json +1 -1
- package/dist/common/Options.d.ts +0 -26
- package/dist/common/Options.d.ts.map +0 -1
- package/dist/core/utils/prepareOptions.d.ts +0 -8
- package/dist/core/utils/prepareOptions.d.ts.map +0 -1
- package/dist/core/utils/prepareOptions.js +0 -31
- /package/dist/common/{Options.js → TRawOptions.js} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnifiedOptionsSchemaV1.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsSchemaV1.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,KAAK,CAAC;AAqBtB;;;GAGG;AACH,eAAO,MAAM,sBAAsB,uBA6BZ,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
exports.unifiedOptionsSchemaV1 = void 0;
|
|
7
|
+
const joi_1 = __importDefault(require("joi"));
|
|
8
|
+
const core_1 = require("../../../core");
|
|
9
|
+
const CommonSchemas_1 = require("../CommonSchemas");
|
|
10
|
+
const mergeObjectSchemas_1 = require("../Utils/mergeObjectSchemas");
|
|
11
|
+
const itemSchema = (0, mergeObjectSchemas_1.mergeObjectSchemas)(joi_1.default.object({
|
|
12
|
+
input: joi_1.default.string().required().description('Путь, URL или строка OpenAPI спецификации'),
|
|
13
|
+
httpClient: joi_1.default.string().valid(...Object.values(core_1.HttpClient)).optional(),
|
|
14
|
+
}), CommonSchemas_1.outputPathsSchema, CommonSchemas_1.additionalParametersSchemaV2, CommonSchemas_1.experimentalParametersSchemaV2);
|
|
15
|
+
/**
|
|
16
|
+
* Unified options schema that supports both single and multi-item configurations.
|
|
17
|
+
* Use either 'items' array for multiple specs OR 'input'/'output' for single spec.
|
|
18
|
+
*/
|
|
19
|
+
exports.unifiedOptionsSchemaV1 = (0, mergeObjectSchemas_1.mergeObjectSchemas)(joi_1.default.object({
|
|
20
|
+
// Multi-item configuration
|
|
21
|
+
items: joi_1.default.array()
|
|
22
|
+
.items(itemSchema)
|
|
23
|
+
.min(1)
|
|
24
|
+
.optional()
|
|
25
|
+
.description('Массив спецификаций для генерации'),
|
|
26
|
+
// Single-item configuration (mutually exclusive with items)
|
|
27
|
+
input: joi_1.default.string()
|
|
28
|
+
.when('items', {
|
|
29
|
+
is: joi_1.default.exist(),
|
|
30
|
+
then: joi_1.default.forbidden(),
|
|
31
|
+
otherwise: joi_1.default.required(),
|
|
32
|
+
})
|
|
33
|
+
.description('Путь, URL или строка OpenAPI спецификации'),
|
|
34
|
+
output: joi_1.default.string()
|
|
35
|
+
.when('items', {
|
|
36
|
+
is: joi_1.default.exist(),
|
|
37
|
+
then: joi_1.default.forbidden(),
|
|
38
|
+
otherwise: joi_1.default.required(),
|
|
39
|
+
})
|
|
40
|
+
.description('Выходная директория'),
|
|
41
|
+
}), CommonSchemas_1.outputPathsSchema, // outputCore, outputServices, etc. for single-item mode
|
|
42
|
+
CommonSchemas_1.specialParametersSchemasV2, CommonSchemas_1.additionalParametersSchemaV2, CommonSchemas_1.experimentalParametersSchemaV2).xor('items', 'input');
|
package/dist/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsVersionedSchemas.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UnifiedOptionsVersionedSchemas.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/UnifiedOptionsVersioned/UnifiedOptionsVersionedSchemas.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAG3C,eAAO,MAAM,8BAA8B,EAAE,eAAe,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAI/E,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.unifiedOptionsVersionedSchemas = void 0;
|
|
4
|
+
const Enums_1 = require("../Enums");
|
|
5
|
+
const UnifiedOptionsSchemaV1_1 = require("./UnifiedOptionsSchemaV1");
|
|
6
|
+
exports.unifiedOptionsVersionedSchemas = [{
|
|
7
|
+
version: 'v1',
|
|
8
|
+
schema: UnifiedOptionsSchemaV1_1.unifiedOptionsSchemaV1,
|
|
9
|
+
type: Enums_1.EVersionedSchemaType.UNIFIED_OPTIONS,
|
|
10
|
+
}];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SchemaMigrationPlan } from "../Types";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a simple migration plan that adds optional fields.
|
|
4
|
+
* Use this when migration only adds optional fields.
|
|
5
|
+
* @param fromVersion
|
|
6
|
+
* @param toVersion
|
|
7
|
+
* @param defaultFields
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare function createDefaultFieldsMigration<From extends Record<string, any>>(fromVersion: string, toVersion: string, defaultFields: Record<string, any>): SchemaMigrationPlan<From, From>;
|
|
11
|
+
//# sourceMappingURL=createDefaultFieldsMigration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createDefaultFieldsMigration.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/createDefaultFieldsMigration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE/C;;;;;;;GAOG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACzE,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GACnC,mBAAmB,CAAC,IAAI,EAAE,IAAI,CAAC,CAOjC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createDefaultFieldsMigration = createDefaultFieldsMigration;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a simple migration plan that adds optional fields.
|
|
6
|
+
* Use this when migration only adds optional fields.
|
|
7
|
+
* @param fromVersion
|
|
8
|
+
* @param toVersion
|
|
9
|
+
* @param defaultFields
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
function createDefaultFieldsMigration(fromVersion, toVersion, defaultFields) {
|
|
13
|
+
return {
|
|
14
|
+
fromVersion,
|
|
15
|
+
toVersion,
|
|
16
|
+
migrate: (oldVersion) => ({ ...oldVersion, ...defaultFields }),
|
|
17
|
+
description: `Adds default values for new optional fields: ${Object.keys(defaultFields).join(', ')}`,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SchemaMigrationPlan } from '../Types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a trivial migration plan that just copies all fields.
|
|
4
|
+
* Use this when migration only adds doesn't require transformation.
|
|
5
|
+
*/
|
|
6
|
+
export declare function createTrivialMigration<From extends Record<string, any>>(fromVersion: string, toVersion: string, description?: string): SchemaMigrationPlan<From, From>;
|
|
7
|
+
//# sourceMappingURL=createTrivialMigration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTrivialMigration.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/createTrivialMigration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE/C;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EACnE,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,WAAW,CAAC,EAAE,MAAM,GACrB,mBAAmB,CAAC,IAAI,EAAE,IAAI,CAAC,CAOjC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createTrivialMigration = createTrivialMigration;
|
|
4
|
+
/**
|
|
5
|
+
* Creates a trivial migration plan that just copies all fields.
|
|
6
|
+
* Use this when migration only adds doesn't require transformation.
|
|
7
|
+
*/
|
|
8
|
+
function createTrivialMigration(fromVersion, toVersion, description) {
|
|
9
|
+
return {
|
|
10
|
+
fromVersion,
|
|
11
|
+
toVersion,
|
|
12
|
+
migrate: (oldVersion) => ({ ...oldVersion }),
|
|
13
|
+
description: description || 'Trivial migration that copies all fields without changes',
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"migrateDataToLatestSchemaVersion.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AASpF,KAAK,oBAAoB,GAAG;IACxB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,cAAc,EAAE,mBAAmB,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;IAChF,gBAAgB,EAAE,eAAe,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;IACzD,aAAa,EAAE,cAAc,CAAC;CACjC,CAAC;AAEF,KAAK,qBAAqB,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,cAAc,EAAE,kBAAkB,CAAC;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,oBAAoB,CAAC;CACpC,CAAC;AAEF,wBAAgB,gCAAgC,CAAC,EAAE,QAAQ,EAAE,cAAc,EAAE,gBAAgB,EAAE,aAAa,EAAE,EAAE,oBAAoB,GAAG,qBAAqB,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"migrateDataToLatestSchemaVersion.d.ts","sourceRoot":"","sources":["../../../../src/common/VersionedSchema/Utils/migrateDataToLatestSchemaVersion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AASpF,KAAK,oBAAoB,GAAG;IACxB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC9B,cAAc,EAAE,mBAAmB,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;IAChF,gBAAgB,EAAE,eAAe,CAAC,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;IACzD,aAAa,EAAE,cAAc,CAAC;CACjC,CAAC;AAEF,KAAK,qBAAqB,GAAG;IACzB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,cAAc,EAAE,kBAAkB,CAAC;IACnC,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,oBAAoB,CAAC;CACpC,CAAC;AAEF,wBAAgB,gCAAgC,CAAC,EAAE,QAAQ,EAAE,cAAc,EAAE,gBAAgB,EAAE,aAAa,EAAE,EAAE,oBAAoB,GAAG,qBAAqB,GAAG,IAAI,CAiElK"}
|
|
@@ -22,19 +22,26 @@ function migrateDataToLatestSchemaVersion({ rawInput, migrationPlans, versionedS
|
|
|
22
22
|
const actualVersionIndex = versionedSchemas.length - 1;
|
|
23
23
|
const actualSchema = versionedSchemas[actualVersionIndex];
|
|
24
24
|
for (let idx = guessedVersion.lastVersionIndex; idx < versionedSchemas.length - 1; idx++) {
|
|
25
|
-
const
|
|
25
|
+
const currentVersionSchema = versionedSchemas[idx];
|
|
26
|
+
const { error: firstError } = currentVersionSchema.schema.validate(currentData);
|
|
26
27
|
if (firstError) {
|
|
27
28
|
(0, getCurrentErrorMessage_1.getCurrentErrorMessage)(firstError, replacingKeysMap);
|
|
28
29
|
}
|
|
29
|
-
const fromVersion =
|
|
30
|
+
const fromVersion = currentVersionSchema.version;
|
|
30
31
|
const migrationPlan = migrationPlans.find(p => p.fromVersion === fromVersion);
|
|
31
32
|
if (!migrationPlan) {
|
|
32
|
-
|
|
33
|
+
const availableVersions = migrationPlans.map(p => p.fromVersion).join(', ');
|
|
34
|
+
throw new Error(`No migration plan from ${fromVersion}. ` +
|
|
35
|
+
`Available migration plans: ${availableVersions}. ` +
|
|
36
|
+
`This usually means the migration chain is incomplete.`);
|
|
33
37
|
}
|
|
38
|
+
const toVersion = versionedSchemas[idx + 1].version;
|
|
34
39
|
const migratedRaw = migrationPlan.migrate(currentData);
|
|
35
40
|
const { error } = versionedSchemas[idx + 1].schema.validate(migratedRaw, { allowUnknown: false });
|
|
36
41
|
if (error) {
|
|
37
|
-
throw new Error(
|
|
42
|
+
throw new Error(`Migration from ${fromVersion} to ${toVersion} failed validation. ` +
|
|
43
|
+
`Error: ${error.message}. ` +
|
|
44
|
+
`Migration description: ${migrationPlan.description || 'No description provided'}.`);
|
|
38
45
|
}
|
|
39
46
|
currentData = { ...migratedRaw };
|
|
40
47
|
const isLastIteration = idx + 1 === actualVersionIndex;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { TRawOptions } from '../common/TRawOptions';
|
|
2
|
+
import { WriteClient } from './WriteClient';
|
|
3
|
+
export declare class OpenApiClient {
|
|
4
|
+
private _writeClient;
|
|
5
|
+
get writeClient(): WriteClient;
|
|
6
|
+
private normalizeOptions;
|
|
7
|
+
private addDefaultValues;
|
|
8
|
+
private cleanOutputDirectories;
|
|
9
|
+
private generateCodeForItems;
|
|
10
|
+
private generateSingle;
|
|
11
|
+
generate(rawOptions: TRawOptions): Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=OpenApiClient.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OpenApiClient.d.ts","sourceRoot":"","sources":["../../src/core/OpenApiClient.ts"],"names":[],"mappings":"AAGA,OAAO,EAAgB,WAAW,EAAsB,MAAM,uBAAuB,CAAC;AActF,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,qBAAa,aAAa;IACtB,OAAO,CAAC,YAAY,CAA4B;IAEhD,IAAW,WAAW,gBAKrB;IAED,OAAO,CAAC,gBAAgB;IAaxB,OAAO,CAAC,gBAAgB;YAyBV,sBAAsB;YAUtB,oBAAoB;YAmCpB,cAAc;IAiFtB,QAAQ,CAAC,UAAU,EAAE,WAAW;CAWzC"}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OpenApiClient = void 0;
|
|
4
|
+
const Consts_1 = require("../common/Consts");
|
|
5
|
+
const Logger_1 = require("../common/Logger");
|
|
6
|
+
const LoggerMessages_1 = require("../common/LoggerMessages");
|
|
7
|
+
const fileSystemHelpers_1 = require("../common/utils/fileSystemHelpers");
|
|
8
|
+
const pathHelpers_1 = require("../common/utils/pathHelpers");
|
|
9
|
+
const Parser_1 = require("./api/v2/Parser");
|
|
10
|
+
const Parser_2 = require("./api/v3/Parser");
|
|
11
|
+
const Context_1 = require("./Context");
|
|
12
|
+
const getOpenApiSpec_1 = require("./utils/getOpenApiSpec");
|
|
13
|
+
const getOpenApiVersion_1 = require("./utils/getOpenApiVersion");
|
|
14
|
+
const getOutputPaths_1 = require("./utils/getOutputPaths");
|
|
15
|
+
const postProcessClient_1 = require("./utils/postProcessClient");
|
|
16
|
+
const registerHandlebarTemplates_1 = require("./utils/registerHandlebarTemplates");
|
|
17
|
+
const WriteClient_1 = require("./WriteClient");
|
|
18
|
+
class OpenApiClient {
|
|
19
|
+
_writeClient = null;
|
|
20
|
+
get writeClient() {
|
|
21
|
+
if (!this._writeClient) {
|
|
22
|
+
throw new Error('WriteClient must be initialized');
|
|
23
|
+
}
|
|
24
|
+
return this._writeClient;
|
|
25
|
+
}
|
|
26
|
+
normalizeOptions(rawOptions) {
|
|
27
|
+
if (rawOptions.items && rawOptions.items.length > 0) {
|
|
28
|
+
// Для items: Наследуем глобальный request, если не переопределён
|
|
29
|
+
return rawOptions.items.map(item => ({
|
|
30
|
+
...item,
|
|
31
|
+
request: item.request ?? rawOptions.request, // ?? для fallback на глобальный
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
// Плоский формат (из CLI или старого конфига): Один item с глобальным request
|
|
36
|
+
return [rawOptions];
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
addDefaultValues(item) {
|
|
40
|
+
return {
|
|
41
|
+
input: item.input || Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.input,
|
|
42
|
+
output: item.output || Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.output,
|
|
43
|
+
outputCore: item.outputCore || Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.outputCore,
|
|
44
|
+
outputServices: item.outputServices || Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.outputServices,
|
|
45
|
+
outputModels: item.outputModels || Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.outputModels,
|
|
46
|
+
outputSchemas: item.outputSchemas || Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.outputSchemas,
|
|
47
|
+
httpClient: item.httpClient || Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.httpClient,
|
|
48
|
+
useOptions: item.useOptions ?? Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.useOptions,
|
|
49
|
+
useUnionTypes: item.useUnionTypes ?? Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.useUnionTypes,
|
|
50
|
+
excludeCoreServiceFiles: item.excludeCoreServiceFiles ?? Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.excludeCoreServiceFiles,
|
|
51
|
+
includeSchemasFiles: item.includeSchemasFiles ?? Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.includeSchemasFiles,
|
|
52
|
+
request: item.request || Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.request,
|
|
53
|
+
interfacePrefix: item.interfacePrefix || Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.interfacePrefix,
|
|
54
|
+
enumPrefix: item.enumPrefix || Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.enumPrefix,
|
|
55
|
+
typePrefix: item.typePrefix || Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.typePrefix,
|
|
56
|
+
useCancelableRequest: item.useCancelableRequest ?? Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.useCancelableRequest,
|
|
57
|
+
logLevel: item.logLevel || Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.logLevel,
|
|
58
|
+
logTarget: item.logTarget || Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.logTarget,
|
|
59
|
+
sortByRequired: item.sortByRequired ?? Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.sortByRequired,
|
|
60
|
+
useSeparatedIndexes: item.useSeparatedIndexes ?? Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.useSeparatedIndexes,
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
async cleanOutputDirectories(option) {
|
|
64
|
+
const outputDirs = [option.output, option.outputCore, option.outputSchemas, option.outputModels, option.outputServices];
|
|
65
|
+
for (const dir of outputDirs) {
|
|
66
|
+
if (dir) {
|
|
67
|
+
await fileSystemHelpers_1.fileSystemHelpers.rmdir(dir);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async generateCodeForItems(items) {
|
|
72
|
+
if (items.length === 0) {
|
|
73
|
+
throw new Error(LoggerMessages_1.LOGGER_MESSAGES.GENERATION.NO_OPTIONS);
|
|
74
|
+
}
|
|
75
|
+
this.writeClient.logger.forceInfo(LoggerMessages_1.LOGGER_MESSAGES.GENERATION.STARTED(items.length));
|
|
76
|
+
try {
|
|
77
|
+
const start = process.hrtime();
|
|
78
|
+
for (const option of items) {
|
|
79
|
+
await this.cleanOutputDirectories(option);
|
|
80
|
+
}
|
|
81
|
+
for (const option of items) {
|
|
82
|
+
const fileStart = process.hrtime();
|
|
83
|
+
await this.generateSingle(option);
|
|
84
|
+
const [fileSeconds, fileNanoseconds] = process.hrtime(fileStart);
|
|
85
|
+
const fileDuration = fileSeconds + fileNanoseconds / 1e6;
|
|
86
|
+
this.writeClient.logger.info(LoggerMessages_1.LOGGER_MESSAGES.GENERATION.DURATION_FOR_FILE(option.input, fileDuration.toFixed(2)));
|
|
87
|
+
}
|
|
88
|
+
if (items[0]?.useSeparatedIndexes) {
|
|
89
|
+
await this.writeClient.combineAndWrightSimple();
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
await this.writeClient.combineAndWrite();
|
|
93
|
+
}
|
|
94
|
+
this.writeClient.logger.forceInfo(LoggerMessages_1.LOGGER_MESSAGES.GENERATION.FINISHED);
|
|
95
|
+
const [seconds, nanoseconds] = process.hrtime(start);
|
|
96
|
+
const durationInMs = seconds + nanoseconds / 1e6;
|
|
97
|
+
this.writeClient.logger.forceInfo(LoggerMessages_1.LOGGER_MESSAGES.GENERATION.FINISHED_WITH_DURATION(durationInMs.toFixed(2)));
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
this.writeClient.logger.error(LoggerMessages_1.LOGGER_MESSAGES.ERROR.GENERIC(error.message));
|
|
101
|
+
}
|
|
102
|
+
this.writeClient.logger.shutdownLogger();
|
|
103
|
+
}
|
|
104
|
+
async generateSingle(item) {
|
|
105
|
+
const { input, output, outputCore, outputServices, outputModels, outputSchemas, httpClient, useOptions, useUnionTypes, excludeCoreServiceFiles, includeSchemasFiles, request, interfacePrefix, enumPrefix, typePrefix, useCancelableRequest, sortByRequired, useSeparatedIndexes, } = item;
|
|
106
|
+
const outputPaths = (0, getOutputPaths_1.getOutputPaths)({
|
|
107
|
+
output,
|
|
108
|
+
outputCore,
|
|
109
|
+
outputServices,
|
|
110
|
+
outputModels,
|
|
111
|
+
outputSchemas,
|
|
112
|
+
});
|
|
113
|
+
const absoluteInput = (0, pathHelpers_1.resolveHelper)(process.cwd(), input);
|
|
114
|
+
const context = new Context_1.Context({ input: absoluteInput, output: outputPaths, prefix: { interface: interfacePrefix, enum: enumPrefix, type: typePrefix }, sortByRequired });
|
|
115
|
+
const openApi = await (0, getOpenApiSpec_1.getOpenApiSpec)(context, absoluteInput);
|
|
116
|
+
const openApiVersion = (0, getOpenApiVersion_1.getOpenApiVersion)(openApi);
|
|
117
|
+
const templates = (0, registerHandlebarTemplates_1.registerHandlebarTemplates)({
|
|
118
|
+
httpClient,
|
|
119
|
+
useUnionTypes,
|
|
120
|
+
useOptions,
|
|
121
|
+
});
|
|
122
|
+
this.writeClient.logger.info(LoggerMessages_1.LOGGER_MESSAGES.OPENAPI.DEFINING_VERSION);
|
|
123
|
+
switch (openApiVersion) {
|
|
124
|
+
case getOpenApiVersion_1.OpenApiVersion.V2: {
|
|
125
|
+
const client = new Parser_1.Parser(context).parse(openApi);
|
|
126
|
+
const clientFinal = (0, postProcessClient_1.postProcessClient)(client);
|
|
127
|
+
this.writeClient.logger.info(LoggerMessages_1.LOGGER_MESSAGES.OPENAPI.WRITING_V2);
|
|
128
|
+
await this.writeClient.writeClient({
|
|
129
|
+
client: clientFinal,
|
|
130
|
+
templates,
|
|
131
|
+
outputPaths,
|
|
132
|
+
httpClient,
|
|
133
|
+
useOptions,
|
|
134
|
+
useUnionTypes,
|
|
135
|
+
excludeCoreServiceFiles,
|
|
136
|
+
includeSchemasFiles,
|
|
137
|
+
request,
|
|
138
|
+
useCancelableRequest,
|
|
139
|
+
useSeparatedIndexes,
|
|
140
|
+
});
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
case getOpenApiVersion_1.OpenApiVersion.V3: {
|
|
144
|
+
const client = new Parser_2.Parser(context).parse(openApi);
|
|
145
|
+
const clientFinal = (0, postProcessClient_1.postProcessClient)(client);
|
|
146
|
+
this.writeClient.logger.info(LoggerMessages_1.LOGGER_MESSAGES.OPENAPI.WRITING_V3);
|
|
147
|
+
await this.writeClient.writeClient({
|
|
148
|
+
client: clientFinal,
|
|
149
|
+
templates,
|
|
150
|
+
outputPaths,
|
|
151
|
+
httpClient,
|
|
152
|
+
useOptions,
|
|
153
|
+
useUnionTypes,
|
|
154
|
+
excludeCoreServiceFiles,
|
|
155
|
+
includeSchemasFiles,
|
|
156
|
+
request,
|
|
157
|
+
useCancelableRequest,
|
|
158
|
+
useSeparatedIndexes,
|
|
159
|
+
});
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async generate(rawOptions) {
|
|
165
|
+
const logger = new Logger_1.Logger({
|
|
166
|
+
level: rawOptions.logLevel ?? Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.logLevel,
|
|
167
|
+
instanceId: 'client',
|
|
168
|
+
logOutput: rawOptions.logTarget ?? Consts_1.COMMON_DEFAULT_OPTIONS_VALUES.logTarget,
|
|
169
|
+
});
|
|
170
|
+
this._writeClient = new WriteClient_1.WriteClient(logger);
|
|
171
|
+
const items = this.normalizeOptions(rawOptions).map(item => this.addDefaultValues(item));
|
|
172
|
+
await this.generateCodeForItems(items);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
exports.OpenApiClient = OpenApiClient;
|
|
@@ -46,7 +46,7 @@ type TAPIClientGeneratorConfig = Omit<TWriteClientProps, 'httpClient' | 'useOpti
|
|
|
46
46
|
export declare class WriteClient {
|
|
47
47
|
private config;
|
|
48
48
|
private _logger;
|
|
49
|
-
constructor();
|
|
49
|
+
constructor(logger?: Logger);
|
|
50
50
|
/**
|
|
51
51
|
* Write our OpenAPI client, using the given templates at the given output
|
|
52
52
|
* @param client Client object with all the models, services, etc.
|
|
@@ -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,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAE1D,OAAO,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAG/D,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAExE;;;;;;;;;;;;GAYG;AACH,KAAK,iBAAiB,GAAG;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,SAAS,CAAC;IACrB,WAAW,EAAE,WAAW,CAAC;IACzB,UAAU,EAAE,UAAU,CAAC;IACvB,UAAU,EAAE,OAAO,CAAC;IACpB,aAAa,EAAE,OAAO,CAAC;IACvB,uBAAuB,EAAE,OAAO,CAAC;IACjC,mBAAmB,EAAE,OAAO,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,mBAAmB,CAAC,EAAE,OAAO,CAAC;CACjC,CAAC;AAEF,KAAK,yBAAyB,GAAG,IAAI,CAAC,iBAAiB,EAAE,YAAY,GAAG,YAAY,GAAG,SAAS,GAAG,sBAAsB,GAAG,qBAAqB,CAAC,CAAC;AAEnJ;;GAEG;AACH,qBAAa,WAAW;IACpB,OAAO,CAAC,MAAM,CAAuD;IACrE,OAAO,CAAC,OAAO,CAAS
|
|
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,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAC3D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAE1D,OAAO,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAG/D,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kCAAkC,CAAC;AAC5E,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AAExE;;;;;;;;;;;;GAYG;AACH,KAAK,iBAAiB,GAAG;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,SAAS,CAAC;IACrB,WAAW,EAAE,WAAW,CAAC;IACzB,UAAU,EAAE,UAAU,CAAC;IACvB,UAAU,EAAE,OAAO,CAAC;IACpB,aAAa,EAAE,OAAO,CAAC;IACvB,uBAAuB,EAAE,OAAO,CAAC;IACjC,mBAAmB,EAAE,OAAO,CAAC;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,mBAAmB,CAAC,EAAE,OAAO,CAAC;CACjC,CAAC;AAEF,KAAK,yBAAyB,GAAG,IAAI,CAAC,iBAAiB,EAAE,YAAY,GAAG,YAAY,GAAG,SAAS,GAAG,sBAAsB,GAAG,qBAAqB,CAAC,CAAC;AAEnJ;;GAEG;AACH,qBAAa,WAAW;IACpB,OAAO,CAAC,MAAM,CAAuD;IACrE,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,CAAC,EAAE,MAAM;IAQ3B;;;;;;;;;;;;OAYG;IACG,WAAW,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IA2F5D;;;OAGG;IACH,6BAA6B,CAAC,MAAM,EAAE,yBAAyB;IAUzD,eAAe;IAKf,sBAAsB;IAK5B,IAAW,MAAM,WAEhB;IAED,OAAO,CAAC,yBAAyB;IAyCjC,OAAO,CAAC,mBAAmB;YA4Db,gBAAgB;YAUhB,uBAAuB;IAMrC,OAAO,CAAC,aAAa;IAIrB,OAAO,CAAC,iBAAiB;IAezB,OAAO,CAAC,uBAAuB;IAe/B,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,aAAa;IAId,eAAe,yBAAmB;IAClC,oBAAoB,8BAAwB;IAC5C,oBAAoB,8BAAwB;IAC5C,iBAAiB,2BAAqB;IACtC,sBAAsB,gCAA0B;IAChD,kBAAkB,4BAAsB;IACxC,uBAAuB,iCAA2B;IAClD,mBAAmB,6BAAuB;IAC1C,wBAAwB,kCAA4B;IACpD,sBAAsB,gCAA0B;CAC1D"}
|
package/dist/core/WriteClient.js
CHANGED
|
@@ -24,8 +24,8 @@ const writeClientSimpleIndex_1 = require("./utils/writeClientSimpleIndex");
|
|
|
24
24
|
class WriteClient {
|
|
25
25
|
config = new Map();
|
|
26
26
|
_logger;
|
|
27
|
-
constructor() {
|
|
28
|
-
this._logger = new Logger_1.Logger({
|
|
27
|
+
constructor(logger) {
|
|
28
|
+
this._logger = logger || new Logger_1.Logger({
|
|
29
29
|
level: Enums_1.ELogLevel.ERROR,
|
|
30
30
|
instanceId: 'client',
|
|
31
31
|
logOutput: Enums_1.ELogOutput.CONSOLE,
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TRawOptions } from '../common/TRawOptions';
|
|
2
2
|
export { HttpClient } from './types/enums/HttpClient.enum';
|
|
3
|
-
|
|
4
|
-
* @throws {Error} If options validation fails or generation encounters an error
|
|
5
|
-
* @returns {Promise<void>}
|
|
6
|
-
*/
|
|
7
|
-
export declare function generate(options: TOptions | TOptions[] | TMultiOptions): Promise<void>;
|
|
3
|
+
export declare function generate(rawOptions: TRawOptions): Promise<void>;
|
|
8
4
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAE3D,wBAAsB,QAAQ,CAAC,UAAU,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAGrE"}
|
package/dist/core/index.js
CHANGED
|
@@ -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
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
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
|
-
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts-openapi-codegen",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-beta.0",
|
|
4
4
|
"description": "Library that generates Typescript clients based on the OpenAPI specification. It bases on openapi-typescript-codegen",
|
|
5
5
|
"author": "Alexey Zverev",
|
|
6
6
|
"homepage": "https://github.com/ozonophore/openapi-codegen.git",
|
package/dist/common/Options.d.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { HttpClient } from '../core';
|
|
2
|
-
export type TOptions = {
|
|
3
|
-
input: string | Record<string, any>;
|
|
4
|
-
output: string;
|
|
5
|
-
outputCore?: string;
|
|
6
|
-
outputServices?: string;
|
|
7
|
-
outputModels?: string;
|
|
8
|
-
outputSchemas?: string;
|
|
9
|
-
httpClient?: HttpClient;
|
|
10
|
-
useOptions?: boolean;
|
|
11
|
-
useUnionTypes?: boolean;
|
|
12
|
-
excludeCoreServiceFiles?: boolean;
|
|
13
|
-
includeSchemasFiles?: boolean;
|
|
14
|
-
request?: string;
|
|
15
|
-
write?: boolean;
|
|
16
|
-
interfacePrefix?: string;
|
|
17
|
-
enumPrefix?: string;
|
|
18
|
-
typePrefix?: string;
|
|
19
|
-
useCancelableRequest?: boolean;
|
|
20
|
-
sortByRequired?: boolean;
|
|
21
|
-
useSeparatedIndexes?: boolean;
|
|
22
|
-
};
|
|
23
|
-
export type TMultiOptions = {
|
|
24
|
-
items: TOptions[];
|
|
25
|
-
} & Omit<TOptions, 'input' | 'output'>;
|
|
26
|
-
//# sourceMappingURL=Options.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Options.d.ts","sourceRoot":"","sources":["../../src/common/Options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,MAAM,MAAM,QAAQ,GAAG;IACnB,KAAK,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,mBAAmB,CAAC,EAAE,OAAO,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IACxB,KAAK,EAAE,QAAQ,EAAE,CAAC;CACrB,GAAG,IAAI,CAAC,QAAQ,EAAE,OAAO,GAAG,QAAQ,CAAC,CAAC"}
|