@1szx1/vite-plugin-swagger2ts 1.1.5 → 1.1.7

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.
@@ -12,12 +12,11 @@ declare function axiosAdapter<T>(httpInstance: AxiosInstance): {
12
12
  }) | undefined) => Promise<T[U][M]["response" & keyof T[U][M]]>;
13
13
  };
14
14
 
15
- declare function LuchAdapter<T extends Record<string, any>, C extends HttpRequestConfig['custom'] = HttpRequestConfig['custom']>(httpInstance: Request__default): {
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> & {
15
+ declare function LuchAdapter<T extends Record<string, any>, C extends HttpRequestConfig = HttpRequestConfig>(httpInstance: Request__default): {
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> & C & {
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
19
  path?: Get<T[U][M]["param" & keyof T[U][M]], "path"> | undefined;
20
- custom?: C | undefined;
21
20
  }) | undefined) => Promise<T[U][M]["response" & keyof T[U][M]]>;
22
21
  upload: <U_1 extends { [K in keyof T]: T[K] extends {
23
22
  post: any;
package/dist/index.cjs CHANGED
@@ -233,7 +233,7 @@ function swagger2TsPlugin(userOptions) {
233
233
  if (docs.swagger)
234
234
  openapiDocs = await convertObjPromise(openapiDocs);
235
235
  else
236
- return "";
236
+ throw new Error(JSON.stringify(docs));
237
237
  }
238
238
  const apistrings = generateDocs(openapiDocs, { docsName, baseUrl: docs.basePath ?? "", formatSchema });
239
239
  return apistrings;
@@ -242,21 +242,21 @@ function swagger2TsPlugin(userOptions) {
242
242
  return "";
243
243
  }
244
244
  }
245
- const sources = await fetchUrl(`${swaggerUrl}/swagger-resources`).catch((error) => {
246
- console.log(`%c[vite-plugin-swagger2ts]: doc error`, "color: #ff0000;", error);
247
- return [];
248
- });
249
- const code = (await Promise.all(sources.map(genCode))).reduce((a, b, index, list) => {
250
- let res = a + b;
251
- if (index === list.length - 1) {
252
- const suffix = `export type ${getPathsName("_Intersection")} = ${sources.map(({ name }) => getPathsName(name)).join("&")}
245
+ const sources = await fetchUrl(`${swaggerUrl}/swagger-resources`).catch((error) => error);
246
+ if (!Array.isArray(sources))
247
+ return console.log(`%c[vite-plugin-swagger2ts]: doc error`, "color: #ff0000;", JSON.stringify(sources));
248
+ const interfaceList = await Promise.all(sources.map(genCode));
249
+ const code = interfaceList.reduce((a, b) => a + b, "");
250
+ const suffix = interfaceList.reduce((a, b, index) => {
251
+ if (b) {
252
+ a += !a ? `export type ${getPathsName("_Intersection")} = ` : `&
253
253
  `;
254
- res += suffix;
254
+ a += `${getPathsName(sources[index].name)}`;
255
255
  }
256
- return res;
256
+ return a;
257
257
  }, "");
258
258
  const outputFile = path.resolve(process.cwd(), output);
259
- fs.writeFileSync(outputFile, code);
259
+ fs.writeFileSync(outputFile, code + suffix);
260
260
  }
261
261
  loadSwaggerSource();
262
262
  return {
package/dist/index.mjs CHANGED
@@ -225,7 +225,7 @@ function swagger2TsPlugin(userOptions) {
225
225
  if (docs.swagger)
226
226
  openapiDocs = await convertObjPromise(openapiDocs);
227
227
  else
228
- return "";
228
+ throw new Error(JSON.stringify(docs));
229
229
  }
230
230
  const apistrings = generateDocs(openapiDocs, { docsName, baseUrl: docs.basePath ?? "", formatSchema });
231
231
  return apistrings;
@@ -234,21 +234,21 @@ function swagger2TsPlugin(userOptions) {
234
234
  return "";
235
235
  }
236
236
  }
237
- const sources = await fetchUrl(`${swaggerUrl}/swagger-resources`).catch((error) => {
238
- console.log(`%c[vite-plugin-swagger2ts]: doc error`, "color: #ff0000;", error);
239
- return [];
240
- });
241
- const code = (await Promise.all(sources.map(genCode))).reduce((a, b, index, list) => {
242
- let res = a + b;
243
- if (index === list.length - 1) {
244
- const suffix = `export type ${getPathsName("_Intersection")} = ${sources.map(({ name }) => getPathsName(name)).join("&")}
237
+ const sources = await fetchUrl(`${swaggerUrl}/swagger-resources`).catch((error) => error);
238
+ if (!Array.isArray(sources))
239
+ return console.log(`%c[vite-plugin-swagger2ts]: doc error`, "color: #ff0000;", JSON.stringify(sources));
240
+ const interfaceList = await Promise.all(sources.map(genCode));
241
+ const code = interfaceList.reduce((a, b) => a + b, "");
242
+ const suffix = interfaceList.reduce((a, b, index) => {
243
+ if (b) {
244
+ a += !a ? `export type ${getPathsName("_Intersection")} = ` : `&
245
245
  `;
246
- res += suffix;
246
+ a += `${getPathsName(sources[index].name)}`;
247
247
  }
248
- return res;
248
+ return a;
249
249
  }, "");
250
250
  const outputFile = resolve(process.cwd(), output);
251
- writeFileSync(outputFile, code);
251
+ writeFileSync(outputFile, code + suffix);
252
252
  }
253
253
  loadSwaggerSource();
254
254
  return {
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.1.5",
4
+ "version": "1.1.7",
5
5
  "license": "MIT",
6
6
  "author": "1SZX1 <2414126198@qq.com>",
7
7
  "repository": {