fix#6247: Interpolate dynamic variables in path param (#6251)

This commit is contained in:
Nikhil
2026-02-27 12:21:32 +05:30
committed by GitHub
parent fcfb7d409c
commit 3fdb81849c
3 changed files with 29 additions and 3 deletions

View File

@@ -95,7 +95,8 @@ const GenerateCodeItem = ({ collectionUid, item, onClose, isExample = false, exa
// interpolate the path params
const finalUrl = interpolateUrlPathParams(
interpolatedUrl,
requestData.params
requestData.params,
variables
);
// Get the full language object based on current preferences

View File

@@ -98,9 +98,9 @@ export const interpolateUrl = ({ url, variables }) => {
return interpolate(url, variables);
};
export const interpolateUrlPathParams = (url, params) => {
export const interpolateUrlPathParams = (url, params, variables = {}) => {
const getInterpolatedBasePath = (pathname, params) => {
return pathname
let replacedPathname = pathname
.split('/')
.map((segment) => {
// traditional path parameters
@@ -137,6 +137,8 @@ export const interpolateUrlPathParams = (url, params) => {
return result;
})
.join('/');
return interpolate(replacedPathname, variables);
};
let uri;

View File

@@ -319,6 +319,29 @@ describe('Url Utils - interpolateUrl, interpolateUrlPathParams', () => {
expect(result).toEqual(expectedUrl);
});
it('should interpolate path params correctly', () => {
const url = 'https://example.com/api/:id/path/:user';
const params = [{ name: 'id', type: 'path', enabled: true, value: '123' }, { name: 'user', type: 'path', enabled: true, value: '{{user}}' }];
const variables = { user: 'John' };
const expectedUrl = 'https://example.com/api/123/path/John';
const result = interpolateUrlPathParams(url, params, variables);
expect(result).toEqual(expectedUrl);
});
it('should interpolate url and path params correctly', () => {
const url = '{{host}}/api/:id/path/:user?foo={{foo}}&bar={{bar}}&baz={{process.env.baz}}';
const params = [{ name: 'id', type: 'path', enabled: true, value: '123' }, { name: 'user', type: 'path', enabled: true, value: '{{user}}' }];
const variables = { 'host': 'https://example.com', 'foo': 'foo_value', 'bar': 'bar_value', 'process.env.baz': 'baz_value', 'user': 'John' };
const expectedUrl = 'https://example.com/api/123/path/John?foo=foo_value&bar=bar_value&baz=baz_value';
const intermediateResult = interpolateUrl({ url, variables });
const result = interpolateUrlPathParams(intermediateResult, params, variables);
expect(result).toEqual(expectedUrl);
});
it('should handle empty params', () => {
const url = 'https://example.com/api';
const params = [];