@1szx1/vite-plugin-swagger2ts 1.3.8 → 1.3.10
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 +7 -11
- package/dist/index.mjs +7 -11
- package/package.json +2 -1
package/dist/index.cjs
CHANGED
|
@@ -221,22 +221,13 @@ function getApiName(json) {
|
|
|
221
221
|
return json.info.title.replace(" ", "_");
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
-
function convertObjPromise(docs) {
|
|
225
|
-
return new Promise((resolve2, reject) => {
|
|
226
|
-
swagger2openapi.convertObj(docs, { patch: true }, function(err, option) {
|
|
227
|
-
if (err || !option.openapi)
|
|
228
|
-
return reject(err);
|
|
229
|
-
resolve2(option.openapi);
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
224
|
async function loadSwaggerSource(options) {
|
|
234
225
|
const { swaggerUrl, jsonUrl, jsonPath, output, formatDocs, formatSchema } = options;
|
|
235
226
|
async function genInterface(docs, docsName) {
|
|
236
227
|
docs = formatDocs ? formatDocs(docs) : docs;
|
|
237
228
|
if (!("openapi" in docs)) {
|
|
238
229
|
if (docs.swagger)
|
|
239
|
-
docs = await
|
|
230
|
+
docs = (await swagger2openapi.convertObj(docs, { patch: true })).openapi;
|
|
240
231
|
else
|
|
241
232
|
throw new Error(JSON.stringify(docs));
|
|
242
233
|
}
|
|
@@ -281,6 +272,11 @@ async function loadSwaggerSource(options) {
|
|
|
281
272
|
const { sources, interfaces } = await getSources() || {};
|
|
282
273
|
if (!interfaces?.length)
|
|
283
274
|
return;
|
|
275
|
+
const prefix = `/* eslint-disable */
|
|
276
|
+
/* prettier-ignore */
|
|
277
|
+
// @ts-nocheck
|
|
278
|
+
// noinspection JSUnusedGlobalSymbols
|
|
279
|
+
// Generated by vite-plugin-swagger2ts`;
|
|
284
280
|
const code = interfaces.reduce((a, b) => a + b, "");
|
|
285
281
|
const suffix = sources ? interfaces.reduce((a, b, index) => {
|
|
286
282
|
if (b) {
|
|
@@ -290,7 +286,7 @@ async function loadSwaggerSource(options) {
|
|
|
290
286
|
return a;
|
|
291
287
|
}, "") : "";
|
|
292
288
|
const outputFile = path.resolve(process.cwd(), output);
|
|
293
|
-
fs.writeFileSync(outputFile, code + suffix);
|
|
289
|
+
fs.writeFileSync(outputFile, prefix + code + suffix);
|
|
294
290
|
}
|
|
295
291
|
function swagger2TsPlugin(userOptions) {
|
|
296
292
|
resolveOptions(userOptions).then((options) => {
|
package/dist/index.mjs
CHANGED
|
@@ -212,22 +212,13 @@ function getApiName(json) {
|
|
|
212
212
|
return json.info.title.replace(" ", "_");
|
|
213
213
|
}
|
|
214
214
|
|
|
215
|
-
function convertObjPromise(docs) {
|
|
216
|
-
return new Promise((resolve2, reject) => {
|
|
217
|
-
convertObj(docs, { patch: true }, function(err, option) {
|
|
218
|
-
if (err || !option.openapi)
|
|
219
|
-
return reject(err);
|
|
220
|
-
resolve2(option.openapi);
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
215
|
async function loadSwaggerSource(options) {
|
|
225
216
|
const { swaggerUrl, jsonUrl, jsonPath, output, formatDocs, formatSchema } = options;
|
|
226
217
|
async function genInterface(docs, docsName) {
|
|
227
218
|
docs = formatDocs ? formatDocs(docs) : docs;
|
|
228
219
|
if (!("openapi" in docs)) {
|
|
229
220
|
if (docs.swagger)
|
|
230
|
-
docs = await
|
|
221
|
+
docs = (await convertObj(docs, { patch: true })).openapi;
|
|
231
222
|
else
|
|
232
223
|
throw new Error(JSON.stringify(docs));
|
|
233
224
|
}
|
|
@@ -272,6 +263,11 @@ async function loadSwaggerSource(options) {
|
|
|
272
263
|
const { sources, interfaces } = await getSources() || {};
|
|
273
264
|
if (!interfaces?.length)
|
|
274
265
|
return;
|
|
266
|
+
const prefix = `/* eslint-disable */
|
|
267
|
+
/* prettier-ignore */
|
|
268
|
+
// @ts-nocheck
|
|
269
|
+
// noinspection JSUnusedGlobalSymbols
|
|
270
|
+
// Generated by vite-plugin-swagger2ts`;
|
|
275
271
|
const code = interfaces.reduce((a, b) => a + b, "");
|
|
276
272
|
const suffix = sources ? interfaces.reduce((a, b, index) => {
|
|
277
273
|
if (b) {
|
|
@@ -281,7 +277,7 @@ async function loadSwaggerSource(options) {
|
|
|
281
277
|
return a;
|
|
282
278
|
}, "") : "";
|
|
283
279
|
const outputFile = resolve(process.cwd(), output);
|
|
284
|
-
writeFileSync(outputFile, code + suffix);
|
|
280
|
+
writeFileSync(outputFile, prefix + code + suffix);
|
|
285
281
|
}
|
|
286
282
|
function swagger2TsPlugin(userOptions) {
|
|
287
283
|
resolveOptions(userOptions).then((options) => {
|
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.3.
|
|
4
|
+
"version": "1.3.10",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "1SZX1 <2414126198@qq.com>",
|
|
7
7
|
"repository": {
|
|
@@ -76,6 +76,7 @@
|
|
|
76
76
|
"@types/eslint": "^8.44.0",
|
|
77
77
|
"@types/jest": "^26.0.24",
|
|
78
78
|
"@types/node": "^14.18.12",
|
|
79
|
+
"@types/swagger2openapi": "^7.0.0",
|
|
79
80
|
"@typescript-eslint/eslint-plugin": "^4.33.0",
|
|
80
81
|
"@typescript-eslint/parser": "^5.14.0",
|
|
81
82
|
"conventional-changelog": "^3.1.25",
|