diff --git a/packages/bruno-app/src/utils/codemirror/autocomplete.js b/packages/bruno-app/src/utils/codemirror/autocomplete.js index 38e4e1fdc..1c3395814 100644 --- a/packages/bruno-app/src/utils/codemirror/autocomplete.js +++ b/packages/bruno-app/src/utils/codemirror/autocomplete.js @@ -27,6 +27,7 @@ const STATIC_API_HINTS = { 'req.setTimeout(timeout)', 'req.getExecutionMode()', 'req.getName()', + 'req.getPathParams()', 'req.getTags()', 'req.disableParsingResponseJson()', 'req.onFail(function(err) {})' diff --git a/packages/bruno-electron/src/ipc/network/index.js b/packages/bruno-electron/src/ipc/network/index.js index 633f5dd6c..f91673b0a 100644 --- a/packages/bruno-electron/src/ipc/network/index.js +++ b/packages/bruno-electron/src/ipc/network/index.js @@ -278,9 +278,6 @@ const configureRequest = async ( request.url = urlObj.toString(); } - // Remove pathParams, already in URL (Issue #2439) - delete request.pathParams; - // Remove apiKeyAuthValueForQueryParams, already interpolated and added to URL delete request.apiKeyAuthValueForQueryParams; diff --git a/packages/bruno-js/src/bruno-request.js b/packages/bruno-js/src/bruno-request.js index 12275fd53..64b64db51 100644 --- a/packages/bruno-js/src/bruno-request.js +++ b/packages/bruno-js/src/bruno-request.js @@ -18,6 +18,7 @@ class BrunoRequest { this.headers = req.headers; this.timeout = req.timeout; this.name = req.name; + this.pathParams = req.pathParams; this.tags = req.tags || []; /** * We automatically parse the JSON body if the content type is JSON @@ -191,6 +192,10 @@ class BrunoRequest { return this.req.name; } + getPathParams() { + return this.req.pathParams; + } + /** * Get the tags associated with this request * @returns {Array} Array of tag strings diff --git a/packages/bruno-js/src/sandbox/quickjs/shims/bruno-request.js b/packages/bruno-js/src/sandbox/quickjs/shims/bruno-request.js index df014b9c6..78d872b68 100644 --- a/packages/bruno-js/src/sandbox/quickjs/shims/bruno-request.js +++ b/packages/bruno-js/src/sandbox/quickjs/shims/bruno-request.js @@ -9,6 +9,7 @@ const addBrunoRequestShimToContext = (vm, req) => { const body = marshallToVm(req.getBody(), vm); const timeout = marshallToVm(req.getTimeout(), vm); const name = marshallToVm(req.getName(), vm); + const pathParams = marshallToVm(req.getPathParams(), vm); const tags = marshallToVm(req.getTags(), vm); vm.setProp(reqObject, 'url', url); @@ -17,6 +18,7 @@ const addBrunoRequestShimToContext = (vm, req) => { vm.setProp(reqObject, 'body', body); vm.setProp(reqObject, 'timeout', timeout); vm.setProp(reqObject, 'name', name); + vm.setProp(reqObject, 'pathParams', pathParams); vm.setProp(reqObject, 'tags', tags); url.dispose(); @@ -25,6 +27,7 @@ const addBrunoRequestShimToContext = (vm, req) => { body.dispose(); timeout.dispose(); name.dispose(); + pathParams.dispose(); tags.dispose(); let getUrl = vm.newFunction('getUrl', function () { @@ -57,6 +60,12 @@ const addBrunoRequestShimToContext = (vm, req) => { vm.setProp(reqObject, 'getName', getName); getName.dispose(); + let getPathParams = vm.newFunction('getPathParams', function () { + return marshallToVm(req.getPathParams(), vm); + }); + vm.setProp(reqObject, 'getPathParams', getPathParams); + getPathParams.dispose(); + let setMethod = vm.newFunction('setMethod', function (method) { req.setMethod(vm.dump(method)); }); diff --git a/packages/bruno-tests/collection/scripting/api/req/getPathParams.bru b/packages/bruno-tests/collection/scripting/api/req/getPathParams.bru new file mode 100644 index 000000000..71fa92ae2 --- /dev/null +++ b/packages/bruno-tests/collection/scripting/api/req/getPathParams.bru @@ -0,0 +1,23 @@ +meta { + name: getPathParam + type: http + seq: 1 +} + +get { + url: {{host}}/:pathParam + body: none + auth: none +} + +params:path { + pathParam: ping +} + +tests { + test("req.getPathParams()", function() { + const pathParams = req.getPathParams(); + expect(pathParams[0].name).to.equal('pathParam'); + expect(pathParams[0].value).to.equal('ping'); + }); +}