Skip to content

Commit 717dbb0

Browse files
committed
preferredRequestBodyType option- Set default to 'first-listed" and remove fallback
1 parent 04a4527 commit 717dbb0

File tree

3 files changed

+7
-20
lines changed

3 files changed

+7
-20
lines changed

libV2/schemaUtils.js

+2-15
Original file line numberDiff line numberDiff line change
@@ -1646,7 +1646,7 @@ let QUERYPARAM = 'query',
16461646
rawModeRequestBody;
16471647

16481648
const { preferredRequestBodyType: optionRequestBodyType } = context.computedOptions,
1649-
preferredRequestBodyType = optionRequestBodyType || 'x-www-form-urlencoded';
1649+
preferredRequestBodyType = optionRequestBodyType || 'first-listed';
16501650

16511651
if (!requestBody) {
16521652
return requestBody;
@@ -1694,22 +1694,9 @@ let QUERYPARAM = 'query',
16941694
else if (preferredRequestBodyType === 'form-data' && formDataRequestBody) {
16951695
return formDataRequestBody;
16961696
}
1697-
else if (preferredRequestBodyType === 'raw' && rawModeRequestBody) {
1698-
return rawModeRequestBody;
1699-
}
17001697
}
17011698

1702-
// Legacy fallback
1703-
// If preferredRequestBodyType is not provided, return the first available request body
1704-
if (encodedRequestBody) {
1705-
return encodedRequestBody;
1706-
}
1707-
else if (formDataRequestBody) {
1708-
return formDataRequestBody;
1709-
}
1710-
else {
1711-
return rawModeRequestBody;
1712-
}
1699+
return rawModeRequestBody;
17131700
},
17141701

17151702
resolvePathItemParams = (context, operationParam, pathParam) => {

test/system/structure.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ const optionIds = [
241241
description: 'When there are multiple content-types defined in the request body of OpenAPI, the conversion ' +
242242
'selects the preferred option content-type as request body.If "first-listed" is set, the first ' +
243243
'content-type defined in the OpenAPI spec will be selected.',
244-
external: true,
244+
external: false,
245245
usage: ['CONVERSION']
246246
}
247247
};

test/unit/schemaUtilsV2.test.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const {
8686

8787
describe('resolveRequestBodyForPostmanRequest function', function () {
8888

89-
it('should return encoded request body when preferredRequestBodyType is not set', function () {
89+
it('should return first-listed request body when preferredRequestBodyType is not set', function () {
9090
const contextTest = {
9191
concreteUtils,
9292
schemaCache: {},
@@ -98,10 +98,10 @@ describe('resolveRequestBodyForPostmanRequest function', function () {
9898
operationItemTest = operationItem.put,
9999
result = resolveRequestBodyForPostmanRequest(contextTest, operationItemTest);
100100

101-
expect(result.body.mode).to.equal('urlencoded');
101+
expect(result.body.mode).to.equal('raw');
102102
});
103103

104-
it('should return encoded request body as fallback when preferredRequestBodyType is not a valid option', function () {
104+
it('should return first-listed request body when preferredRequestBodyType is not a valid option', function () {
105105
const contextTest = {
106106
concreteUtils,
107107
schemaCache: {},
@@ -114,7 +114,7 @@ describe('resolveRequestBodyForPostmanRequest function', function () {
114114
operationItemTest = operationItem.put,
115115
result = resolveRequestBodyForPostmanRequest(contextTest, operationItemTest);
116116

117-
expect(result.body.mode).to.equal('urlencoded');
117+
expect(result.body.mode).to.equal('raw');
118118
});
119119

120120
it('should return encoded request body when preferredRequestBodyType is x-www-form-urlencoded', function () {

0 commit comments

Comments
 (0)