@1szx1/vite-plugin-swagger2ts 1.3.16 → 1.3.18
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 +14 -11
- package/dist/index.d.cts +4 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.mjs +14 -11
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -247,7 +247,7 @@ function getApiName(json) {
|
|
|
247
247
|
}
|
|
248
248
|
|
|
249
249
|
async function loadSwaggerSource(options) {
|
|
250
|
-
const { swaggerUrl, jsonUrl, jsonPath, output, formatDocs, formatSchema } = options;
|
|
250
|
+
const { swaggerUrl, jsonUrl, jsonPath, jsonLoader, output, formatDocs, formatSchema } = options;
|
|
251
251
|
async function genInterface(docs, docsName) {
|
|
252
252
|
docs = formatDocs ? formatDocs(docs) : docs;
|
|
253
253
|
if (!("openapi" in docs)) {
|
|
@@ -274,6 +274,15 @@ async function loadSwaggerSource(options) {
|
|
|
274
274
|
async function getSources() {
|
|
275
275
|
const sources2 = [];
|
|
276
276
|
const interfaces2 = [];
|
|
277
|
+
async function loadSwaggerJson(swaggerJson) {
|
|
278
|
+
if (swaggerJson.info) {
|
|
279
|
+
const name = getApiName(swaggerJson);
|
|
280
|
+
interfaces2.push(await genInterface(swaggerJson, name));
|
|
281
|
+
sources2.push({ name });
|
|
282
|
+
} else {
|
|
283
|
+
console.log(chalk__default.yellow(`[${pluginName}]: jsonUrl error;`) + JSON.stringify(swaggerJson));
|
|
284
|
+
}
|
|
285
|
+
}
|
|
277
286
|
if (typeof swaggerUrl === "string") {
|
|
278
287
|
const resources = await fetchUrl(`${swaggerUrl}/swagger-resources;`).catch((error) => error);
|
|
279
288
|
if (Array.isArray(resources)) {
|
|
@@ -285,20 +294,14 @@ async function loadSwaggerSource(options) {
|
|
|
285
294
|
}
|
|
286
295
|
if (typeof jsonUrl === "string") {
|
|
287
296
|
const swaggerJson = await fetchUrl(jsonUrl);
|
|
288
|
-
|
|
289
|
-
const name = getApiName(swaggerJson);
|
|
290
|
-
interfaces2.push(await genInterface(swaggerJson, name));
|
|
291
|
-
sources2.push({ name });
|
|
292
|
-
} else {
|
|
293
|
-
console.log(chalk__default.yellow(`[${pluginName}]: jsonUrl error;`) + JSON.stringify(swaggerJson));
|
|
294
|
-
}
|
|
297
|
+
await loadSwaggerJson(swaggerJson);
|
|
295
298
|
}
|
|
299
|
+
if (jsonLoader)
|
|
300
|
+
await loadSwaggerJson(await jsonLoader());
|
|
296
301
|
if (typeof jsonPath === "string") {
|
|
297
302
|
const _jsonPath = path.resolve(process.cwd(), jsonPath);
|
|
298
303
|
const swaggerJson = JSON.parse(fs.readFileSync(_jsonPath, { encoding: "utf-8" }));
|
|
299
|
-
|
|
300
|
-
interfaces2.push(await genInterface(swaggerJson, name));
|
|
301
|
-
sources2.push({ name });
|
|
304
|
+
await loadSwaggerJson(swaggerJson);
|
|
302
305
|
}
|
|
303
306
|
return { sources: sources2, interfaces: interfaces2 };
|
|
304
307
|
}
|
package/dist/index.d.cts
CHANGED
|
@@ -15,6 +15,10 @@ interface Options {
|
|
|
15
15
|
* openApi 本地json
|
|
16
16
|
*/
|
|
17
17
|
jsonPath?: string;
|
|
18
|
+
/**
|
|
19
|
+
* 加载json的方法
|
|
20
|
+
*/
|
|
21
|
+
jsonLoader?: () => OpenAPIObject | Promise<OpenAPIObject>;
|
|
18
22
|
output?: string;
|
|
19
23
|
formatDocs?: (docs: SwaggerDoc | OpenAPIObject) => typeof docs;
|
|
20
24
|
formatSchema?: FormatSchema;
|
package/dist/index.d.mts
CHANGED
|
@@ -15,6 +15,10 @@ interface Options {
|
|
|
15
15
|
* openApi 本地json
|
|
16
16
|
*/
|
|
17
17
|
jsonPath?: string;
|
|
18
|
+
/**
|
|
19
|
+
* 加载json的方法
|
|
20
|
+
*/
|
|
21
|
+
jsonLoader?: () => OpenAPIObject | Promise<OpenAPIObject>;
|
|
18
22
|
output?: string;
|
|
19
23
|
formatDocs?: (docs: SwaggerDoc | OpenAPIObject) => typeof docs;
|
|
20
24
|
formatSchema?: FormatSchema;
|
package/dist/index.d.ts
CHANGED
|
@@ -15,6 +15,10 @@ interface Options {
|
|
|
15
15
|
* openApi 本地json
|
|
16
16
|
*/
|
|
17
17
|
jsonPath?: string;
|
|
18
|
+
/**
|
|
19
|
+
* 加载json的方法
|
|
20
|
+
*/
|
|
21
|
+
jsonLoader?: () => OpenAPIObject | Promise<OpenAPIObject>;
|
|
18
22
|
output?: string;
|
|
19
23
|
formatDocs?: (docs: SwaggerDoc | OpenAPIObject) => typeof docs;
|
|
20
24
|
formatSchema?: FormatSchema;
|
package/dist/index.mjs
CHANGED
|
@@ -238,7 +238,7 @@ function getApiName(json) {
|
|
|
238
238
|
}
|
|
239
239
|
|
|
240
240
|
async function loadSwaggerSource(options) {
|
|
241
|
-
const { swaggerUrl, jsonUrl, jsonPath, output, formatDocs, formatSchema } = options;
|
|
241
|
+
const { swaggerUrl, jsonUrl, jsonPath, jsonLoader, output, formatDocs, formatSchema } = options;
|
|
242
242
|
async function genInterface(docs, docsName) {
|
|
243
243
|
docs = formatDocs ? formatDocs(docs) : docs;
|
|
244
244
|
if (!("openapi" in docs)) {
|
|
@@ -265,6 +265,15 @@ async function loadSwaggerSource(options) {
|
|
|
265
265
|
async function getSources() {
|
|
266
266
|
const sources2 = [];
|
|
267
267
|
const interfaces2 = [];
|
|
268
|
+
async function loadSwaggerJson(swaggerJson) {
|
|
269
|
+
if (swaggerJson.info) {
|
|
270
|
+
const name = getApiName(swaggerJson);
|
|
271
|
+
interfaces2.push(await genInterface(swaggerJson, name));
|
|
272
|
+
sources2.push({ name });
|
|
273
|
+
} else {
|
|
274
|
+
console.log(chalk.yellow(`[${pluginName}]: jsonUrl error;`) + JSON.stringify(swaggerJson));
|
|
275
|
+
}
|
|
276
|
+
}
|
|
268
277
|
if (typeof swaggerUrl === "string") {
|
|
269
278
|
const resources = await fetchUrl(`${swaggerUrl}/swagger-resources;`).catch((error) => error);
|
|
270
279
|
if (Array.isArray(resources)) {
|
|
@@ -276,20 +285,14 @@ async function loadSwaggerSource(options) {
|
|
|
276
285
|
}
|
|
277
286
|
if (typeof jsonUrl === "string") {
|
|
278
287
|
const swaggerJson = await fetchUrl(jsonUrl);
|
|
279
|
-
|
|
280
|
-
const name = getApiName(swaggerJson);
|
|
281
|
-
interfaces2.push(await genInterface(swaggerJson, name));
|
|
282
|
-
sources2.push({ name });
|
|
283
|
-
} else {
|
|
284
|
-
console.log(chalk.yellow(`[${pluginName}]: jsonUrl error;`) + JSON.stringify(swaggerJson));
|
|
285
|
-
}
|
|
288
|
+
await loadSwaggerJson(swaggerJson);
|
|
286
289
|
}
|
|
290
|
+
if (jsonLoader)
|
|
291
|
+
await loadSwaggerJson(await jsonLoader());
|
|
287
292
|
if (typeof jsonPath === "string") {
|
|
288
293
|
const _jsonPath = resolve(process.cwd(), jsonPath);
|
|
289
294
|
const swaggerJson = JSON.parse(readFileSync(_jsonPath, { encoding: "utf-8" }));
|
|
290
|
-
|
|
291
|
-
interfaces2.push(await genInterface(swaggerJson, name));
|
|
292
|
-
sources2.push({ name });
|
|
295
|
+
await loadSwaggerJson(swaggerJson);
|
|
293
296
|
}
|
|
294
297
|
return { sources: sources2, interfaces: interfaces2 };
|
|
295
298
|
}
|
package/package.json
CHANGED