@paulpugovkin/api-docs-axios-ts-generator 1.0.9 → 1.0.12
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/package.json
CHANGED
|
@@ -6,6 +6,8 @@
|
|
|
6
6
|
* @param {Object} config - Конфигурация генератора
|
|
7
7
|
* @returns {string} - Сгенерированный код класса TypeScript
|
|
8
8
|
*/
|
|
9
|
+
const path = require('path');
|
|
10
|
+
|
|
9
11
|
function generateClass(name, methods, usedInterfaces, config) {
|
|
10
12
|
const axiosResponseImport =
|
|
11
13
|
'import { AxiosResponse, AxiosRequestConfig } from "axios";\n';
|
|
@@ -14,12 +16,17 @@ function generateClass(name, methods, usedInterfaces, config) {
|
|
|
14
16
|
const axiosPath = config?.imports?.axiosPath || 'axios';
|
|
15
17
|
const baseUrlPath = config?.imports?.baseUrlPath || './config/axios/axios';
|
|
16
18
|
|
|
19
|
+
// Определяем базовый путь для импорта интерфейсов (папка выше, чем папка с классами)
|
|
20
|
+
const interfaceImportPath = config?.outputDir
|
|
21
|
+
? path.relative(path.join(config.outputDir, 'classes'), config.outputDir)
|
|
22
|
+
: '../../';
|
|
23
|
+
|
|
17
24
|
// Импорты интерфейсов
|
|
18
25
|
let interfaceImport = '';
|
|
19
26
|
if (usedInterfaces && usedInterfaces.size > 0) {
|
|
20
27
|
interfaceImport = Array.from(usedInterfaces)
|
|
21
28
|
.sort()
|
|
22
|
-
.map((interfaceName) => `import { ${interfaceName} } from '
|
|
29
|
+
.map((interfaceName) => `import { ${interfaceName} } from '${interfaceImportPath}';`)
|
|
23
30
|
.join("\n");
|
|
24
31
|
}
|
|
25
32
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const {resolveType} = require("../resolve-type/resolveType"); // Импорт функции resolveType
|
|
2
|
+
const path = require("path");
|
|
2
3
|
|
|
3
4
|
function capitalizeOnlyFirst(text) {
|
|
4
5
|
return text ? text.charAt(0).toUpperCase() + text.slice(1) : text;
|
|
@@ -60,9 +61,14 @@ function generateInterface(name, schema, schemaRefs) {
|
|
|
60
61
|
props.push(` ${propName}: ${tsType};`);
|
|
61
62
|
}
|
|
62
63
|
|
|
64
|
+
// Определяем базовый путь для импорта интерфейсов
|
|
65
|
+
const interfaceImportPath = config?.outputDir
|
|
66
|
+
? path.relative(path.join(config.outputDir, 'interfaces'), config.outputDir)
|
|
67
|
+
: './';
|
|
68
|
+
|
|
63
69
|
const imports = Array.from(usedInterfaces)
|
|
64
70
|
.sort()
|
|
65
|
-
.map((interfaceName) => `import { ${interfaceName} } from '
|
|
71
|
+
.map((interfaceName) => `import { ${interfaceName} } from '${interfaceImportPath}';`)
|
|
66
72
|
.join("\n");
|
|
67
73
|
|
|
68
74
|
const extendsClause = extendsInterfaces.length
|
package/src/index.js
CHANGED
|
@@ -122,10 +122,10 @@ async function main() {
|
|
|
122
122
|
}
|
|
123
123
|
|
|
124
124
|
console.log(`Using API Docs URL: ${config.apiDocsUrl}`);
|
|
125
|
-
console.log(`Output directory: ${config.outputDir}`);
|
|
125
|
+
console.log(`Output directory: ${config.outputDir || 'Not specified - using default'}`);
|
|
126
126
|
|
|
127
127
|
// Определяем пути
|
|
128
|
-
const outputDir = config.outputDir;
|
|
128
|
+
const outputDir = config.outputDir || path.resolve(__dirname, "../generated");
|
|
129
129
|
const interfacesDir = config.interfacesDir || path.join(outputDir, "interfaces");
|
|
130
130
|
const classesDir = config.classesDir || path.join(outputDir, "classes");
|
|
131
131
|
const interfacesOpenApi = path.join(interfacesDir, "index.ts");
|
|
@@ -71,7 +71,7 @@ async function parseAndGenerate(jsonFile, config) {
|
|
|
71
71
|
const spec = JSON.parse(fs.readFileSync(jsonFile, {encoding: "utf-8"}));
|
|
72
72
|
|
|
73
73
|
// Определяем пути из конфигурации
|
|
74
|
-
const outputDir = config.outputDir;
|
|
74
|
+
const outputDir = config.outputDir || path.resolve(__dirname, "../../generated");
|
|
75
75
|
const interfacesDir = config.interfacesDir || path.join(outputDir, "interfaces");
|
|
76
76
|
const classesDir = config.classesDir || path.join(outputDir, "classes");
|
|
77
77
|
|
|
@@ -86,7 +86,8 @@ async function parseAndGenerate(jsonFile, config) {
|
|
|
86
86
|
const interfaceCode = generateInterface(
|
|
87
87
|
schemaName,
|
|
88
88
|
schema,
|
|
89
|
-
schemaRefs
|
|
89
|
+
schemaRefs,
|
|
90
|
+
config
|
|
90
91
|
);
|
|
91
92
|
fs.writeFileSync(
|
|
92
93
|
path.join(interfacesDir, `${schemaName}.ts`),
|