@1szx1/vite-plugin-swagger2ts 1.1.6 → 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.
- package/dist/index.cjs +12 -12
- package/dist/index.mjs +12 -12
- package/package.json +1 -1
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
|
-
|
|
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
|
-
|
|
247
|
-
return [];
|
|
248
|
-
|
|
249
|
-
const code =
|
|
250
|
-
|
|
251
|
-
if (
|
|
252
|
-
|
|
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
|
-
|
|
254
|
+
a += `${getPathsName(sources[index].name)}`;
|
|
255
255
|
}
|
|
256
|
-
return
|
|
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
|
-
|
|
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
|
-
|
|
239
|
-
return [];
|
|
240
|
-
|
|
241
|
-
const code =
|
|
242
|
-
|
|
243
|
-
if (
|
|
244
|
-
|
|
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
|
-
|
|
246
|
+
a += `${getPathsName(sources[index].name)}`;
|
|
247
247
|
}
|
|
248
|
-
return
|
|
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