Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
Lint, ES6, popover for codegen
Liyas Thomaseaeefafe39bd
diff --git a/components/firebase/__tests__/feeds.spec.js b/components/firebase/__tests__/feeds.spec.jsindex 09d53786e..e15900bdd 100644--- a/components/firebase/__tests__/feeds.spec.js+++ b/components/firebase/__tests__/feeds.spec.js@@ -1,34 +1,33 @@import feeds from "../feeds"import { shallowMount } from "@vue/test-utils"-jest.mock("~/helpers/fb", () => {- return {- __esModule: true,- fb: {- currentFeeds: [- {- id: "test1",- label: "First",- message: "First Message",- },- {- id: "test2",- label: "Second",- },- {- id: "test3",- message: "Third Message",- },- {- id: "test4",- },- ],- deleteFeed: jest.fn(() => Promise.resolve()),- },- }-})+jest.mock("~/helpers/fb", () => ({+ __esModule: true,++ fb: {+ currentFeeds: [+ {+ id: "test1",+ label: "First",+ message: "First Message",+ },+ {+ id: "test2",+ label: "Second",+ },+ {+ id: "test3",+ message: "Third Message",+ },+ {+ id: "test4",+ },+ ],+ deleteFeed: jest.fn(() => Promise.resolve()),+ },+}))-const { fb } = require("~/helpers/fb")+import { fb } from "~/helpers/fb"const factory = () =>shallowMount(feeds, {diff --git a/components/firebase/__tests__/inputform.spec.js b/components/firebase/__tests__/inputform.spec.jsindex f5d42bbd5..f3a170a93 100644--- a/components/firebase/__tests__/inputform.spec.js+++ b/components/firebase/__tests__/inputform.spec.js@@ -1,16 +1,15 @@import inputform from "../inputform"import { shallowMount } from "@vue/test-utils"-jest.mock("~/helpers/fb", () => {- return {- __esModule: true,- fb: {- writeFeeds: jest.fn(() => Promise.resolve()),- },- }-})+jest.mock("~/helpers/fb", () => ({+ __esModule: true,++ fb: {+ writeFeeds: jest.fn(() => Promise.resolve()),+ },+}))-const { fb } = require("~/helpers/fb")+import { fb } from "~/helpers/fb"const factory = () =>shallowMount(inputform, {diff --git a/components/firebase/__tests__/logout.spec.js b/components/firebase/__tests__/logout.spec.jsindex b13256249..31ca4f71d 100644--- a/components/firebase/__tests__/logout.spec.js+++ b/components/firebase/__tests__/logout.spec.js@@ -1,16 +1,15 @@import logout from "../logout"import { shallowMount, createLocalVue } from "@vue/test-utils"-jest.mock("~/helpers/fb", () => {- return {- __esModule: true,- fb: {- signOutUser: jest.fn(() => Promise.resolve()),- },- }-})+jest.mock("~/helpers/fb", () => ({+ __esModule: true,++ fb: {+ signOutUser: jest.fn(() => Promise.resolve()),+ },+}))-const { fb } = require("~/helpers/fb")+import { fb } from "~/helpers/fb"const $toast = {info: jest.fn(),diff --git a/helpers/codegen/generators/cs-restsharp.js b/helpers/codegen/generators/cs-restsharp.jsindex ac6032316..b6f0dda75 100644--- a/helpers/codegen/generators/cs-restsharp.js+++ b/helpers/codegen/generators/cs-restsharp.js@@ -22,39 +22,43 @@ export const CsRestSharpCodegen = {// initial request setuplet requestBody = rawInput ? rawParams : rawRequestBody- requestBody = requestBody.replace(/"/g,'""'); // escape quotes for C# verbatim string compatibility+ requestBody = requestBody.replace(/"/g, '""') // escape quotes for C# verbatim string compatibility// prepare data- let requestDataFormat;- let requestContentType;+ let requestDataFormat+ let requestContentType- if(isJSONContentType(contentType)) {- requestDataFormat = 'DataFormat.Json'- requestContentType = 'text/json'+ if (isJSONContentType(contentType)) {+ requestDataFormat = "DataFormat.Json"+ requestContentType = "text/json"} else {- requestDataFormat = 'DataFormat.Xml'- requestContentType = 'text/xml'+ requestDataFormat = "DataFormat.Xml"+ requestContentType = "text/xml"}const verbs = [- { verb: 'GET', csMethod: 'Get' },- { verb: 'POST', csMethod: 'Post' },- { verb: 'PUT', csMethod: 'Put' },- { verb: 'PATCH', csMethod: 'Patch' },- { verb: 'DELETE', csMethod: 'Delete' },+ { verb: "GET", csMethod: "Get" },+ { verb: "POST", csMethod: "Post" },+ { verb: "PUT", csMethod: "Put" },+ { verb: "PATCH", csMethod: "Patch" },+ { verb: "DELETE", csMethod: "Delete" },]// create client and requestrequestString.push(`var client = new RestClient("${url}");\n\n`)- requestString.push(`var request = new RestRequest("${pathName}${queryString}", ${requestDataFormat});\n\n`)-+ requestString.push(+ `var request = new RestRequest("${pathName}${queryString}", ${requestDataFormat});\n\n`+ )+// authentificationif (auth === "Basic Auth") {- requestString.push(`client.Authenticator = new HttpBasicAuthenticator("${httpUser}", "${httpPassword}");\n`)+ requestString.push(+ `client.Authenticator = new HttpBasicAuthenticator("${httpUser}", "${httpPassword}");\n`+ )} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {requestString.push(`request.AddHeader("Authorization", "Bearer ${bearerToken}");\n`)}-+// content typeif (contentType) {requestString.push(`request.AddHeader("Content-Type", "${contentType}");\n`)@@ -70,19 +74,23 @@ export const CsRestSharpCodegen = {}requestString.push(`\n`)-+// set bodyif (["POST", "PUT", "PATCH", "DELETE"].includes(method)) {- requestString.push(`request.AddParameter("${requestContentType}", @"${requestBody}", ParameterType.RequestBody);\n\n`)+ requestString.push(+ `request.AddParameter("${requestContentType}", @"${requestBody}", ParameterType.RequestBody);\n\n`+ )}-+// process- const verb = verbs.find(v => v.verb === method)+ const verb = verbs.find((v) => v.verb === method)requestString.push(`var response = client.${verb.csMethod}(request);\n\n`)// analyse result- requestString.push(`if (!response.IsSuccessful)\n{\n Console.WriteLine("An error occured " + response.ErrorMessage);\n}\n\n`)-+ requestString.push(+ `if (!response.IsSuccessful)\n{\n Console.WriteLine("An error occured " + response.ErrorMessage);\n}\n\n`+ )+requestString.push(`var result = response.Content;\n`)return requestString.join("")diff --git a/helpers/codegen/generators/nodejs-request.js b/helpers/codegen/generators/nodejs-request.jsindex ace908795..378058a4e 100644--- a/helpers/codegen/generators/nodejs-request.js+++ b/helpers/codegen/generators/nodejs-request.js@@ -42,7 +42,7 @@ export const NodeJsRequestCodegen = {reqBodyType = "body"} else if (contentType.includes("x-www-form-urlencoded")) {const formData = []- if (requestBody.indexOf("=") > -1) {+ if (requestBody.includes("=")) {requestBody.split("&").forEach((rq) => {const [key, val] = rq.split("=")formData.push(`"${key}": "${val}"`)diff --git a/helpers/codegen/generators/php-curl.js b/helpers/codegen/generators/php-curl.jsindex 40f3fb4b6..c5e12b65e 100644--- a/helpers/codegen/generators/php-curl.js+++ b/helpers/codegen/generators/php-curl.js@@ -56,7 +56,7 @@ export const PhpCurlCodegen = {} else if (isJSONContentType(contentType)) {requestBody = JSON.stringify(requestBody)} else if (contentType.includes("x-www-form-urlencoded")) {- if (requestBody.indexOf("=") > -1) {+ if (requestBody.includes("=")) {requestBody = `"${requestBody}"`} else {const requestObject = JSON.parse(requestBody)diff --git a/helpers/codegen/generators/powershell.js b/helpers/codegen/generators/powershell.jsindex 67acd2425..dd1dddf0d 100644--- a/helpers/codegen/generators/powershell.js+++ b/helpers/codegen/generators/powershell.js@@ -18,7 +18,7 @@ export const PowerShellRestMethod = {}) => {const methodsWithBody = ["Put", "Post", "Delete"]const formattedMethod = method[0].toUpperCase() + method.substring(1).toLowerCase()- const includeBody = methodsWithBody.indexOf(formattedMethod) >= 0+ const includeBody = methodsWithBody.includes(formattedMethod)const requestString = []let genHeaders = []let variables = ""diff --git a/helpers/codegen/generators/python-http-client.js b/helpers/codegen/generators/python-http-client.jsindex 941188376..20cbd3274 100644--- a/helpers/codegen/generators/python-http-client.js+++ b/helpers/codegen/generators/python-http-client.js@@ -72,7 +72,7 @@ export const PythonHttpClientCodegen = {requestString.push(`payload = ${requestBody}\n`)} else if (contentType.includes("x-www-form-urlencoded")) {const formData = []- if (requestBody.indexOf("=") > -1) {+ if (requestBody.includes("=")) {requestBody.split("&").forEach((rq) => {const [key, val] = rq.split("=")formData.push(`('${key}', '${val}')`)diff --git a/helpers/codegen/generators/python-requests.js b/helpers/codegen/generators/python-requests.jsindex 24cdc9657..771acf4c7 100644--- a/helpers/codegen/generators/python-requests.js+++ b/helpers/codegen/generators/python-requests.js@@ -66,7 +66,7 @@ export const PythonRequestsCodegen = {requestString.push(`data = ${requestBody}\n`)} else if (contentType.includes("x-www-form-urlencoded")) {const formData = []- if (requestBody.indexOf("=") > -1) {+ if (requestBody.includes("=")) {requestBody.split("&").forEach((rq) => {const [key, val] = rq.split("=")formData.push(`('${key}', '${val}')`)diff --git a/helpers/codegen/generators/shell-httpie.js b/helpers/codegen/generators/shell-httpie.jsindex 18cce7113..10bb2b6cf 100644--- a/helpers/codegen/generators/shell-httpie.js+++ b/helpers/codegen/generators/shell-httpie.js@@ -17,7 +17,7 @@ export const ShellHTTPie = {headers,}) => {const methodsWithBody = ["POST", "PUT", "PATCH", "DELETE"]- const includeBody = methodsWithBody.indexOf(method) >= 0+ const includeBody = methodsWithBody.includes(method)const requestString = []let requestBody = rawInput ? rawParams : rawRequestBodydiff --git a/helpers/fb.js b/helpers/fb.jsindex 90fb90881..f564448d8 100644--- a/helpers/fb.js+++ b/helpers/fb.js@@ -309,7 +309,7 @@ export class FirebaseInstance {author: this.currentUser.uid,author_name: this.currentUser.displayName,author_image: this.currentUser.photoURL,- team: team,+ team,}try {diff --git a/pages/index.vue b/pages/index.vueindex 791c44a68..61b37a759 100644--- a/pages/index.vue+++ b/pages/index.vue@@ -1043,11 +1043,23 @@<li><label for="requestType">{{ $t("request_type") }}</label><span class="select-wrapper">- <select id="requestType" v-model="requestType">- <option v-for="gen in codegens" :key="gen.id" :value="gen.id">- {{ gen.name }}- </option>- </select>+ <v-popover>+ <input+ id="requestType"+ v-model="requestType"+ :placeholder="$t('choose_language')"+ class="cursor-pointer"+ readonly+ autofocus+ />+ <template slot="popover">+ <div v-for="gen in codegens" :key="gen.id">+ <button class="icon" @click="requestType = gen.id" v-close-popover>+ {{ gen.name }}+ </button>+ </div>+ </template>+ </v-popover></span></li></ul>