Check for type and format in the original param instead of checking for value after processing

This commit is contained in:
Ankit Saini
2021-10-04 19:31:55 +05:30
parent 98f985612b
commit 2f7e214037
3 changed files with 13 additions and 4 deletions

View File

@@ -337,7 +337,7 @@ module.exports = {
// Discard format if not supported by both json-schema-faker and ajv or pattern is also defined
if (!_.includes(SUPPORTED_FORMATS, schema.format) || (schema.pattern && schema.format)) {
delete schema.format;
return _.omit(schema, 'format');
}
}

View File

@@ -1701,6 +1701,7 @@ module.exports = {
var contentObj, // content is required
bodyData,
param,
originalParam,
paramArray = [],
updateOptions = {},
reqBody = new sdk.RequestBody(),
@@ -1832,8 +1833,14 @@ module.exports = {
}
}
// Set param type to 'file' for binary value
if (value === '<binary>') {
// Fetch the original param and if it is of type 'string' and format 'binary'
// then set the type of FormParam to 'file'
originalParam = _.get(contentObj[FORM_DATA], ['schema', 'properties', key]);
if (originalParam &&
originalParam.type === 'string' &&
originalParam.format === 'binary'
) {
param = new sdk.FormParam({
key: key,
value: '',

View File

@@ -116,7 +116,7 @@ describe('DEREF FUNCTION TESTS ', function() {
type: 'object',
description: 'Schema 2',
properties: {
id: { default: '<long>', type: 'integer' },
id: { default: '<long>', type: 'integer', format: 'int64' },
test_prop: { default: '<string>', type: 'string' }
}
});
@@ -302,6 +302,8 @@ describe('DEREF FUNCTION TESTS ', function() {
expect(_.get(schemaResoltionCache, ['#/components/schemas/schemaUsed', 'schema'])).to.not.deep
.equal(componentsAndPaths.components.schemas.schemaUsed);
resolvedSchema = deref.resolveRefs(schema, parameterSource, componentsAndPaths, schemaResoltionCache);
// Restoring the original format as it is deleted if not supported by json-schema-faker and ajv
resolvedSchema.properties.id.format = 'int64';
/**
* Even though schema cache contains schemaUsed as impartially cached,resolution were it's used again will