Open NianHan-Advantech opened 1 month ago
Now I'm doing this
var code = clientGenerator.GenerateFile();
code = code.Replace("responseType: \"blob\",", "");
code = code.Replace("<FileResponse>", "<any>");
code = code.Replace("const contentDisposition = response.headers ? response.headers[\"content-disposition\"] : undefined;", "");
code = code.Replace("let fileNameMatch = contentDisposition ? /filename\\*=(?:(\\\\?['\"])(.*?)\\1|(?:[^\\s]+'.*?')?([^;\\n]*))/g.exec(contentDisposition) : undefined;", "");
code = code.Replace("let fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[3] || fileNameMatch[2] : undefined;", "");
code = code.Replace("if (fileName) {", "if (process.env.NODE_ENV === \"production\") {");
code = code.Replace("fileName = decodeURIComponent(fileName);", "");
code = code.Replace("fileNameMatch = contentDisposition ? /filename=\"?([^\"]*?)\"?(;|$)/g.exec(contentDisposition) : undefined;", "");
code = code.Replace("fileName = fileNameMatch && fileNameMatch.length > 1 ? fileNameMatch[1] : undefined;", "console.log(\"response: \", response);");
code = code.Replace("{ fileName: fileName, status: status, data: new Blob([response.data], { type: response.headers[\"content-type\"] }), headers: _headers }", "response.data");
During use, the return values of most interfaces are recognized as FileResponse, and the blob type data needs to be converted into corresponding objects. May I ask if it is possible to change some unrecognized returns to Promise,
Just like this
Or we can handle the return processing ourselves.
Or is there something I haven't discovered, such as using custom templates to generate API code.