Skip to content

Commit 50e1eb0

Browse files
authored
Merge pull request #760 from postmanlabs/feature/add-description
Add description for path variables to the request if present in OpenAPI schema
2 parents 150a7c0 + c984919 commit 50e1eb0

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

libV2/utils.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ const sdk = require('postman-collection'),
6666
});
6767

6868
requestItem.request.url.variables.assimilate(pathParams);
69+
_.forEach(pathParams, (param) => {
70+
if (param.description) {
71+
const item = requestItem.request.url.variables.one(param.key);
72+
if (!_.isEmpty(item)) {
73+
item.description = param.description;
74+
}
75+
}
76+
});
77+
6978
requestItem.request.auth = auth;
7079

7180
_.forEach(responses, (response) => {
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"openapi": "3.0.0",
3+
"info": {
4+
"version": "1.0.0",
5+
"title": "Swagger Petstore",
6+
"license": {
7+
"name": "MIT"
8+
}
9+
},
10+
"servers": [
11+
{
12+
"url": "http://petstore.swagger.io/v1"
13+
}
14+
],
15+
"paths": {
16+
"/pets/{petId}": {
17+
"get": {
18+
"summary": "List all pets",
19+
"operationId": "listPets",
20+
"parameters": [
21+
{
22+
"name": "petId",
23+
"in": "path",
24+
"description": "Id of pet",
25+
"required": true,
26+
"schema": {
27+
"type": "integer",
28+
"format": "int32"
29+
}
30+
}
31+
],
32+
"responses": {
33+
"200": {
34+
"description": "Successful response",
35+
"headers": {
36+
"responseHeader1": {
37+
"description":"Description of responseHeader1",
38+
"required": true,
39+
"schema": {
40+
"type": "integer"
41+
}
42+
},
43+
"responseHeader2": {
44+
"description":"Description of responseHeader2",
45+
"schema": {
46+
"type": "integer"
47+
}
48+
}
49+
}
50+
}
51+
}
52+
}
53+
}
54+
}
55+
}

test/unit/convertV2.test.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const expect = require('chai').expect,
3030
examplesOutsideSchema = path.join(__dirname, VALID_OPENAPI_PATH + '/examples_outside_schema.json'),
3131
exampleOutsideSchema = path.join(__dirname, VALID_OPENAPI_PATH + '/example_outside_schema.json'),
3232
descriptionInBodyParams = path.join(__dirname, VALID_OPENAPI_PATH + '/description_in_body_params.json'),
33+
descriptionInPathParams = path.join(__dirname, VALID_OPENAPI_PATH + '/path_params_with_description.json'),
3334
zeroDefaultValueSpec = path.join(__dirname, VALID_OPENAPI_PATH + '/zero_in_default_value.json'),
3435
requiredInParams = path.join(__dirname, VALID_OPENAPI_PATH, '/required_in_parameters.json'),
3536
multipleRefs = path.join(__dirname, VALID_OPENAPI_PATH, '/multiple_refs.json'),
@@ -552,6 +553,16 @@ describe('The convert v2 Function', function() {
552553
});
553554
});
554555

556+
it('should add description in path params', function (done) {
557+
var openapi = fs.readFileSync(descriptionInPathParams, 'utf-8');
558+
Converter.convertV2({ type: 'string', data: openapi }, { schemaFaker: true }, (err, conversionResult) => {
559+
let description = conversionResult.output[0].data.item[0].item[0].item[0].request.url.variable[0].description;
560+
expect(err).to.be.null;
561+
expect(description).to.equal('(Required) Id of pet');
562+
done();
563+
});
564+
});
565+
555566
it('Should create collection from folder having one root file for browser', function(done) {
556567
let folderPath = path.join(__dirname, '../data/petstore separate yaml'),
557568
files = [],

0 commit comments

Comments
 (0)