Skip to content

Commit

Permalink
Added support for file type filed for form-data body
Browse files Browse the repository at this point in the history
  • Loading branch information
VShingala committed Jul 18, 2024
1 parent c753ff0 commit 5a8a889
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 12 deletions.
11 changes: 2 additions & 9 deletions libV2/schemaUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const schemaFaker = require('../assets/json-schema-faker'),
'ipv4', 'ipv6',
'regex',
'uuid',
'binary',
'json-pointer',
'int64',
'float',
Expand Down Expand Up @@ -576,15 +577,9 @@ let QUERYPARAM = 'query',
return;
}

// Set type to binary
if (property.format === 'binary') {
property.type = 'binary';
}

if (
property.format === 'decimal' ||
property.format === 'byte' ||
property.format === 'binary' ||
property.format === 'password' ||
property.format === 'unix-time'
) {
Expand Down Expand Up @@ -848,7 +843,6 @@ let QUERYPARAM = 'query',
for (const prop in resolvedSchema.properties) {
if (resolvedSchema.properties.hasOwnProperty(prop)) {
if (
resolvedSchema.properties[prop].format === 'binary' ||
resolvedSchema.properties[prop].format === 'byte' ||
resolvedSchema.properties[prop].format === 'decimal'
) {
Expand Down Expand Up @@ -1363,7 +1357,6 @@ let QUERYPARAM = 'query',
}

if (
requestBodySchema.properties[prop].format === 'binary' ||
requestBodySchema.properties[prop].format === 'byte' ||
requestBodySchema.properties[prop].format === 'decimal'
) {
Expand Down Expand Up @@ -1523,7 +1516,7 @@ let QUERYPARAM = 'query',

// TODO: Add handling for headers from encoding

if (paramSchema && paramSchema.type === 'binary') {
if (paramSchema && paramSchema.type === 'string' && paramSchema.format === 'binary') {
param = {
key,
value: '',
Expand Down
3 changes: 2 additions & 1 deletion libV2/validationUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ schemaFaker.option({
maxItems: 20, // limit on maximum number of items faked for (type: array)
useDefaultValue: true,
ignoreMissingRefs: true,
avoidExampleItemsLength: true // option to avoid validating type array schema example's minItems and maxItems props.
avoidExampleItemsLength: true, // option to avoid validating type array schema example's minItems and maxItems props.
failOnInvalidFormat: false
});

/**
Expand Down
6 changes: 4 additions & 2 deletions test/unit/faker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ describe('JSON SCHEMA FAKER TESTS', function () {
useDefaultValue: true,
useExamplesValue: true,
ignoreMissingRefs: true,
avoidExampleItemsLength: false
avoidExampleItemsLength: false,
failOnInvalidFormat: false
});
});

Expand All @@ -27,7 +28,8 @@ describe('JSON SCHEMA FAKER TESTS', function () {
maxItems: 20,
useDefaultValue: true,
ignoreMissingRefs: true,
avoidExampleItemsLength: true
avoidExampleItemsLength: true,
failOnInvalidFormat: false
});
});

Expand Down

0 comments on commit 5a8a889

Please sign in to comment.