Merge pull request #412 from postmanlabs/issue/382

Handle the case when request body is of type `string` and format `binary`
This commit is contained in:
Vishal Shingala
2021-10-05 11:39:11 +05:30
committed by GitHub
3 changed files with 38 additions and 7 deletions

View File

@@ -134,7 +134,8 @@
"raw",
"urlencoded",
"formdata",
"graphql"
"graphql",
"file"
]
},
"raw": {

View File

@@ -1873,6 +1873,17 @@ module.exports = {
}
}
if (
bodyType &&
!_.isEmpty(_.get(contentObj, [bodyType, 'schema'])) &&
contentObj[bodyType].schema.type === 'string' &&
contentObj[bodyType].schema.format === 'binary'
) {
updateOptions = {
mode: 'file'
};
}
else {
bodyData = this.convertToPmBodyData(contentObj[bodyType], requestType, bodyType,
PARAMETER_SOURCE.REQUEST, options.indentCharacter, components, options, schemaCache);
@@ -1880,6 +1891,7 @@ module.exports = {
mode: rDataMode,
raw: JSON.stringify(bodyData, null, 4)
};
}
contentHeader = new sdk.Header({
key: 'Content-Type',

View File

@@ -1692,6 +1692,24 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () {
{ key: 'Content-Type', value: 'application/javascript' });
done();
});
it(' image/*', function (done) {
var requestBody = {
description: 'body description',
content: {
'image/*': {
schema: {
type: 'string',
format: 'binary'
}
}
}
},
result;
result = SchemaUtils.convertToPmBody(requestBody);
expect(result.body.mode).to.equal('file');
done();
});
// things remaining : application/xml
});
});