Skip to content

Commit

Permalink
Merge pull request #722 from postmanlabs/feature/fix-non-array-requir…
Browse files Browse the repository at this point in the history
…ed-issue

#708 Fixes issue where if string is defined for required field, conversion was failing.
  • Loading branch information
VShingala committed May 15, 2023
2 parents c16465b + ccda74f commit c811736
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion assets/json-schema-faker.js
Original file line number Diff line number Diff line change
Expand Up @@ -24258,7 +24258,7 @@ function extend() {

const properties = value.properties || {};
const patternProperties = value.patternProperties || {};
const requiredProperties = typeof value.required === 'boolean' ? [] : (value.required || []).slice();
const requiredProperties = (!Array.isArray(value.required)) ? [] : (value.required || []).slice();
const allowsAdditional = value.additionalProperties !== false;

const propertyKeys = Object.keys(properties);
Expand Down
18 changes: 18 additions & 0 deletions test/unit/faker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,22 @@ describe('JSON SCHEMA FAKER TESTS', function () {
expect(fakedData.length >= 2).to.be.true;
expect(fakedData.length <= 63).to.be.true;
});

it('Should successsfully generate data iff required is defined as string', function () {
const schema = {
type: 'object',
required: 'timebase',
properties: {
timebase: { type: 'string' },
linkid: { type: 'string' },
chartRef: { type: 'string' }
}
};

var fakedData = schemaFaker(schema);
expect(fakedData).to.be.an('object');
expect(fakedData.timebase).to.be.a('string');
expect(fakedData.linkid).to.be.a('string');
expect(fakedData.chartRef).to.be.a('string');
});
});

0 comments on commit c811736

Please sign in to comment.