Skip to content

Commit a43b61b

Browse files
authored
Merge pull request #602 from postmanlabs/feature/fix-request-protocol-profile-behavior
Fixed issue where disableBodyPruning option was not set for requests with no request body.
2 parents 8f58201 + 199ac54 commit a43b61b

File tree

3 files changed

+354
-4
lines changed

3 files changed

+354
-4
lines changed

lib/schemaUtils.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2454,9 +2454,6 @@ module.exports = {
24542454
pmBody = this.convertToPmBody(reqBody, REQUEST_TYPE.ROOT, components, options, schemaCache);
24552455
item.request.body = pmBody.body;
24562456

2457-
// Following is added to make sure body pruning for request methods like GET, HEAD etc is disabled'.
2458-
item.protocolProfileBehavior = { disableBodyPruning: true };
2459-
24602457
if (!options.keepImplicitHeaders || (!_.find(reqParams.header, (h) => {
24612458
return _.toLower(_.get(h, 'name')) === 'content-type';
24622459
}))) {
@@ -2568,6 +2565,13 @@ module.exports = {
25682565
if (!_.isEmpty(acceptHeader) && !item.request.headers.has('accept')) {
25692566
item.request.addHeader(acceptHeader);
25702567
}
2568+
2569+
/**
2570+
* Following is added to make sure body pruning for request methods like GET, HEAD etc is disabled'.
2571+
* https://github.com/postmanlabs/postman-runtime/blob/develop/docs/protocol-profile-behavior.md
2572+
*/
2573+
item.protocolProfileBehavior = { disableBodyPruning: true };
2574+
25712575
return item;
25722576
},
25732577

Lines changed: 328 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,328 @@
1+
openapi: "3.0.0"
2+
info:
3+
version: 1.0.0
4+
title: Swagger Petstore
5+
license:
6+
name: MIT
7+
servers:
8+
- url: http://petstore.swagger.io/v1
9+
paths:
10+
/pets:
11+
get:
12+
summary: List all pets
13+
operationId: listPets
14+
tags:
15+
- pets
16+
parameters:
17+
- name: limit
18+
in: query
19+
description: How many items to return at one time (max 100)
20+
required: false
21+
schema:
22+
type: integer
23+
format: int32
24+
requestBody:
25+
content:
26+
application/json:
27+
schema:
28+
$ref: "#/components/schemas/Pets"
29+
responses:
30+
'200':
31+
description: A paged array of pets
32+
headers:
33+
x-next:
34+
description: A link to the next page of responses
35+
schema:
36+
type: string
37+
content:
38+
application/json:
39+
schema:
40+
$ref: "#/components/schemas/Pets"
41+
default:
42+
description: unexpected error
43+
content:
44+
application/json:
45+
schema:
46+
$ref: "#/components/schemas/Error"
47+
post:
48+
summary: List all pets
49+
operationId: listPets
50+
tags:
51+
- pets
52+
parameters:
53+
- name: limit
54+
in: query
55+
description: How many items to return at one time (max 100)
56+
required: false
57+
schema:
58+
type: integer
59+
format: int32
60+
requestBody:
61+
content:
62+
application/json:
63+
schema:
64+
$ref: "#/components/schemas/Pets"
65+
responses:
66+
'200':
67+
description: A paged array of pets
68+
headers:
69+
x-next:
70+
description: A link to the next page of responses
71+
schema:
72+
type: string
73+
content:
74+
application/json:
75+
schema:
76+
$ref: "#/components/schemas/Pets"
77+
default:
78+
description: unexpected error
79+
content:
80+
application/json:
81+
schema:
82+
$ref: "#/components/schemas/Error"
83+
put:
84+
summary: List all pets
85+
operationId: listPets
86+
tags:
87+
- pets
88+
parameters:
89+
- name: limit
90+
in: query
91+
description: How many items to return at one time (max 100)
92+
required: false
93+
schema:
94+
type: integer
95+
format: int32
96+
requestBody:
97+
content:
98+
application/json:
99+
schema:
100+
$ref: "#/components/schemas/Pets"
101+
responses:
102+
'200':
103+
description: A paged array of pets
104+
headers:
105+
x-next:
106+
description: A link to the next page of responses
107+
schema:
108+
type: string
109+
content:
110+
application/json:
111+
schema:
112+
$ref: "#/components/schemas/Pets"
113+
default:
114+
description: unexpected error
115+
content:
116+
application/json:
117+
schema:
118+
$ref: "#/components/schemas/Error"
119+
patch:
120+
summary: List all pets
121+
operationId: listPets
122+
tags:
123+
- pets
124+
parameters:
125+
- name: limit
126+
in: query
127+
description: How many items to return at one time (max 100)
128+
required: false
129+
schema:
130+
type: integer
131+
format: int32
132+
requestBody:
133+
content:
134+
application/json:
135+
schema:
136+
$ref: "#/components/schemas/Pets"
137+
responses:
138+
'200':
139+
description: A paged array of pets
140+
headers:
141+
x-next:
142+
description: A link to the next page of responses
143+
schema:
144+
type: string
145+
content:
146+
application/json:
147+
schema:
148+
$ref: "#/components/schemas/Pets"
149+
default:
150+
description: unexpected error
151+
content:
152+
application/json:
153+
schema:
154+
$ref: "#/components/schemas/Error"
155+
delete:
156+
summary: List all pets
157+
operationId: listPets
158+
tags:
159+
- pets
160+
parameters:
161+
- name: limit
162+
in: query
163+
description: How many items to return at one time (max 100)
164+
required: false
165+
schema:
166+
type: integer
167+
format: int32
168+
requestBody:
169+
content:
170+
application/json:
171+
schema:
172+
$ref: "#/components/schemas/Pets"
173+
responses:
174+
'200':
175+
description: A paged array of pets
176+
headers:
177+
x-next:
178+
description: A link to the next page of responses
179+
schema:
180+
type: string
181+
content:
182+
application/json:
183+
schema:
184+
$ref: "#/components/schemas/Pets"
185+
default:
186+
description: unexpected error
187+
content:
188+
application/json:
189+
schema:
190+
$ref: "#/components/schemas/Error"
191+
head:
192+
summary: List all pets
193+
operationId: listPets
194+
tags:
195+
- pets
196+
parameters:
197+
- name: limit
198+
in: query
199+
description: How many items to return at one time (max 100)
200+
required: false
201+
schema:
202+
type: integer
203+
format: int32
204+
requestBody:
205+
content:
206+
application/json:
207+
schema:
208+
$ref: "#/components/schemas/Pets"
209+
responses:
210+
'200':
211+
description: A paged array of pets
212+
headers:
213+
x-next:
214+
description: A link to the next page of responses
215+
schema:
216+
type: string
217+
content:
218+
application/json:
219+
schema:
220+
$ref: "#/components/schemas/Pets"
221+
default:
222+
description: unexpected error
223+
content:
224+
application/json:
225+
schema:
226+
$ref: "#/components/schemas/Error"
227+
options:
228+
summary: List all pets
229+
operationId: listPets
230+
tags:
231+
- pets
232+
parameters:
233+
- name: limit
234+
in: query
235+
description: How many items to return at one time (max 100)
236+
required: false
237+
schema:
238+
type: integer
239+
format: int32
240+
requestBody:
241+
content:
242+
application/json:
243+
schema:
244+
$ref: "#/components/schemas/Pets"
245+
responses:
246+
'200':
247+
description: A paged array of pets
248+
headers:
249+
x-next:
250+
description: A link to the next page of responses
251+
schema:
252+
type: string
253+
content:
254+
application/json:
255+
schema:
256+
$ref: "#/components/schemas/Pets"
257+
default:
258+
description: unexpected error
259+
content:
260+
application/json:
261+
schema:
262+
$ref: "#/components/schemas/Error"
263+
trace:
264+
summary: List all pets
265+
operationId: listPets
266+
tags:
267+
- pets
268+
parameters:
269+
- name: limit
270+
in: query
271+
description: How many items to return at one time (max 100)
272+
required: false
273+
schema:
274+
type: integer
275+
format: int32
276+
requestBody:
277+
content:
278+
application/json:
279+
schema:
280+
$ref: "#/components/schemas/Pets"
281+
responses:
282+
'200':
283+
description: A paged array of pets
284+
headers:
285+
x-next:
286+
description: A link to the next page of responses
287+
schema:
288+
type: string
289+
content:
290+
application/json:
291+
schema:
292+
$ref: "#/components/schemas/Pets"
293+
default:
294+
description: unexpected error
295+
content:
296+
application/json:
297+
schema:
298+
$ref: "#/components/schemas/Error"
299+
components:
300+
schemas:
301+
Pet:
302+
type: object
303+
required:
304+
- id
305+
- name
306+
properties:
307+
id:
308+
type: integer
309+
format: int64
310+
name:
311+
type: string
312+
tag:
313+
type: string
314+
Pets:
315+
type: array
316+
items:
317+
$ref: "#/components/schemas/Pet"
318+
Error:
319+
type: object
320+
required:
321+
- code
322+
- message
323+
properties:
324+
code:
325+
type: integer
326+
format: int32
327+
message:
328+
type: string

test/unit/base.test.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ describe('CONVERT FUNCTION TESTS ', function() {
5050
issue10229 = path.join(__dirname, VALID_OPENAPI_PATH, '/issue#10229.json'),
5151
deepObjectLengthProperty = path.join(__dirname, VALID_OPENAPI_PATH, '/deepObjectLengthProperty.yaml'),
5252
valuePropInExample = path.join(__dirname, VALID_OPENAPI_PATH, '/valuePropInExample.yaml'),
53-
petstoreParamExample = path.join(__dirname, VALID_OPENAPI_PATH, '/petstoreParamExample.yaml');
53+
petstoreParamExample = path.join(__dirname, VALID_OPENAPI_PATH, '/petstoreParamExample.yaml'),
54+
allHTTPMethodsSpec = path.join(__dirname, VALID_OPENAPI_PATH, '/all-http-methods.yaml');
5455

5556

5657
it('Should add collection level auth with type as `bearer`' +
@@ -1141,6 +1142,23 @@ describe('CONVERT FUNCTION TESTS ', function() {
11411142
done();
11421143
});
11431144
});
1145+
1146+
it('Should have disableBodyPruning option for protocolProfileBehavior set to true for all types of request' +
1147+
allHTTPMethodsSpec, function (done) {
1148+
var openapi = fs.readFileSync(allHTTPMethodsSpec, 'utf8');
1149+
1150+
Converter.convert({ type: 'string', data: openapi },
1151+
{}, (err, conversionResult) => {
1152+
expect(err).to.be.null;
1153+
expect(conversionResult.result).to.equal(true);
1154+
1155+
_.forEach(conversionResult.output[0].data.item[0].item, (request) => {
1156+
expect(request.protocolProfileBehavior.disableBodyPruning).to.eql(true);
1157+
});
1158+
1159+
done();
1160+
});
1161+
});
11441162
});
11451163
describe('Converting swagger 2.0 files', function() {
11461164
it('should convert path paramters to postman-compatible paramters', function (done) {

0 commit comments

Comments
 (0)