@1szx1/vite-plugin-swagger2ts 1.3.0 → 1.3.2
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 +1 -0
- package/dist/bin.mjs +1 -0
- package/dist/index.cjs +10 -8
- package/dist/index.mjs +9 -8
- package/package.json +111 -107
package/dist/bin.cjs
CHANGED
package/dist/bin.mjs
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -7,10 +7,12 @@ const path = require('path');
|
|
|
7
7
|
const swagger2openapi = require('swagger2openapi');
|
|
8
8
|
const fetch = require('cross-fetch');
|
|
9
9
|
const unconfig = require('unconfig');
|
|
10
|
+
const chalk = require('chalk');
|
|
10
11
|
|
|
11
12
|
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
|
|
12
13
|
|
|
13
14
|
const fetch__default = /*#__PURE__*/_interopDefaultCompat(fetch);
|
|
15
|
+
const chalk__default = /*#__PURE__*/_interopDefaultCompat(chalk);
|
|
14
16
|
|
|
15
17
|
function loadConfig() {
|
|
16
18
|
return unconfig.loadConfig({
|
|
@@ -231,14 +233,14 @@ function convertObjPromise(docs) {
|
|
|
231
233
|
async function loadSwaggerSource(options) {
|
|
232
234
|
const { swaggerUrl, jsonUrl, jsonPath, output, formatDocs, formatSchema } = options;
|
|
233
235
|
async function genInterface(docs, docsName) {
|
|
234
|
-
|
|
235
|
-
if (!("openapi" in
|
|
236
|
+
docs = formatDocs ? formatDocs(docs) : docs;
|
|
237
|
+
if (!("openapi" in docs)) {
|
|
236
238
|
if (docs.swagger)
|
|
237
|
-
|
|
239
|
+
docs = await convertObjPromise(docs);
|
|
238
240
|
else
|
|
239
241
|
throw new Error(JSON.stringify(docs));
|
|
240
242
|
}
|
|
241
|
-
return generateDocs(
|
|
243
|
+
return generateDocs(docs, { docsName, baseUrl: docs.basePath ?? "", formatSchema });
|
|
242
244
|
}
|
|
243
245
|
async function genResourcesCode(source) {
|
|
244
246
|
const { url, name } = source;
|
|
@@ -247,7 +249,7 @@ async function loadSwaggerSource(options) {
|
|
|
247
249
|
const code2 = await genInterface(docs, name);
|
|
248
250
|
return code2;
|
|
249
251
|
} catch (error) {
|
|
250
|
-
console.log(
|
|
252
|
+
console.log(chalk__default.yellow(`[vite-plugin-swagger2ts]: ${name} error;`) + error.message);
|
|
251
253
|
return "";
|
|
252
254
|
}
|
|
253
255
|
}
|
|
@@ -255,18 +257,18 @@ async function loadSwaggerSource(options) {
|
|
|
255
257
|
let sources2 = void 0;
|
|
256
258
|
let interfaces2 = [];
|
|
257
259
|
if (typeof swaggerUrl === "string") {
|
|
258
|
-
const resources = await fetchUrl(`${swaggerUrl}/swagger-resources
|
|
260
|
+
const resources = await fetchUrl(`${swaggerUrl}/swagger-resources;`).catch((error) => error);
|
|
259
261
|
if (Array.isArray(resources)) {
|
|
260
262
|
sources2 = resources;
|
|
261
263
|
interfaces2.push(...await Promise.all(sources2.map(genResourcesCode)));
|
|
262
264
|
} else {
|
|
263
|
-
console.log(
|
|
265
|
+
console.log(chalk__default.yellow(`[vite-plugin-swagger2ts]: resources error`) + JSON.stringify(resources));
|
|
264
266
|
}
|
|
265
267
|
}
|
|
266
268
|
if (typeof jsonUrl === "string") {
|
|
267
269
|
const swaggerJson = await fetchUrl(jsonUrl);
|
|
268
270
|
if (!swaggerJson.info)
|
|
269
|
-
return console.log(
|
|
271
|
+
return console.log(chalk__default.yellow(`[vite-plugin-swagger2ts]: jsonUrl error;`) + JSON.stringify(swaggerJson));
|
|
270
272
|
interfaces2.push(await genInterface(swaggerJson, getApiName(swaggerJson)));
|
|
271
273
|
}
|
|
272
274
|
if (typeof jsonPath === "string") {
|
package/dist/index.mjs
CHANGED
|
@@ -3,6 +3,7 @@ import { resolve } from 'path';
|
|
|
3
3
|
import { convertObj } from 'swagger2openapi';
|
|
4
4
|
import fetch from 'cross-fetch';
|
|
5
5
|
import { loadConfig as loadConfig$1 } from 'unconfig';
|
|
6
|
+
import chalk from 'chalk';
|
|
6
7
|
|
|
7
8
|
function loadConfig() {
|
|
8
9
|
return loadConfig$1({
|
|
@@ -223,14 +224,14 @@ function convertObjPromise(docs) {
|
|
|
223
224
|
async function loadSwaggerSource(options) {
|
|
224
225
|
const { swaggerUrl, jsonUrl, jsonPath, output, formatDocs, formatSchema } = options;
|
|
225
226
|
async function genInterface(docs, docsName) {
|
|
226
|
-
|
|
227
|
-
if (!("openapi" in
|
|
227
|
+
docs = formatDocs ? formatDocs(docs) : docs;
|
|
228
|
+
if (!("openapi" in docs)) {
|
|
228
229
|
if (docs.swagger)
|
|
229
|
-
|
|
230
|
+
docs = await convertObjPromise(docs);
|
|
230
231
|
else
|
|
231
232
|
throw new Error(JSON.stringify(docs));
|
|
232
233
|
}
|
|
233
|
-
return generateDocs(
|
|
234
|
+
return generateDocs(docs, { docsName, baseUrl: docs.basePath ?? "", formatSchema });
|
|
234
235
|
}
|
|
235
236
|
async function genResourcesCode(source) {
|
|
236
237
|
const { url, name } = source;
|
|
@@ -239,7 +240,7 @@ async function loadSwaggerSource(options) {
|
|
|
239
240
|
const code2 = await genInterface(docs, name);
|
|
240
241
|
return code2;
|
|
241
242
|
} catch (error) {
|
|
242
|
-
console.log(
|
|
243
|
+
console.log(chalk.yellow(`[vite-plugin-swagger2ts]: ${name} error;`) + error.message);
|
|
243
244
|
return "";
|
|
244
245
|
}
|
|
245
246
|
}
|
|
@@ -247,18 +248,18 @@ async function loadSwaggerSource(options) {
|
|
|
247
248
|
let sources2 = void 0;
|
|
248
249
|
let interfaces2 = [];
|
|
249
250
|
if (typeof swaggerUrl === "string") {
|
|
250
|
-
const resources = await fetchUrl(`${swaggerUrl}/swagger-resources
|
|
251
|
+
const resources = await fetchUrl(`${swaggerUrl}/swagger-resources;`).catch((error) => error);
|
|
251
252
|
if (Array.isArray(resources)) {
|
|
252
253
|
sources2 = resources;
|
|
253
254
|
interfaces2.push(...await Promise.all(sources2.map(genResourcesCode)));
|
|
254
255
|
} else {
|
|
255
|
-
console.log(
|
|
256
|
+
console.log(chalk.yellow(`[vite-plugin-swagger2ts]: resources error`) + JSON.stringify(resources));
|
|
256
257
|
}
|
|
257
258
|
}
|
|
258
259
|
if (typeof jsonUrl === "string") {
|
|
259
260
|
const swaggerJson = await fetchUrl(jsonUrl);
|
|
260
261
|
if (!swaggerJson.info)
|
|
261
|
-
return console.log(
|
|
262
|
+
return console.log(chalk.yellow(`[vite-plugin-swagger2ts]: jsonUrl error;`) + JSON.stringify(swaggerJson));
|
|
262
263
|
interfaces2.push(await genInterface(swaggerJson, getApiName(swaggerJson)));
|
|
263
264
|
}
|
|
264
265
|
if (typeof jsonPath === "string") {
|
package/package.json
CHANGED
|
@@ -1,108 +1,112 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@1szx1/vite-plugin-swagger2ts",
|
|
3
|
-
"description": "forked from https://github.com/morelearn1990/vite-plugin-swagger2ts",
|
|
4
|
-
"version": "1.3.
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"author": "1SZX1 <2414126198@qq.com>",
|
|
7
|
-
"repository": {
|
|
8
|
-
"type": "git",
|
|
9
|
-
"url": "https://github.com/1SZX1/vite-plugin-swagger2ts"
|
|
10
|
-
},
|
|
11
|
-
"homepage": "https://github.com/1SZX1/vite-plugin-swagger2ts",
|
|
12
|
-
"bugs": "https://github.com/1SZX1/vite-plugin-swagger2ts/issues",
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
"
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
},
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
"
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
"@
|
|
73
|
-
"@
|
|
74
|
-
"@
|
|
75
|
-
"@
|
|
76
|
-
"@
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"eslint": "^
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
},
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@1szx1/vite-plugin-swagger2ts",
|
|
3
|
+
"description": "forked from https://github.com/morelearn1990/vite-plugin-swagger2ts",
|
|
4
|
+
"version": "1.3.2",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "1SZX1 <2414126198@qq.com>",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/1SZX1/vite-plugin-swagger2ts"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://github.com/1SZX1/vite-plugin-swagger2ts",
|
|
12
|
+
"bugs": "https://github.com/1SZX1/vite-plugin-swagger2ts/issues",
|
|
13
|
+
"publishConfig": {
|
|
14
|
+
"registry": "https://registry.npmjs.org"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"require": "./dist/index.cjs",
|
|
22
|
+
"import": "./dist/index.mjs",
|
|
23
|
+
"types": "./dist/index.d.ts"
|
|
24
|
+
},
|
|
25
|
+
"./adapters": {
|
|
26
|
+
"require": "./dist/adapters.cjs",
|
|
27
|
+
"import": "./dist/adapters.mjs",
|
|
28
|
+
"types": "./dist/adapters.d.ts"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"main": "dist/index.cjs",
|
|
32
|
+
"module": "dist/index.mjs",
|
|
33
|
+
"types": "dist/index.d.ts",
|
|
34
|
+
"typesVersions": {
|
|
35
|
+
"*": {
|
|
36
|
+
"adapters": [
|
|
37
|
+
"./dist/adapters"
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
"bin": {
|
|
42
|
+
"swagger2ts": "./dist/bin.mjs"
|
|
43
|
+
},
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "unbuild",
|
|
46
|
+
"stub": "unbuild --stub",
|
|
47
|
+
"prepublishOnly": "pnpm run build",
|
|
48
|
+
"release": "pnpx git-ensure -a && pnpx bumpp --commit --tag --push",
|
|
49
|
+
"demo:dev": "pnpm -C examples/demo run dev",
|
|
50
|
+
"demo:build": "pnpm -C examples/demo run build",
|
|
51
|
+
"demo:preview": "pnpm -C examples/demo run preview",
|
|
52
|
+
"test": "jest",
|
|
53
|
+
"lint": "eslint --fix --ext .ts ./",
|
|
54
|
+
"version": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md",
|
|
55
|
+
"preinstall": "npx only-allow pnpm"
|
|
56
|
+
},
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"axios": "^1.4.0",
|
|
59
|
+
"cross-fetch": "^3.1.5",
|
|
60
|
+
"luch-request": "^3.1.0",
|
|
61
|
+
"openapi3-ts": "^2.0.2",
|
|
62
|
+
"swagger2openapi": "^7.0.8",
|
|
63
|
+
"unconfig": "^0.3.9"
|
|
64
|
+
},
|
|
65
|
+
"peerDependencies": {
|
|
66
|
+
"axios": "^1.4.0",
|
|
67
|
+
"luch-request": "^3.1.0",
|
|
68
|
+
"chalk": "^5.3.0",
|
|
69
|
+
"vite": "^2.0.0"
|
|
70
|
+
},
|
|
71
|
+
"devDependencies": {
|
|
72
|
+
"@antfu/eslint-config": "^0.6.6",
|
|
73
|
+
"@commitlint/cli": "^12.1.4",
|
|
74
|
+
"@commitlint/config-conventional": "^12.1.4",
|
|
75
|
+
"@dcloudio/types": "^3.3.3",
|
|
76
|
+
"@types/eslint": "^8.44.0",
|
|
77
|
+
"@types/jest": "^26.0.24",
|
|
78
|
+
"@types/node": "^14.18.12",
|
|
79
|
+
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
|
80
|
+
"@typescript-eslint/parser": "^5.14.0",
|
|
81
|
+
"conventional-changelog": "^3.1.25",
|
|
82
|
+
"cz-conventional-changelog": "^3.3.0",
|
|
83
|
+
"eslint": "^8.44.0",
|
|
84
|
+
"husky": "^8.0.3",
|
|
85
|
+
"jest": "^26.6.3",
|
|
86
|
+
"jest-esbuild": "^0.1.6",
|
|
87
|
+
"lint-staged": "^10.5.4",
|
|
88
|
+
"typescript": "^4.7.0",
|
|
89
|
+
"unbuild": "^2.0.0",
|
|
90
|
+
"vite": "^2.8.6"
|
|
91
|
+
},
|
|
92
|
+
"lint-staged": {
|
|
93
|
+
"*.{ts}": "eslint --fix --ext",
|
|
94
|
+
"*.{ts,md}": "prettier --write"
|
|
95
|
+
},
|
|
96
|
+
"husky": {
|
|
97
|
+
"hooks": {
|
|
98
|
+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
|
|
99
|
+
"pre-commit": "lint-staged"
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
"commitlint": {
|
|
103
|
+
"extends": [
|
|
104
|
+
"@commitlint/config-conventional"
|
|
105
|
+
]
|
|
106
|
+
},
|
|
107
|
+
"config": {
|
|
108
|
+
"commitizen": {
|
|
109
|
+
"path": "./node_modules/cz-conventional-changelog"
|
|
110
|
+
}
|
|
111
|
+
}
|
|
108
112
|
}
|