@1szx1/vite-plugin-swagger2ts 1.1.1 → 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/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,17 +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
246
  const sources = await fetchUrl(`${swaggerUrl}/swagger-resources`).catch((error) => {
243
- console.log("vite-plugin-swagger2ts doc error", error);
247
+ console.log(`%c[vite-plugin-swagger2ts]: doc error`, "color: #ff0000;", error);
244
248
  return [];
245
249
  });
246
- const code = (await Promise.all(sources.map(genCode))).reduce((a, b) => a + b, "");
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
+ }, "");
247
259
  const outputFile = path.resolve(process.cwd(), output);
248
260
  fs.writeFileSync(outputFile, code);
249
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,17 +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
238
  const sources = await fetchUrl(`${swaggerUrl}/swagger-resources`).catch((error) => {
235
- console.log("vite-plugin-swagger2ts doc error", error);
239
+ console.log(`%c[vite-plugin-swagger2ts]: doc error`, "color: #ff0000;", error);
236
240
  return [];
237
241
  });
238
- const code = (await Promise.all(sources.map(genCode))).reduce((a, b) => a + b, "");
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
+ }, "");
239
251
  const outputFile = resolve(process.cwd(), output);
240
252
  writeFileSync(outputFile, code);
241
253
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@1szx1/vite-plugin-swagger2ts",
3
- "description": "fork for https://github.com/1SZX1/vite-plugin-swagger2ts",
4
- "version": "1.1.1",
3
+ "description": "forked from https://github.com/morelearn1990/vite-plugin-swagger2ts",
4
+ "version": "1.1.2",
5
5
  "license": "MIT",
6
6
  "author": "1SZX1 <2414126198@qq.com>",
7
7
  "repository": {
@@ -30,9 +30,6 @@
30
30
  "types": "dist/index.d.ts",
31
31
  "typesVersions": {
32
32
  "*": {
33
- "/": [
34
- "./dist"
35
- ],
36
33
  "adapters": [
37
34
  "./dist/adapters"
38
35
  ]
@@ -55,30 +52,31 @@
55
52
  "preinstall": "npx only-allow pnpm"
56
53
  },
57
54
  "dependencies": {
55
+ "axios": "^1.4.0",
58
56
  "cross-fetch": "^3.1.5",
57
+ "luch-request": "^3.1.0",
59
58
  "openapi3-ts": "^2.0.2",
60
59
  "swagger2openapi": "^7.0.8",
61
- "luch-request": "^3.1.0",
62
- "axios": "^1.4.0",
63
60
  "unconfig": "^0.3.9"
64
61
  },
65
62
  "peerDependencies": {
66
- "vite": "^2.0.0",
63
+ "axios": "^1.4.0",
67
64
  "luch-request": "^3.1.0",
68
- "axios": "^1.4.0"
65
+ "vite": "^2.0.0"
69
66
  },
70
67
  "devDependencies": {
71
68
  "@antfu/eslint-config": "^0.6.6",
72
69
  "@commitlint/cli": "^12.1.4",
73
70
  "@commitlint/config-conventional": "^12.1.4",
74
71
  "@dcloudio/types": "^3.3.3",
72
+ "@types/eslint": "^8.44.0",
75
73
  "@types/jest": "^26.0.24",
76
74
  "@types/node": "^14.18.12",
77
75
  "@typescript-eslint/eslint-plugin": "^4.33.0",
78
76
  "@typescript-eslint/parser": "^5.14.0",
79
77
  "conventional-changelog": "^3.1.25",
80
78
  "cz-conventional-changelog": "^3.3.0",
81
- "eslint": "^7.32.0",
79
+ "eslint": "^8.44.0",
82
80
  "husky": "^8.0.3",
83
81
  "jest": "^26.6.3",
84
82
  "jest-esbuild": "^0.1.6",