Skip to content

Commit 0d8d3b8

Browse files
authored
Merge pull request #904 from postmanlabs/feature/populate-example-path-param
[AB-1625] fixed emitting path param values in example request
2 parents 15a45fb + 408777d commit 0d8d3b8

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

libV2/utils.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ const _ = require('lodash'),
1414
url: requestItem.request.url
1515
},
1616
originalRequestQueryParams = _.get(response, 'originalRequest.params.queryParams',
17-
_.get(response, 'originalRequest.url.query', []));
17+
_.get(response, 'originalRequest.url.query', [])),
18+
originalRequestPathParams = _.get(response, 'originalRequest.params.pathParams',
19+
_.get(requestItem, 'request.url.variables.members', []));
1820

1921
/**
2022
* Setting variable
@@ -38,6 +40,7 @@ const _ = require('lodash'),
3840

3941
// Assimilate original query params as SDK doesn't handle query params well.
4042
sdkResponse.originalRequest.url.query.assimilate(originalRequestQueryParams);
43+
sdkResponse.originalRequest.url.variables.assimilate(originalRequestPathParams);
4144

4245
/**
4346
* Adding it here because sdk converts

test/unit/convertV2WithTypes.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,32 @@ describe('convertV2WithTypes should generate collection conforming to collection
153153
});
154154
});
155155

156+
describe('convertV2WithTypes - example originalRequest path variables', function() {
157+
it('should include populated path variable values in example originalRequest', function(done) {
158+
const openapi = fs.readFileSync(testSpec1, 'utf8'),
159+
options = { parametersResolution: 'schema' };
160+
161+
Converter.convertV2WithTypes({ type: 'string', data: openapi }, options, (err, conversionResult) => {
162+
expect(err).to.be.null;
163+
expect(conversionResult.result).to.equal(true);
164+
const item = conversionResult.output[0].data.item[1].item[0].item[0];
165+
166+
const requestPathVariables = item.request && item.request.url && item.request.url.variable || [];
167+
expect(requestPathVariables).to.be.an('array').that.is.not.empty;
168+
const requestPetIdVariable = requestPathVariables.find((v) => { return v && v.key === 'petId'; });
169+
expect(requestPetIdVariable).to.be.an('object');
170+
expect(requestPetIdVariable.value).to.equal('<string>');
171+
172+
const resp = item.response && item.response[0],
173+
exampleRequestPathVariables = resp.originalRequest && resp.originalRequest.url && resp.originalRequest.url.variable || [];
174+
expect(exampleRequestPathVariables).to.be.an('array').that.is.not.empty;
175+
const examplePetIdVariable = exampleRequestPathVariables.find((v) => { return v && v.key === 'petId'; });
176+
expect(examplePetIdVariable).to.be.an('object');
177+
expect(examplePetIdVariable.value).to.equal('<string>');
178+
done();
179+
});
180+
});
181+
});
156182

157183
describe('convertV2WithTypes', function() {
158184
it('should contain extracted types' + testSpec1, function () {

0 commit comments

Comments
 (0)