feat: js api supports get path params (#5235)

This commit is contained in:
David Skrivanek
2026-01-09 10:30:13 +00:00
committed by GitHub
parent 45264bfcc5
commit 3b33fa89d1
5 changed files with 38 additions and 3 deletions

View File

@@ -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) {})'

View File

@@ -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;

View File

@@ -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<string>} Array of tag strings

View File

@@ -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));
});

View File

@@ -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');
});
}