feat: remove node_native option from request snippets plugin (#7181)
* snippet generator support intended for different shell options only * will not maintain snippet generator for various languages
This commit is contained in:
@@ -65,7 +65,7 @@ Parameter name | Docker variable | Description
|
||||
<a name="syntaxHighlight.activate"></a>`syntaxHighlight.activate` | _Unavailable_ | `Boolean=true`. Whether syntax highlighting should be activated or not.
|
||||
<a name="syntaxHighlight.theme"></a>`syntaxHighlight.theme` | _Unavailable_ | `String=["agate"*, "arta", "monokai", "nord", "obsidian", "tomorrow-night"]`. [Highlight.js](https://highlightjs.org/static/demo/) syntax coloring theme to use. (Only these 6 styles are available.)
|
||||
<a name="tryItOutEnabled"></a>`tryItOutEnabled` | `TRY_IT_OUT_ENABLED` | `Boolean=false`. Controls whether the "Try it out" section should be enabled by default.
|
||||
<a name="requestSnippets"></a>`requestSnippets` | _Unavailable_ | `Object`. This is the default configuration section for the the requestSnippets plugin.<br>requestSnippets: {<br> generators: {<br> "curl_bash": {<br> title: "cURL (bash)",<br> syntax: "bash"<br> },<br> "curl_powershell": {<br> title: "cURL (PowerShell)",<br> syntax: "powershell"<br> },<br> "curl_cmd": {<br> title: "cURL (CMD)",<br> syntax: "bash"<br> },<br> "node_native": {<br> title: "Node.js (Native)",<br> syntax: "javascript"<br> },<br> },<br> defaultExpanded: true,<br> languagesMask: null, // e.g. only show curl bash = \["curl_bash"\]<br>},
|
||||
<a name="requestSnippets"></a>`requestSnippets` | _Unavailable_ | `Object`. This is the default configuration section for the the requestSnippets plugin.<br>requestSnippets: {<br> generators: {<br> "curl_bash": {<br> title: "cURL (bash)",<br> syntax: "bash"<br> },<br> "curl_powershell": {<br> title: "cURL (PowerShell)",<br> syntax: "powershell"<br> },<br> "curl_cmd": {<br> title: "cURL (CMD)",<br> syntax: "bash"<br> },<br> },<br> defaultExpanded: true,<br> languagesMask: null, // e.g. only show curl bash = \["curl_bash"\]<br>},
|
||||
|
||||
|
||||
##### Network
|
||||
|
||||
@@ -68,10 +68,6 @@ export default function SwaggerUI(opts) {
|
||||
title: "cURL (CMD)",
|
||||
syntax: "bash"
|
||||
},
|
||||
"node_native": {
|
||||
title: "Node.js (Native)",
|
||||
syntax: "javascript"
|
||||
},
|
||||
},
|
||||
defaultExpanded: true,
|
||||
languagesMask: null, // e.g. only show curl bash = ["curl_bash"]
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import win from "../../window"
|
||||
import { Map } from "immutable"
|
||||
import Url from "url-parse"
|
||||
|
||||
/**
|
||||
* if duplicate key name existed from FormData entries,
|
||||
@@ -154,64 +153,3 @@ export const requestSnippetGenerator_curl_bash = (request) => {
|
||||
export const requestSnippetGenerator_curl_cmd = (request) => {
|
||||
return curlify(request, escapeCMD, "^\n")
|
||||
}
|
||||
|
||||
// eslint-disable-next-line camelcase
|
||||
export const requestSnippetGenerator_node_native = (request) => {
|
||||
const url = new Url(request.get("url"))
|
||||
let isMultipartFormDataRequest = false
|
||||
const headers = request.get("headers")
|
||||
if(headers && headers.size) {
|
||||
request.get("headers").map((val, key) => {
|
||||
isMultipartFormDataRequest = isMultipartFormDataRequest || /^content-type$/i.test(key) && /^multipart\/form-data$/i.test(val)
|
||||
})
|
||||
}
|
||||
const packageStr = url.protocol === "https:" ? "https" : "http"
|
||||
let reqBody = request.get("body")
|
||||
if (request.get("body")) {
|
||||
if (isMultipartFormDataRequest && ["POST", "PUT", "PATCH"].includes(request.get("method"))) {
|
||||
return "throw new Error(\"Currently unsupported content-type: /^multipart\\/form-data$/i\");"
|
||||
} else {
|
||||
if (!Map.isMap(reqBody)) {
|
||||
if (typeof reqBody !== "string") {
|
||||
reqBody = JSON.stringify(reqBody)
|
||||
}
|
||||
} else {
|
||||
reqBody = getStringBodyOfMap(request)
|
||||
}
|
||||
}
|
||||
} else if (!request.get("body") && request.get("method") === "POST") {
|
||||
reqBody = ""
|
||||
}
|
||||
|
||||
const stringBody = "`" + (reqBody || "")
|
||||
.replace(/\\n/g, "\n")
|
||||
.replace(/`/g, "\\`")
|
||||
+ "`"
|
||||
|
||||
return `const http = require("${packageStr}");
|
||||
|
||||
const options = {
|
||||
"method": "${request.get("method")}",
|
||||
"hostname": "${url.host}",
|
||||
"port": ${url.port || "null"},
|
||||
"path": "${url.pathname}"${headers && headers.size ? `,
|
||||
"headers": {
|
||||
${request.get("headers").map((val, key) => `"${key}": "${val}"`).valueSeq().join(",\n ")}
|
||||
}` : ""}
|
||||
};
|
||||
|
||||
const req = http.request(options, function (res) {
|
||||
const chunks = [];
|
||||
|
||||
res.on("data", function (chunk) {
|
||||
chunks.push(chunk);
|
||||
});
|
||||
|
||||
res.on("end", function () {
|
||||
const body = Buffer.concat(chunks);
|
||||
console.log(body.toString());
|
||||
});
|
||||
});
|
||||
${reqBody ? `\nreq.write(${stringBody});` : ""}
|
||||
req.end();`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user