@1szx1/vite-plugin-swagger2ts 1.1.0 → 1.1.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/adapters.cjs CHANGED
@@ -22,6 +22,8 @@ function axiosAdapter(httpInstance) {
22
22
 
23
23
  function LuchAdapter(httpInstance) {
24
24
  async function request(url, method, param, config) {
25
+ if (config?.path)
26
+ url = mergeUrlParam(url, config.path);
25
27
  const response = await httpInstance.middleware({
26
28
  url,
27
29
  method: method.toUpperCase(),
@@ -16,6 +16,7 @@ declare function LuchAdapter<T extends Record<string, any>>(httpInstance: Reques
16
16
  request: <U extends keyof T, M extends string & keyof T[U]>(url: U & string, method: M, param?: Get<T[U][M]["param" & keyof T[U][M]], M extends "get" ? "query" : "body"> | undefined, config?: (HttpRequestConfig<Request.HttpTask> & {
17
17
  data?: Get<T[U][M]["param" & keyof T[U][M]], "body"> | undefined;
18
18
  params?: Get<T[U][M]["param" & keyof T[U][M]], "query"> | undefined;
19
+ path?: Get<T[U][M]["param" & keyof T[U][M]], "path"> | undefined;
19
20
  }) | undefined) => Promise<T[U][M]["response" & keyof T[U][M]]>;
20
21
  upload: <U_1 extends { [K in keyof T]: T[K] extends {
21
22
  post: any;
package/dist/adapters.mjs CHANGED
@@ -20,6 +20,8 @@ function axiosAdapter(httpInstance) {
20
20
 
21
21
  function LuchAdapter(httpInstance) {
22
22
  async function request(url, method, param, config) {
23
+ if (config?.path)
24
+ url = mergeUrlParam(url, config.path);
23
25
  const response = await httpInstance.middleware({
24
26
  url,
25
27
  method: method.toUpperCase(),
package/dist/index.cjs CHANGED
@@ -122,7 +122,7 @@ param:{${paramString}}` : ""}${responseString}}` });
122
122
  return generatorSchemaType(getRefName(`#/components/schemas/${name}`, docsName), schema, { isRoot: true, isExport: true, docsName });
123
123
  }).join("") : "";
124
124
  const apiString = `${typeString}
125
- export interface Paths${getRefName(docsName)}{${pathsTypeString}}
125
+ export interface ${getPathsName(docsName)}}{${pathsTypeString}}
126
126
  `;
127
127
  return apiString.replaceAll(/\n\n/g, "\n").replaceAll(/\n\n/g, "\n");
128
128
  }
@@ -208,6 +208,9 @@ ${title ? ` * @title ${title}
208
208
  ` : `${key}${isRequired === false ? "?" : ""}: ${result};
209
209
  `}`;
210
210
  }
211
+ function getPathsName(docsName) {
212
+ return `Paths${getRefName(docsName)}`;
213
+ }
211
214
 
212
215
  function convertObjPromise(docs) {
213
216
  return new Promise((resolve2, reject) => {
@@ -233,14 +236,26 @@ function swagger2TsPlugin(userOptions) {
233
236
  return "";
234
237
  }
235
238
  const apistrings = generateDocs(openapiDocs, { docsName, baseUrl: docs.basePath ?? "", formatSchema });
239
+ console.log(`%c[vite-plugin-swagger2ts]: ${docsName} succeeded`, "color: #00ff00;");
236
240
  return apistrings;
237
241
  } catch (error) {
238
- console.log("vite-plugin-swagger2ts convert error", docsName, error);
242
+ console.log(`%c[vite-plugin-swagger2ts]: ${docsName} error`, "color: #ff0000;", error);
239
243
  return "";
240
244
  }
241
245
  }
242
- const sources = await fetchUrl(`${swaggerUrl}/swagger-resources`);
243
- const code = (await Promise.all(sources.map(genCode))).reduce((a, b) => a + b, "");
246
+ const sources = await fetchUrl(`${swaggerUrl}/swagger-resources`).catch((error) => {
247
+ console.log(`%c[vite-plugin-swagger2ts]: doc error`, "color: #ff0000;", error);
248
+ return [];
249
+ });
250
+ const code = (await Promise.all(sources.map(genCode))).reduce((a, b, index, list) => {
251
+ let res = a + b;
252
+ if (index === list.length - 1) {
253
+ const suffix = `export type ${getPathsName("Intersection")} = ${sources.map(({ name }) => getPathsName(name)).join("&")}
254
+ `;
255
+ res += suffix;
256
+ }
257
+ return res;
258
+ }, "");
244
259
  const outputFile = path.resolve(process.cwd(), output);
245
260
  fs.writeFileSync(outputFile, code);
246
261
  }
package/dist/index.mjs CHANGED
@@ -114,7 +114,7 @@ param:{${paramString}}` : ""}${responseString}}` });
114
114
  return generatorSchemaType(getRefName(`#/components/schemas/${name}`, docsName), schema, { isRoot: true, isExport: true, docsName });
115
115
  }).join("") : "";
116
116
  const apiString = `${typeString}
117
- export interface Paths${getRefName(docsName)}{${pathsTypeString}}
117
+ export interface ${getPathsName(docsName)}}{${pathsTypeString}}
118
118
  `;
119
119
  return apiString.replaceAll(/\n\n/g, "\n").replaceAll(/\n\n/g, "\n");
120
120
  }
@@ -200,6 +200,9 @@ ${title ? ` * @title ${title}
200
200
  ` : `${key}${isRequired === false ? "?" : ""}: ${result};
201
201
  `}`;
202
202
  }
203
+ function getPathsName(docsName) {
204
+ return `Paths${getRefName(docsName)}`;
205
+ }
203
206
 
204
207
  function convertObjPromise(docs) {
205
208
  return new Promise((resolve2, reject) => {
@@ -225,14 +228,26 @@ function swagger2TsPlugin(userOptions) {
225
228
  return "";
226
229
  }
227
230
  const apistrings = generateDocs(openapiDocs, { docsName, baseUrl: docs.basePath ?? "", formatSchema });
231
+ console.log(`%c[vite-plugin-swagger2ts]: ${docsName} succeeded`, "color: #00ff00;");
228
232
  return apistrings;
229
233
  } catch (error) {
230
- console.log("vite-plugin-swagger2ts convert error", docsName, error);
234
+ console.log(`%c[vite-plugin-swagger2ts]: ${docsName} error`, "color: #ff0000;", error);
231
235
  return "";
232
236
  }
233
237
  }
234
- const sources = await fetchUrl(`${swaggerUrl}/swagger-resources`);
235
- const code = (await Promise.all(sources.map(genCode))).reduce((a, b) => a + b, "");
238
+ const sources = await fetchUrl(`${swaggerUrl}/swagger-resources`).catch((error) => {
239
+ console.log(`%c[vite-plugin-swagger2ts]: doc error`, "color: #ff0000;", error);
240
+ return [];
241
+ });
242
+ const code = (await Promise.all(sources.map(genCode))).reduce((a, b, index, list) => {
243
+ let res = a + b;
244
+ if (index === list.length - 1) {
245
+ const suffix = `export type ${getPathsName("Intersection")} = ${sources.map(({ name }) => getPathsName(name)).join("&")}
246
+ `;
247
+ res += suffix;
248
+ }
249
+ return res;
250
+ }, "");
236
251
  const outputFile = resolve(process.cwd(), output);
237
252
  writeFileSync(outputFile, code);
238
253
  }
package/package.json CHANGED
@@ -1,110 +1,108 @@
1
- {
2
- "name": "@1szx1/vite-plugin-swagger2ts",
3
- "description": "fork for https://github.com/1SZX1/vite-plugin-swagger2ts",
4
- "version": "1.1.0",
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
- "files": [
14
- "dist"
15
- ],
16
- "exports": {
17
- ".": {
18
- "require": "./dist/index.cjs",
19
- "import": "./dist/index.mjs",
20
- "types": "./dist/index.d.ts"
21
- },
22
- "./adapters": {
23
- "require": "./dist/adapters.cjs",
24
- "import": "./dist/adapters.mjs",
25
- "types": "./dist/adapters.d.ts"
26
- }
27
- },
28
- "main": "dist/index.cjs",
29
- "module": "dist/index.mjs",
30
- "types": "dist/index.d.ts",
31
- "typesVersions": {
32
- "*": {
33
- "/": [
34
- "./dist"
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
- "cross-fetch": "^3.1.5",
59
- "openapi3-ts": "^2.0.2",
60
- "swagger2openapi": "^7.0.8",
61
- "luch-request": "^3.1.0",
62
- "axios": "^1.4.0",
63
- "unconfig": "^0.3.9"
64
- },
65
- "peerDependencies": {
66
- "vite": "^2.0.0",
67
- "luch-request": "^3.1.0",
68
- "axios": "^1.4.0"
69
- },
70
- "devDependencies": {
71
- "@antfu/eslint-config": "^0.6.6",
72
- "@commitlint/cli": "^12.1.4",
73
- "@commitlint/config-conventional": "^12.1.4",
74
- "@dcloudio/types": "^3.3.3",
75
- "@types/jest": "^26.0.24",
76
- "@types/node": "^14.18.12",
77
- "@typescript-eslint/eslint-plugin": "^4.33.0",
78
- "@typescript-eslint/parser": "^5.14.0",
79
- "conventional-changelog": "^3.1.25",
80
- "cz-conventional-changelog": "^3.3.0",
81
- "eslint": "^7.32.0",
82
- "husky": "^8.0.3",
83
- "jest": "^26.6.3",
84
- "jest-esbuild": "^0.1.6",
85
- "lint-staged": "^10.5.4",
86
- "typescript": "^4.7.0",
87
- "unbuild": "^1.2.1",
88
- "vite": "^2.8.6"
89
- },
90
- "lint-staged": {
91
- "*.{ts}": "eslint --fix --ext",
92
- "*.{ts,md}": "prettier --write"
93
- },
94
- "husky": {
95
- "hooks": {
96
- "commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
97
- "pre-commit": "lint-staged"
98
- }
99
- },
100
- "commitlint": {
101
- "extends": [
102
- "@commitlint/config-conventional"
103
- ]
104
- },
105
- "config": {
106
- "commitizen": {
107
- "path": "./node_modules/cz-conventional-changelog"
108
- }
109
- }
1
+ {
2
+ "name": "@1szx1/vite-plugin-swagger2ts",
3
+ "description": "forked from https://github.com/morelearn1990/vite-plugin-swagger2ts",
4
+ "version": "1.1.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
+ "files": [
14
+ "dist"
15
+ ],
16
+ "exports": {
17
+ ".": {
18
+ "require": "./dist/index.cjs",
19
+ "import": "./dist/index.mjs",
20
+ "types": "./dist/index.d.ts"
21
+ },
22
+ "./adapters": {
23
+ "require": "./dist/adapters.cjs",
24
+ "import": "./dist/adapters.mjs",
25
+ "types": "./dist/adapters.d.ts"
26
+ }
27
+ },
28
+ "main": "dist/index.cjs",
29
+ "module": "dist/index.mjs",
30
+ "types": "dist/index.d.ts",
31
+ "typesVersions": {
32
+ "*": {
33
+ "adapters": [
34
+ "./dist/adapters"
35
+ ]
36
+ }
37
+ },
38
+ "bin": {
39
+ "swagger2ts": "./dist/bin.mjs"
40
+ },
41
+ "scripts": {
42
+ "build": "unbuild",
43
+ "stub": "unbuild --stub",
44
+ "prepublishOnly": "pnpm run build",
45
+ "release": "pnpx git-ensure -a && pnpx bumpp --commit --tag --push",
46
+ "demo:dev": "pnpm -C examples/demo run dev",
47
+ "demo:build": "pnpm -C examples/demo run build",
48
+ "demo:preview": "pnpm -C examples/demo run preview",
49
+ "test": "jest",
50
+ "lint": "eslint --fix --ext .ts ./",
51
+ "version": "conventional-changelog -p angular -i CHANGELOG.md -s -r 0 && git add CHANGELOG.md",
52
+ "preinstall": "npx only-allow pnpm"
53
+ },
54
+ "dependencies": {
55
+ "axios": "^1.4.0",
56
+ "cross-fetch": "^3.1.5",
57
+ "luch-request": "^3.1.0",
58
+ "openapi3-ts": "^2.0.2",
59
+ "swagger2openapi": "^7.0.8",
60
+ "unconfig": "^0.3.9"
61
+ },
62
+ "peerDependencies": {
63
+ "axios": "^1.4.0",
64
+ "luch-request": "^3.1.0",
65
+ "vite": "^2.0.0"
66
+ },
67
+ "devDependencies": {
68
+ "@antfu/eslint-config": "^0.6.6",
69
+ "@commitlint/cli": "^12.1.4",
70
+ "@commitlint/config-conventional": "^12.1.4",
71
+ "@dcloudio/types": "^3.3.3",
72
+ "@types/eslint": "^8.44.0",
73
+ "@types/jest": "^26.0.24",
74
+ "@types/node": "^14.18.12",
75
+ "@typescript-eslint/eslint-plugin": "^4.33.0",
76
+ "@typescript-eslint/parser": "^5.14.0",
77
+ "conventional-changelog": "^3.1.25",
78
+ "cz-conventional-changelog": "^3.3.0",
79
+ "eslint": "^8.44.0",
80
+ "husky": "^8.0.3",
81
+ "jest": "^26.6.3",
82
+ "jest-esbuild": "^0.1.6",
83
+ "lint-staged": "^10.5.4",
84
+ "typescript": "^4.7.0",
85
+ "unbuild": "^1.2.1",
86
+ "vite": "^2.8.6"
87
+ },
88
+ "lint-staged": {
89
+ "*.{ts}": "eslint --fix --ext",
90
+ "*.{ts,md}": "prettier --write"
91
+ },
92
+ "husky": {
93
+ "hooks": {
94
+ "commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
95
+ "pre-commit": "lint-staged"
96
+ }
97
+ },
98
+ "commitlint": {
99
+ "extends": [
100
+ "@commitlint/config-conventional"
101
+ ]
102
+ },
103
+ "config": {
104
+ "commitizen": {
105
+ "path": "./node_modules/cz-conventional-changelog"
106
+ }
107
+ }
110
108
  }