@1szx1/vite-plugin-swagger2ts 1.3.7 → 1.3.9

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
@@ -152,7 +152,7 @@ ${key}${isRequired === false ? "?" : ""}: `}any${key && `;`}`;
152
152
  result = `${Enum.map((t) => `"${t}"`).join(" | ")}`;
153
153
  } else if (items) {
154
154
  result = `${generatorSchemaType("", items, { docsName })}[]`;
155
- } else if (properties) {
155
+ } else if (properties && !isTypeAny(properties)) {
156
156
  result += `{${Object.entries(properties).map(([pName, _schema]) => generatorSchemaType(pName, _schema, { isRequired: !required || required.includes(pName) ? true : false, docsName })).join("")}
157
157
  }`;
158
158
  } else if (oneOf) {
@@ -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 convertObjPromise(docs);
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,12 @@ 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
280
+ `;
284
281
  const code = interfaces.reduce((a, b) => a + b, "");
285
282
  const suffix = sources ? interfaces.reduce((a, b, index) => {
286
283
  if (b) {
@@ -290,7 +287,7 @@ async function loadSwaggerSource(options) {
290
287
  return a;
291
288
  }, "") : "";
292
289
  const outputFile = path.resolve(process.cwd(), output);
293
- fs.writeFileSync(outputFile, code + suffix);
290
+ fs.writeFileSync(outputFile, prefix + code + suffix);
294
291
  }
295
292
  function swagger2TsPlugin(userOptions) {
296
293
  resolveOptions(userOptions).then((options) => {
package/dist/index.mjs CHANGED
@@ -143,7 +143,7 @@ ${key}${isRequired === false ? "?" : ""}: `}any${key && `;`}`;
143
143
  result = `${Enum.map((t) => `"${t}"`).join(" | ")}`;
144
144
  } else if (items) {
145
145
  result = `${generatorSchemaType("", items, { docsName })}[]`;
146
- } else if (properties) {
146
+ } else if (properties && !isTypeAny(properties)) {
147
147
  result += `{${Object.entries(properties).map(([pName, _schema]) => generatorSchemaType(pName, _schema, { isRequired: !required || required.includes(pName) ? true : false, docsName })).join("")}
148
148
  }`;
149
149
  } else if (oneOf) {
@@ -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 convertObjPromise(docs);
221
+ docs = (await convertObj(docs, { patch: true })).openapi;
231
222
  else
232
223
  throw new Error(JSON.stringify(docs));
233
224
  }
@@ -272,6 +263,12 @@ 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
271
+ `;
275
272
  const code = interfaces.reduce((a, b) => a + b, "");
276
273
  const suffix = sources ? interfaces.reduce((a, b, index) => {
277
274
  if (b) {
@@ -281,7 +278,7 @@ async function loadSwaggerSource(options) {
281
278
  return a;
282
279
  }, "") : "";
283
280
  const outputFile = resolve(process.cwd(), output);
284
- writeFileSync(outputFile, code + suffix);
281
+ writeFileSync(outputFile, prefix + code + suffix);
285
282
  }
286
283
  function swagger2TsPlugin(userOptions) {
287
284
  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.7",
4
+ "version": "1.3.9",
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",