Skip to content

Commit c811736

Browse files
authored
Merge pull request #722 from postmanlabs/feature/fix-non-array-required-issue
#708 Fixes issue where if string is defined for required field, conversion was failing.
2 parents c16465b + ccda74f commit c811736

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

assets/json-schema-faker.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24258,7 +24258,7 @@ function extend() {
2425824258

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

2426424264
const propertyKeys = Object.keys(properties);

test/unit/faker.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,22 @@ describe('JSON SCHEMA FAKER TESTS', function () {
136136
expect(fakedData.length >= 2).to.be.true;
137137
expect(fakedData.length <= 63).to.be.true;
138138
});
139+
140+
it('Should successsfully generate data iff required is defined as string', function () {
141+
const schema = {
142+
type: 'object',
143+
required: 'timebase',
144+
properties: {
145+
timebase: { type: 'string' },
146+
linkid: { type: 'string' },
147+
chartRef: { type: 'string' }
148+
}
149+
};
150+
151+
var fakedData = schemaFaker(schema);
152+
expect(fakedData).to.be.an('object');
153+
expect(fakedData.timebase).to.be.a('string');
154+
expect(fakedData.linkid).to.be.a('string');
155+
expect(fakedData.chartRef).to.be.a('string');
156+
});
139157
});

0 commit comments

Comments
 (0)