@@ -23468,7 +23468,12 @@ function extend() {
23468
23468
var context = {};
23469
23469
while (length--) {
23470
23470
var fn = keys[length].replace(/^x-/, '');
23471
- var gen = this.support[fn];
23471
+
23472
+ /**
23473
+ * CHANGE: This Makes sure that we're not using Object's prototype properties,
23474
+ * while accessing certain keys like 'constructor'
23475
+ */
23476
+ var gen = this.support.hasOwnProperty(fn) && this.support[fn];
23472
23477
if (typeof gen === 'function') {
23473
23478
if (typeof schema[fn] === 'object' && schema[fn].hasOwnProperty('type')) {
23474
23479
continue;
@@ -23814,6 +23819,14 @@ function extend() {
23814
23819
}
23815
23820
// execute generator
23816
23821
var value = callback(params);
23822
+
23823
+ /**
23824
+ * CHANGE: This Makes sure that we're not typecasting null to "null"
23825
+ */
23826
+ if (_.get(schema, 'nullable') && value === null) {
23827
+ return value;
23828
+ }
23829
+
23817
23830
// normalize output value
23818
23831
switch (schema.type) {
23819
23832
case 'number':
@@ -23830,7 +23843,11 @@ function extend() {
23830
23843
var min = Math.max(params.minLength || 0, 0);
23831
23844
var max = Math.min(params.maxLength || Infinity, Infinity);
23832
23845
while (value.length < min) {
23833
- value += ' ' + value;
23846
+ /**
23847
+ * CHANGE: This Makes sure that we're not adding extra spaces in generated value,
23848
+ * As such behaviour generates invalid data when pattern is mentioned.
23849
+ */
23850
+ value += (schema.pattern ? '' : ' ') + value;
23834
23851
}
23835
23852
if (value.length > max) {
23836
23853
value = value.substr(0, max);
@@ -24236,24 +24253,24 @@ function extend() {
24236
24253
// Updated objectType definition to latest version (0.5.0-rcv.41)
24237
24254
var objectType = function objectType(value, path, resolve, traverseCallback, seenSchemaCache) {
24238
24255
const props = {};
24239
-
24256
+
24240
24257
const properties = value.properties || {};
24241
24258
const patternProperties = value.patternProperties || {};
24242
24259
const requiredProperties = typeof value.required === 'boolean' ? [] : (value.required || []).slice();
24243
24260
const allowsAdditional = value.additionalProperties !== false;
24244
-
24261
+
24245
24262
const propertyKeys = Object.keys(properties);
24246
24263
const patternPropertyKeys = Object.keys(patternProperties);
24247
24264
const optionalProperties = propertyKeys.concat(patternPropertyKeys).reduce((_response, _key) => {
24248
24265
if (requiredProperties.indexOf(_key) === -1) _response.push(_key);
24249
24266
return _response;
24250
24267
}, []);
24251
24268
const allProperties = requiredProperties.concat(optionalProperties);
24252
-
24269
+
24253
24270
const additionalProperties = allowsAdditional // eslint-disable-line
24254
24271
? (value.additionalProperties === true ? anyType : value.additionalProperties)
24255
24272
: value.additionalProperties;
24256
-
24273
+
24257
24274
if (!allowsAdditional
24258
24275
&& propertyKeys.length === 0
24259
24276
&& patternPropertyKeys.length === 0
@@ -24262,50 +24279,50 @@ function extend() {
24262
24279
// just nothing
24263
24280
return null;
24264
24281
}
24265
-
24282
+
24266
24283
if (optionAPI('requiredOnly') === true) {
24267
24284
requiredProperties.forEach(key => {
24268
24285
if (properties[key]) {
24269
24286
props[key] = properties[key];
24270
24287
}
24271
24288
});
24272
-
24289
+
24273
24290
return traverseCallback(props, path.concat(['properties']), resolve, value, seenSchemaCache);
24274
24291
}
24275
-
24292
+
24276
24293
const optionalsProbability = optionAPI('alwaysFakeOptionals') === true ? 1.0 : optionAPI('optionalsProbability');
24277
24294
const fixedProbabilities = optionAPI('alwaysFakeOptionals') || optionAPI('fixedProbabilities') || false;
24278
24295
const ignoreProperties = optionAPI('ignoreProperties') || [];
24279
24296
const reuseProps = optionAPI('reuseProperties');
24280
24297
const fillProps = optionAPI('fillProperties');
24281
-
24298
+
24282
24299
const max = value.maxProperties || (allProperties.length + (allowsAdditional ? random.number(1, 5) : 0));
24283
-
24300
+
24284
24301
let min = Math.max(value.minProperties || 0, requiredProperties.length);
24285
24302
let neededExtras = Math.max(0, allProperties.length - min);
24286
-
24303
+
24287
24304
if (optionalsProbability !== null) {
24288
24305
if (fixedProbabilities === true) {
24289
24306
neededExtras = Math.round((min - requiredProperties.length) + (optionalsProbability * (allProperties.length - min)));
24290
24307
} else {
24291
24308
neededExtras = random.number(min - requiredProperties.length, optionalsProbability * (allProperties.length - min));
24292
24309
}
24293
24310
}
24294
-
24311
+
24295
24312
const extraPropertiesRandomOrder = random.shuffle(optionalProperties).slice(0, neededExtras);
24296
24313
const extraProperties = optionalProperties.filter(_item => {
24297
24314
return extraPropertiesRandomOrder.indexOf(_item) !== -1;
24298
24315
});
24299
-
24316
+
24300
24317
// properties are read from right-to-left
24301
24318
const _limit = optionalsProbability !== null || requiredProperties.length === max ? max : random.number(0, max);
24302
24319
const _props = requiredProperties.concat(extraProperties).slice(0, max);
24303
24320
const _defns = [];
24304
-
24321
+
24305
24322
if (value.dependencies) {
24306
24323
Object.keys(value.dependencies).forEach(prop => {
24307
24324
const _required = value.dependencies[prop];
24308
-
24325
+
24309
24326
if (_props.indexOf(prop) !== -1) {
24310
24327
if (Array.isArray(_required)) {
24311
24328
// property-dependencies
@@ -24319,20 +24336,20 @@ function extend() {
24319
24336
}
24320
24337
}
24321
24338
});
24322
-
24339
+
24323
24340
// schema-dependencies
24324
24341
if (_defns.length) {
24325
24342
delete value.dependencies;
24326
-
24343
+
24327
24344
return traverseCallback({
24328
24345
allOf: _defns.concat(value),
24329
24346
}, path.concat(['properties']), resolve, value, seenSchemaCache);
24330
24347
}
24331
24348
}
24332
-
24349
+
24333
24350
const skipped = [];
24334
24351
const missing = [];
24335
-
24352
+
24336
24353
_props.forEach(key => {
24337
24354
for (let i = 0; i < ignoreProperties.length; i += 1) {
24338
24355
if ((ignoreProperties[i] instanceof RegExp && ignoreProperties[i].test(key))
@@ -24342,38 +24359,38 @@ function extend() {
24342
24359
return;
24343
24360
}
24344
24361
}
24345
-
24362
+
24346
24363
if (additionalProperties === false) {
24347
24364
if (requiredProperties.indexOf(key) !== -1) {
24348
24365
props[key] = properties[key];
24349
24366
}
24350
24367
}
24351
-
24368
+
24352
24369
if (properties[key]) {
24353
24370
props[key] = properties[key];
24354
24371
}
24355
-
24372
+
24356
24373
let found;
24357
-
24374
+
24358
24375
// then try patternProperties
24359
24376
patternPropertyKeys.forEach(_key => {
24360
24377
if (key.match(new RegExp(_key))) {
24361
24378
found = true;
24362
-
24379
+
24363
24380
if (props[key]) {
24364
24381
utils.merge(props[key], patternProperties[_key]);
24365
24382
} else {
24366
24383
props[random.randexp(key)] = patternProperties[_key];
24367
24384
}
24368
24385
}
24369
24386
});
24370
-
24387
+
24371
24388
if (!found) {
24372
24389
// try patternProperties again,
24373
24390
const subschema = patternProperties[key] || additionalProperties;
24374
-
24391
+
24375
24392
// FIXME: allow anyType as fallback when no subschema is given?
24376
-
24393
+
24377
24394
if (subschema && additionalProperties !== false) {
24378
24395
// otherwise we can use additionalProperties?
24379
24396
props[patternProperties[key] ? random.randexp(key) : key] = properties[key] || subschema;
@@ -24382,103 +24399,103 @@ function extend() {
24382
24399
}
24383
24400
}
24384
24401
});
24385
-
24402
+
24386
24403
// discard already ignored props if they're not required to be filled...
24387
24404
let current = Object.keys(props).length + (fillProps ? 0 : skipped.length);
24388
-
24405
+
24389
24406
// generate dynamic suffix for additional props...
24390
24407
const hash = suffix => random.randexp(`_?[_a-f\\d]{1,3}${suffix ? '\\$?' : ''}`);
24391
-
24408
+
24392
24409
function get(from) {
24393
24410
let one;
24394
-
24411
+
24395
24412
do {
24396
24413
if (!from.length) break;
24397
24414
one = from.shift();
24398
24415
} while (props[one]);
24399
-
24416
+
24400
24417
return one;
24401
24418
}
24402
-
24419
+
24403
24420
let minProps = min;
24404
24421
if (allowsAdditional && !requiredProperties.length) {
24405
24422
minProps = Math.max(optionalsProbability === null || additionalProperties ? random.number(fillProps ? 1 : 0, max) : 0, min);
24406
24423
}
24407
-
24424
+
24408
24425
while (fillProps) {
24409
24426
if (!(patternPropertyKeys.length || allowsAdditional)) {
24410
24427
break;
24411
24428
}
24412
-
24429
+
24413
24430
if (current >= minProps) {
24414
24431
break;
24415
24432
}
24416
-
24433
+
24417
24434
if (allowsAdditional) {
24418
24435
if (reuseProps && ((propertyKeys.length - current) > minProps)) {
24419
24436
let count = 0;
24420
24437
let key;
24421
-
24438
+
24422
24439
do {
24423
24440
count += 1;
24424
-
24441
+
24425
24442
// skip large objects
24426
24443
if (count > 1000) {
24427
24444
break;
24428
24445
}
24429
-
24446
+
24430
24447
key = get(requiredProperties) || random.pick(propertyKeys);
24431
24448
} while (typeof props[key] !== 'undefined');
24432
-
24449
+
24433
24450
if (typeof props[key] === 'undefined') {
24434
24451
props[key] = properties[key];
24435
24452
current += 1;
24436
24453
}
24437
24454
} else if (patternPropertyKeys.length && !additionalProperties) {
24438
24455
const prop = random.pick(patternPropertyKeys);
24439
24456
const word = random.randexp(prop);
24440
-
24457
+
24441
24458
if (!props[word]) {
24442
24459
props[word] = patternProperties[prop];
24443
24460
current += 1;
24444
24461
}
24445
24462
} else {
24446
24463
const word = get(requiredProperties) || (wordsGenerator(1) + hash());
24447
-
24464
+
24448
24465
if (!props[word]) {
24449
24466
props[word] = additionalProperties || anyType;
24450
24467
current += 1;
24451
24468
}
24452
24469
}
24453
24470
}
24454
-
24471
+
24455
24472
for (let i = 0; current < min && i < patternPropertyKeys.length; i += 1) {
24456
24473
const _key = patternPropertyKeys[i];
24457
24474
const word = random.randexp(_key);
24458
-
24459
-
24475
+
24476
+
24460
24477
if (!props[word]) {
24461
24478
props[word] = patternProperties[_key];
24462
24479
current += 1;
24463
24480
}
24464
24481
}
24465
24482
}
24466
-
24483
+
24467
24484
// fill up-to this value and no more!
24468
24485
if (requiredProperties.length === 0 && (!allowsAdditional || optionalsProbability === false)) {
24469
24486
const maximum = random.number(min, max);
24470
-
24487
+
24471
24488
for (; current < maximum;) {
24472
24489
const word = get(propertyKeys);
24473
-
24490
+
24474
24491
if (word) {
24475
24492
props[word] = properties[word];
24476
24493
}
24477
-
24494
+
24478
24495
current += 1;
24479
24496
}
24480
24497
}
24481
-
24498
+
24482
24499
return traverseCallback(props, path.concat(['properties']), resolve, value, seenSchemaCache);
24483
24500
};
24484
24501
@@ -24571,7 +24588,11 @@ function extend() {
24571
24588
24572
24589
// types from draft-0[67] (?)
24573
24590
'uri-reference': `${URI_PATTERN}${PARAM_PATTERN}`,
24574
- 'uri-template': URI_PATTERN.replace('(?:', '(?:/\\{[a-z][:a-zA-Z0-9-]*\\}|'),
24591
+ /**
24592
+ * CHANGE: Corrected uri-template format to be inline with RFC-6570
24593
+ * https://www.rfc-editor.org/rfc/rfc6570#section-2
24594
+ */
24595
+ 'uri-template': URI_PATTERN.replace('(?:', '(?:/\\{[a-z][a-zA-Z0-9]*\\}|'),
24575
24596
'json-pointer': `(/(?:${FRAGMENT.replace(']*', '/]*')}|~[01]))+`,
24576
24597
24577
24598
// some types from https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.1.md#data-types (?)
0 commit comments