@1szx1/vite-plugin-swagger2ts 1.3.12 → 1.3.13
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/bin.cjs +2 -1
- package/dist/bin.mjs +2 -1
- package/dist/index.cjs +9 -7
- package/dist/index.mjs +8 -6
- package/package.json +2 -1
package/dist/bin.cjs
CHANGED
package/dist/bin.mjs
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -5,14 +5,15 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
const fs = require('fs');
|
|
6
6
|
const path = require('path');
|
|
7
7
|
const swagger2openapi = require('swagger2openapi');
|
|
8
|
+
const chalk = require('chalk');
|
|
9
|
+
const prettier = require('prettier');
|
|
8
10
|
const fetch = require('cross-fetch');
|
|
9
11
|
const unconfig = require('unconfig');
|
|
10
|
-
const chalk = require('chalk');
|
|
11
12
|
|
|
12
13
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
13
14
|
|
|
14
|
-
const fetch__default = /*#__PURE__*/_interopDefaultCompat(fetch);
|
|
15
15
|
const chalk__default = /*#__PURE__*/_interopDefaultCompat(chalk);
|
|
16
|
+
const fetch__default = /*#__PURE__*/_interopDefaultCompat(fetch);
|
|
16
17
|
|
|
17
18
|
const pluginName = "vite-plugin-swagger2ts";
|
|
18
19
|
const CODE_PREFIX = `/* eslint-disable */
|
|
@@ -229,7 +230,8 @@ function generatorMethodType(intersection) {
|
|
|
229
230
|
return `export type ${toPascalCase(method)}${toPascalCase(key)}<T extends ${paths}>> = ${intersection}[T]['${method}']['param']['${key}'];`;
|
|
230
231
|
};
|
|
231
232
|
return METHODS.reduce((total, method) => {
|
|
232
|
-
const responseCode =
|
|
233
|
+
const responseCode = `// ${method}
|
|
234
|
+
export type ${toPascalCase(method)}${toPascalCase("response")}<T extends keyof ${intersection}> = ${intersection}[T]['${method}']['response'];`;
|
|
233
235
|
const code = paramKeys.reduce((total1, key) => `${total1}
|
|
234
236
|
${genTypeCode(method, key)}`, responseCode);
|
|
235
237
|
return `${total}${total && `
|
|
@@ -313,10 +315,10 @@ async function loadSwaggerSource(options) {
|
|
|
313
315
|
return a;
|
|
314
316
|
}, "");
|
|
315
317
|
const outputFile = path.resolve(process.cwd(), output);
|
|
316
|
-
fs.writeFileSync(outputFile, CODE_PREFIX + code + suffix);
|
|
318
|
+
fs.writeFileSync(outputFile, await prettier.format(CODE_PREFIX + code + suffix, { parser: "typescript" }));
|
|
317
319
|
return { sources, interfaces };
|
|
318
320
|
}
|
|
319
|
-
function loadGlobTypes({ glob, output }) {
|
|
321
|
+
async function loadGlobTypes({ glob, output }) {
|
|
320
322
|
if (!glob)
|
|
321
323
|
return;
|
|
322
324
|
const outputFile = path.resolve(process.cwd(), glob.output || "auto-types.d.ts");
|
|
@@ -336,13 +338,13 @@ declare global {
|
|
|
336
338
|
${generatorMethodType(intersection)}
|
|
337
339
|
}
|
|
338
340
|
}`;
|
|
339
|
-
fs.writeFileSync(outputFile, code);
|
|
341
|
+
fs.writeFileSync(outputFile, await prettier.format(code, { parser: "typescript" }));
|
|
340
342
|
}
|
|
341
343
|
function swagger2TsPlugin(userOptions) {
|
|
342
344
|
(async () => {
|
|
343
345
|
const options = await resolveOptions(userOptions);
|
|
344
346
|
await Promise.all(options.map(loadSwaggerSource));
|
|
345
|
-
options.
|
|
347
|
+
await Promise.all(options.map(loadGlobTypes));
|
|
346
348
|
})();
|
|
347
349
|
return {
|
|
348
350
|
name: `${pluginName}`,
|
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { writeFileSync, readFileSync } from 'fs';
|
|
2
2
|
import { resolve, relative } from 'path';
|
|
3
3
|
import { convertObj } from 'swagger2openapi';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import { format } from 'prettier';
|
|
4
6
|
import fetch from 'cross-fetch';
|
|
5
7
|
import { loadConfig as loadConfig$1 } from 'unconfig';
|
|
6
|
-
import chalk from 'chalk';
|
|
7
8
|
|
|
8
9
|
const pluginName = "vite-plugin-swagger2ts";
|
|
9
10
|
const CODE_PREFIX = `/* eslint-disable */
|
|
@@ -220,7 +221,8 @@ function generatorMethodType(intersection) {
|
|
|
220
221
|
return `export type ${toPascalCase(method)}${toPascalCase(key)}<T extends ${paths}>> = ${intersection}[T]['${method}']['param']['${key}'];`;
|
|
221
222
|
};
|
|
222
223
|
return METHODS.reduce((total, method) => {
|
|
223
|
-
const responseCode =
|
|
224
|
+
const responseCode = `// ${method}
|
|
225
|
+
export type ${toPascalCase(method)}${toPascalCase("response")}<T extends keyof ${intersection}> = ${intersection}[T]['${method}']['response'];`;
|
|
224
226
|
const code = paramKeys.reduce((total1, key) => `${total1}
|
|
225
227
|
${genTypeCode(method, key)}`, responseCode);
|
|
226
228
|
return `${total}${total && `
|
|
@@ -304,10 +306,10 @@ async function loadSwaggerSource(options) {
|
|
|
304
306
|
return a;
|
|
305
307
|
}, "");
|
|
306
308
|
const outputFile = resolve(process.cwd(), output);
|
|
307
|
-
writeFileSync(outputFile, CODE_PREFIX + code + suffix);
|
|
309
|
+
writeFileSync(outputFile, await format(CODE_PREFIX + code + suffix, { parser: "typescript" }));
|
|
308
310
|
return { sources, interfaces };
|
|
309
311
|
}
|
|
310
|
-
function loadGlobTypes({ glob, output }) {
|
|
312
|
+
async function loadGlobTypes({ glob, output }) {
|
|
311
313
|
if (!glob)
|
|
312
314
|
return;
|
|
313
315
|
const outputFile = resolve(process.cwd(), glob.output || "auto-types.d.ts");
|
|
@@ -327,13 +329,13 @@ declare global {
|
|
|
327
329
|
${generatorMethodType(intersection)}
|
|
328
330
|
}
|
|
329
331
|
}`;
|
|
330
|
-
writeFileSync(outputFile, code);
|
|
332
|
+
writeFileSync(outputFile, await format(code, { parser: "typescript" }));
|
|
331
333
|
}
|
|
332
334
|
function swagger2TsPlugin(userOptions) {
|
|
333
335
|
(async () => {
|
|
334
336
|
const options = await resolveOptions(userOptions);
|
|
335
337
|
await Promise.all(options.map(loadSwaggerSource));
|
|
336
|
-
options.
|
|
338
|
+
await Promise.all(options.map(loadGlobTypes));
|
|
337
339
|
})();
|
|
338
340
|
return {
|
|
339
341
|
name: `${pluginName}`,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1szx1/vite-plugin-swagger2ts",
|
|
3
3
|
"description": "forked from https://github.com/morelearn1990/vite-plugin-swagger2ts",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.13",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "1SZX1 <2414126198@qq.com>",
|
|
7
7
|
"repository": {
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
"cross-fetch": "^3.1.5",
|
|
61
61
|
"luch-request": "^3.1.0",
|
|
62
62
|
"openapi3-ts": "^2.0.2",
|
|
63
|
+
"prettier": "^3.2.5",
|
|
63
64
|
"swagger2openapi": "^7.0.8",
|
|
64
65
|
"unconfig": "^0.3.9"
|
|
65
66
|
},
|