mirror of
https://github.com/postmanlabs/openapi-to-postman.git
synced 2022-11-29 22:05:00 +03:00
Merge pull request #413 from postmanlabs/issue/379
Set param type in request to `file` if schema type is `string` and format is `binary`
This commit is contained in:
@@ -337,7 +337,7 @@ module.exports = {
|
|||||||
|
|
||||||
// Discard format if not supported by both json-schema-faker and ajv or pattern is also defined
|
// 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)) {
|
if (!_.includes(SUPPORTED_FORMATS, schema.format) || (schema.pattern && schema.format)) {
|
||||||
delete schema.format;
|
return _.omit(schema, 'format');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1701,6 +1701,7 @@ module.exports = {
|
|||||||
var contentObj, // content is required
|
var contentObj, // content is required
|
||||||
bodyData,
|
bodyData,
|
||||||
param,
|
param,
|
||||||
|
originalParam,
|
||||||
paramArray = [],
|
paramArray = [],
|
||||||
updateOptions = {},
|
updateOptions = {},
|
||||||
reqBody = new sdk.RequestBody(),
|
reqBody = new sdk.RequestBody(),
|
||||||
@@ -1832,11 +1833,27 @@ module.exports = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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: '',
|
||||||
|
type: 'file'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
param = new sdk.FormParam({
|
param = new sdk.FormParam({
|
||||||
key: key,
|
key: key,
|
||||||
value: value,
|
value: value,
|
||||||
type: 'text'
|
type: 'text'
|
||||||
});
|
});
|
||||||
|
}
|
||||||
param.description = description;
|
param.description = description;
|
||||||
paramArray.push(param);
|
paramArray.push(param);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -93,13 +93,15 @@ describe('DEREF FUNCTION TESTS ', function() {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
parameterSource = 'REQUEST',
|
parameterSource = 'REQUEST',
|
||||||
output = deref.resolveRefs(schema, parameterSource, componentsAndPaths),
|
// deref.resolveRefs modifies the input schema and components so cloning to keep tests independent of each other
|
||||||
output_withdot = deref.resolveRefs(schemaWithDotInKey, parameterSource, componentsAndPaths),
|
output = deref.resolveRefs(schema, parameterSource, _.cloneDeep(componentsAndPaths)),
|
||||||
output_customFormat = deref.resolveRefs(schemaWithCustomFormat, parameterSource, componentsAndPaths),
|
output_withdot = deref.resolveRefs(schemaWithDotInKey, parameterSource, _.cloneDeep(componentsAndPaths)),
|
||||||
output_withAllOf = deref.resolveRefs(schemaWithAllOf, parameterSource, componentsAndPaths),
|
output_customFormat = deref.resolveRefs(schemaWithCustomFormat, parameterSource,
|
||||||
output_validationTypeArray = deref.resolveRefs(schemaWithTypeArray, parameterSource, componentsAndPaths,
|
_.cloneDeep(componentsAndPaths)),
|
||||||
{}, 'VALIDATION'),
|
output_withAllOf = deref.resolveRefs(schemaWithAllOf, parameterSource, _.cloneDeep(componentsAndPaths)),
|
||||||
output_emptyObject = deref.resolveRefs(schemaWithEmptyObject, parameterSource, componentsAndPaths);
|
output_validationTypeArray = deref.resolveRefs(schemaWithTypeArray, parameterSource,
|
||||||
|
_.cloneDeep(componentsAndPaths), {}, 'VALIDATION'),
|
||||||
|
output_emptyObject = deref.resolveRefs(schemaWithEmptyObject, parameterSource, _.cloneDeep(componentsAndPaths));
|
||||||
|
|
||||||
expect(output).to.deep.include({ type: 'object',
|
expect(output).to.deep.include({ type: 'object',
|
||||||
required: ['id'],
|
required: ['id'],
|
||||||
@@ -302,6 +304,8 @@ describe('DEREF FUNCTION TESTS ', function() {
|
|||||||
expect(_.get(schemaResoltionCache, ['#/components/schemas/schemaUsed', 'schema'])).to.not.deep
|
expect(_.get(schemaResoltionCache, ['#/components/schemas/schemaUsed', 'schema'])).to.not.deep
|
||||||
.equal(componentsAndPaths.components.schemas.schemaUsed);
|
.equal(componentsAndPaths.components.schemas.schemaUsed);
|
||||||
resolvedSchema = deref.resolveRefs(schema, parameterSource, componentsAndPaths, schemaResoltionCache);
|
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
|
* Even though schema cache contains schemaUsed as impartially cached,resolution were it's used again will
|
||||||
|
|||||||
@@ -1777,14 +1777,18 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () {
|
|||||||
schema: {
|
schema: {
|
||||||
type: 'object',
|
type: 'object',
|
||||||
properties: {
|
properties: {
|
||||||
file: {
|
array: {
|
||||||
type: 'array',
|
type: 'array',
|
||||||
items: {
|
items: {
|
||||||
type: 'string'
|
type: 'string'
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
file: {
|
||||||
|
type: 'string',
|
||||||
|
format: 'binary'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
required: ['file']
|
required: ['array']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1792,7 +1796,9 @@ describe('SCHEMA UTILITY FUNCTION TESTS ', function () {
|
|||||||
result, resultBody;
|
result, resultBody;
|
||||||
result = SchemaUtils.convertToPmBody(requestBody);
|
result = SchemaUtils.convertToPmBody(requestBody);
|
||||||
resultBody = (result.body.formdata.toJSON());
|
resultBody = (result.body.formdata.toJSON());
|
||||||
expect(resultBody[0].key).to.equal('file');
|
expect(resultBody[0].key).to.equal('array');
|
||||||
|
expect(resultBody[1].key).to.equal('file');
|
||||||
|
expect(resultBody[1].type).to.equal('file');
|
||||||
expect(result.contentHeader).to.deep.include(
|
expect(result.contentHeader).to.deep.include(
|
||||||
{ key: 'Content-Type', value: 'multipart/form-data' });
|
{ key: 'Content-Type', value: 'multipart/form-data' });
|
||||||
done();
|
done();
|
||||||
|
|||||||
Reference in New Issue
Block a user