Skip to content

Commit 2373a83

Browse files
authored
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
1 parent 7fc2780 commit 2373a83

File tree

3 files changed

+1
-67
lines changed

3 files changed

+1
-67
lines changed

docs/usage/configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Parameter name | Docker variable | Description
6565
<a name="syntaxHighlight.activate"></a>`syntaxHighlight.activate` | _Unavailable_ | `Boolean=true`. Whether syntax highlighting should be activated or not.
6666
<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.)
6767
<a name="tryItOutEnabled"></a>`tryItOutEnabled` | `TRY_IT_OUT_ENABLED` | `Boolean=false`. Controls whether the "Try it out" section should be enabled by default.
68-
<a name="requestSnippets"></a>`requestSnippets` | _Unavailable_ | `Object`. This is the default configuration section for the the requestSnippets plugin.<br>requestSnippets: {<br>&nbsp;&nbsp;generators: {<br>&nbsp;&nbsp;&nbsp;&nbsp;"curl_bash": {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;title: "cURL (bash)",<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;syntax: "bash"<br>&nbsp;&nbsp;&nbsp;&nbsp;},<br>&nbsp;&nbsp;&nbsp;&nbsp;"curl_powershell": {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;title: "cURL (PowerShell)",<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;syntax: "powershell"<br>&nbsp;&nbsp;&nbsp;&nbsp;},<br>&nbsp;&nbsp;&nbsp;&nbsp;"curl_cmd": {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;title: "cURL (CMD)",<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;syntax: "bash"<br>&nbsp;&nbsp;&nbsp;&nbsp;},<br>&nbsp;&nbsp;&nbsp;&nbsp;"node_native": {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;title: "Node.js (Native)",<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;syntax: "javascript"<br>&nbsp;&nbsp;&nbsp;&nbsp;},<br>&nbsp;&nbsp;},<br>&nbsp;&nbsp;defaultExpanded: true,<br>&nbsp;&nbsp;languagesMask: null, // e.g. only show curl bash = \["curl_bash"\]<br>},
68+
<a name="requestSnippets"></a>`requestSnippets` | _Unavailable_ | `Object`. This is the default configuration section for the the requestSnippets plugin.<br>requestSnippets: {<br>&nbsp;&nbsp;generators: {<br>&nbsp;&nbsp;&nbsp;&nbsp;"curl_bash": {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;title: "cURL (bash)",<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;syntax: "bash"<br>&nbsp;&nbsp;&nbsp;&nbsp;},<br>&nbsp;&nbsp;&nbsp;&nbsp;"curl_powershell": {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;title: "cURL (PowerShell)",<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;syntax: "powershell"<br>&nbsp;&nbsp;&nbsp;&nbsp;},<br>&nbsp;&nbsp;&nbsp;&nbsp;"curl_cmd": {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;title: "cURL (CMD)",<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;syntax: "bash"<br>&nbsp;&nbsp;&nbsp;&nbsp;},<br>&nbsp;&nbsp;},<br>&nbsp;&nbsp;defaultExpanded: true,<br>&nbsp;&nbsp;languagesMask: null, // e.g. only show curl bash = \["curl_bash"\]<br>},
6969

7070

7171
##### Network

src/core/index.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ export default function SwaggerUI(opts) {
6868
title: "cURL (CMD)",
6969
syntax: "bash"
7070
},
71-
"node_native": {
72-
title: "Node.js (Native)",
73-
syntax: "javascript"
74-
},
7571
},
7672
defaultExpanded: true,
7773
languagesMask: null, // e.g. only show curl bash = ["curl_bash"]

src/core/plugins/request-snippets/fn.js

Lines changed: 0 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import win from "../../window"
22
import { Map } from "immutable"
3-
import Url from "url-parse"
43

54
/**
65
* if duplicate key name existed from FormData entries,
@@ -154,64 +153,3 @@ export const requestSnippetGenerator_curl_bash = (request) => {
154153
export const requestSnippetGenerator_curl_cmd = (request) => {
155154
return curlify(request, escapeCMD, "^\n")
156155
}
157-
158-
// eslint-disable-next-line camelcase
159-
export const requestSnippetGenerator_node_native = (request) => {
160-
const url = new Url(request.get("url"))
161-
let isMultipartFormDataRequest = false
162-
const headers = request.get("headers")
163-
if(headers && headers.size) {
164-
request.get("headers").map((val, key) => {
165-
isMultipartFormDataRequest = isMultipartFormDataRequest || /^content-type$/i.test(key) && /^multipart\/form-data$/i.test(val)
166-
})
167-
}
168-
const packageStr = url.protocol === "https:" ? "https" : "http"
169-
let reqBody = request.get("body")
170-
if (request.get("body")) {
171-
if (isMultipartFormDataRequest && ["POST", "PUT", "PATCH"].includes(request.get("method"))) {
172-
return "throw new Error(\"Currently unsupported content-type: /^multipart\\/form-data$/i\");"
173-
} else {
174-
if (!Map.isMap(reqBody)) {
175-
if (typeof reqBody !== "string") {
176-
reqBody = JSON.stringify(reqBody)
177-
}
178-
} else {
179-
reqBody = getStringBodyOfMap(request)
180-
}
181-
}
182-
} else if (!request.get("body") && request.get("method") === "POST") {
183-
reqBody = ""
184-
}
185-
186-
const stringBody = "`" + (reqBody || "")
187-
.replace(/\\n/g, "\n")
188-
.replace(/`/g, "\\`")
189-
+ "`"
190-
191-
return `const http = require("${packageStr}");
192-
193-
const options = {
194-
"method": "${request.get("method")}",
195-
"hostname": "${url.host}",
196-
"port": ${url.port || "null"},
197-
"path": "${url.pathname}"${headers && headers.size ? `,
198-
"headers": {
199-
${request.get("headers").map((val, key) => `"${key}": "${val}"`).valueSeq().join(",\n ")}
200-
}` : ""}
201-
};
202-
203-
const req = http.request(options, function (res) {
204-
const chunks = [];
205-
206-
res.on("data", function (chunk) {
207-
chunks.push(chunk);
208-
});
209-
210-
res.on("end", function () {
211-
const body = Buffer.concat(chunks);
212-
console.log(body.toString());
213-
});
214-
});
215-
${reqBody ? `\nreq.write(${stringBody});` : ""}
216-
req.end();`
217-
}

0 commit comments

Comments
 (0)