@1szx1/vite-plugin-swagger2ts 1.2.0 → 1.2.2
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 +9 -5
- package/dist/index.mjs +9 -5
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -139,9 +139,8 @@ const TYPES = {
|
|
|
139
139
|
};
|
|
140
140
|
function generatorSchemaType(key, schema, { isRoot = false, isRequired, isExport = false, docsName = "" } = {}) {
|
|
141
141
|
if (isTypeAny(schema)) {
|
|
142
|
-
return `
|
|
143
|
-
${key}${isRequired === false ? "?" : ""}: any
|
|
144
|
-
`;
|
|
142
|
+
return `${key && `
|
|
143
|
+
${key}${isRequired === false ? "?" : ""}: `}any${key && `;`}`;
|
|
145
144
|
}
|
|
146
145
|
const { type, $ref, enum: Enum, items, properties, oneOf, additionalProperties, required, allOf } = schema;
|
|
147
146
|
let result = "";
|
|
@@ -195,9 +194,13 @@ function generatorResponseBodyType(schemas, docsName) {
|
|
|
195
194
|
} else {
|
|
196
195
|
result = generatorSchemaType("", schema, { docsName });
|
|
197
196
|
}
|
|
197
|
+
if (result.includes("any;"))
|
|
198
|
+
console.log(jsDoc({ description }, { key: "response", result }));
|
|
198
199
|
return jsDoc({ description }, { key: "response", result });
|
|
199
200
|
}
|
|
200
201
|
function jsDoc({ description, title, format, example, default: default1 }, { key, result, isRoot, isExport, isRequired }) {
|
|
202
|
+
if (!/(^\[.+\]$)|(^[^\[\]]*$)/.test(key))
|
|
203
|
+
key = `'${key}'`;
|
|
201
204
|
const jsDoc2 = `
|
|
202
205
|
/**
|
|
203
206
|
${title ? ` * @title ${title}
|
|
@@ -240,9 +243,10 @@ async function loadSwaggerSource(options) {
|
|
|
240
243
|
const { url, name } = source;
|
|
241
244
|
try {
|
|
242
245
|
const docs = await fetchUrl(`${swaggerUrl}${url}`);
|
|
243
|
-
|
|
246
|
+
const code2 = await genInterface(docs, name);
|
|
247
|
+
return code2;
|
|
244
248
|
} catch (error) {
|
|
245
|
-
console.log(`%c[vite-plugin-swagger2ts]: ${name} error`, "color: #ff0000;", error);
|
|
249
|
+
console.log(`%c[vite-plugin-swagger2ts]: ${name} error`, "color: #ff0000;", error.message);
|
|
246
250
|
return "";
|
|
247
251
|
}
|
|
248
252
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -131,9 +131,8 @@ const TYPES = {
|
|
|
131
131
|
};
|
|
132
132
|
function generatorSchemaType(key, schema, { isRoot = false, isRequired, isExport = false, docsName = "" } = {}) {
|
|
133
133
|
if (isTypeAny(schema)) {
|
|
134
|
-
return `
|
|
135
|
-
${key}${isRequired === false ? "?" : ""}: any
|
|
136
|
-
`;
|
|
134
|
+
return `${key && `
|
|
135
|
+
${key}${isRequired === false ? "?" : ""}: `}any${key && `;`}`;
|
|
137
136
|
}
|
|
138
137
|
const { type, $ref, enum: Enum, items, properties, oneOf, additionalProperties, required, allOf } = schema;
|
|
139
138
|
let result = "";
|
|
@@ -187,9 +186,13 @@ function generatorResponseBodyType(schemas, docsName) {
|
|
|
187
186
|
} else {
|
|
188
187
|
result = generatorSchemaType("", schema, { docsName });
|
|
189
188
|
}
|
|
189
|
+
if (result.includes("any;"))
|
|
190
|
+
console.log(jsDoc({ description }, { key: "response", result }));
|
|
190
191
|
return jsDoc({ description }, { key: "response", result });
|
|
191
192
|
}
|
|
192
193
|
function jsDoc({ description, title, format, example, default: default1 }, { key, result, isRoot, isExport, isRequired }) {
|
|
194
|
+
if (!/(^\[.+\]$)|(^[^\[\]]*$)/.test(key))
|
|
195
|
+
key = `'${key}'`;
|
|
193
196
|
const jsDoc2 = `
|
|
194
197
|
/**
|
|
195
198
|
${title ? ` * @title ${title}
|
|
@@ -232,9 +235,10 @@ async function loadSwaggerSource(options) {
|
|
|
232
235
|
const { url, name } = source;
|
|
233
236
|
try {
|
|
234
237
|
const docs = await fetchUrl(`${swaggerUrl}${url}`);
|
|
235
|
-
|
|
238
|
+
const code2 = await genInterface(docs, name);
|
|
239
|
+
return code2;
|
|
236
240
|
} catch (error) {
|
|
237
|
-
console.log(`%c[vite-plugin-swagger2ts]: ${name} error`, "color: #ff0000;", error);
|
|
241
|
+
console.log(`%c[vite-plugin-swagger2ts]: ${name} error`, "color: #ff0000;", error.message);
|
|
238
242
|
return "";
|
|
239
243
|
}
|
|
240
244
|
}
|
package/package.json
CHANGED