@pactflow/openapi-pact-comparator 1.6.1 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -883,6 +883,18 @@ function overRest(func, start, transform) {
883
883
  };
884
884
  }
885
885
 
886
+ /**
887
+ * The base implementation of `_.rest` which doesn't validate or coerce arguments.
888
+ *
889
+ * @private
890
+ * @param {Function} func The function to apply a rest parameter to.
891
+ * @param {number} [start=func.length-1] The start position of the rest parameter.
892
+ * @returns {Function} Returns the new function.
893
+ */
894
+ function baseRest(func, start) {
895
+ return setToString(overRest(func, start, identity), func + '');
896
+ }
897
+
886
898
  /** Used as references for various `Number` constants. */
887
899
  var MAX_SAFE_INTEGER = 9007199254740991;
888
900
 
@@ -946,6 +958,63 @@ function isArrayLike(value) {
946
958
  return value != null && isLength(value.length) && !isFunction(value);
947
959
  }
948
960
 
961
+ /**
962
+ * Checks if the given arguments are from an iteratee call.
963
+ *
964
+ * @private
965
+ * @param {*} value The potential iteratee value argument.
966
+ * @param {*} index The potential iteratee index or key argument.
967
+ * @param {*} object The potential iteratee object argument.
968
+ * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
969
+ * else `false`.
970
+ */
971
+ function isIterateeCall(value, index, object) {
972
+ if (!isObject(object)) {
973
+ return false;
974
+ }
975
+ var type = typeof index;
976
+ if (type == 'number'
977
+ ? (isArrayLike(object) && isIndex(index, object.length))
978
+ : (type == 'string' && index in object)
979
+ ) {
980
+ return eq(object[index], value);
981
+ }
982
+ return false;
983
+ }
984
+
985
+ /**
986
+ * Creates a function like `_.assign`.
987
+ *
988
+ * @private
989
+ * @param {Function} assigner The function to assign values.
990
+ * @returns {Function} Returns the new assigner function.
991
+ */
992
+ function createAssigner(assigner) {
993
+ return baseRest(function(object, sources) {
994
+ var index = -1,
995
+ length = sources.length,
996
+ customizer = length > 1 ? sources[length - 1] : undefined,
997
+ guard = length > 2 ? sources[2] : undefined;
998
+
999
+ customizer = (assigner.length > 3 && typeof customizer == 'function')
1000
+ ? (length--, customizer)
1001
+ : undefined;
1002
+
1003
+ if (guard && isIterateeCall(sources[0], sources[1], guard)) {
1004
+ customizer = length < 3 ? undefined : customizer;
1005
+ length = 1;
1006
+ }
1007
+ object = Object(object);
1008
+ while (++index < length) {
1009
+ var source = sources[index];
1010
+ if (source) {
1011
+ assigner(object, source, index, customizer);
1012
+ }
1013
+ }
1014
+ return object;
1015
+ });
1016
+ }
1017
+
949
1018
  /** Used for built-in method references. */
950
1019
  var objectProto$9 = Object.prototype;
951
1020
 
@@ -3177,6 +3246,209 @@ function createBaseEach(eachFunc, fromRight) {
3177
3246
  */
3178
3247
  var baseEach = createBaseEach(baseForOwn);
3179
3248
 
3249
+ /**
3250
+ * This function is like `assignValue` except that it doesn't assign
3251
+ * `undefined` values.
3252
+ *
3253
+ * @private
3254
+ * @param {Object} object The object to modify.
3255
+ * @param {string} key The key of the property to assign.
3256
+ * @param {*} value The value to assign.
3257
+ */
3258
+ function assignMergeValue(object, key, value) {
3259
+ if ((value !== undefined && !eq(object[key], value)) ||
3260
+ (value === undefined && !(key in object))) {
3261
+ baseAssignValue(object, key, value);
3262
+ }
3263
+ }
3264
+
3265
+ /**
3266
+ * This method is like `_.isArrayLike` except that it also checks if `value`
3267
+ * is an object.
3268
+ *
3269
+ * @static
3270
+ * @memberOf _
3271
+ * @since 4.0.0
3272
+ * @category Lang
3273
+ * @param {*} value The value to check.
3274
+ * @returns {boolean} Returns `true` if `value` is an array-like object,
3275
+ * else `false`.
3276
+ * @example
3277
+ *
3278
+ * _.isArrayLikeObject([1, 2, 3]);
3279
+ * // => true
3280
+ *
3281
+ * _.isArrayLikeObject(document.body.children);
3282
+ * // => true
3283
+ *
3284
+ * _.isArrayLikeObject('abc');
3285
+ * // => false
3286
+ *
3287
+ * _.isArrayLikeObject(_.noop);
3288
+ * // => false
3289
+ */
3290
+ function isArrayLikeObject(value) {
3291
+ return isObjectLike(value) && isArrayLike(value);
3292
+ }
3293
+
3294
+ /**
3295
+ * Gets the value at `key`, unless `key` is "__proto__" or "constructor".
3296
+ *
3297
+ * @private
3298
+ * @param {Object} object The object to query.
3299
+ * @param {string} key The key of the property to get.
3300
+ * @returns {*} Returns the property value.
3301
+ */
3302
+ function safeGet(object, key) {
3303
+ if (key === 'constructor' && typeof object[key] === 'function') {
3304
+ return;
3305
+ }
3306
+
3307
+ if (key == '__proto__') {
3308
+ return;
3309
+ }
3310
+
3311
+ return object[key];
3312
+ }
3313
+
3314
+ /**
3315
+ * Converts `value` to a plain object flattening inherited enumerable string
3316
+ * keyed properties of `value` to own properties of the plain object.
3317
+ *
3318
+ * @static
3319
+ * @memberOf _
3320
+ * @since 3.0.0
3321
+ * @category Lang
3322
+ * @param {*} value The value to convert.
3323
+ * @returns {Object} Returns the converted plain object.
3324
+ * @example
3325
+ *
3326
+ * function Foo() {
3327
+ * this.b = 2;
3328
+ * }
3329
+ *
3330
+ * Foo.prototype.c = 3;
3331
+ *
3332
+ * _.assign({ 'a': 1 }, new Foo);
3333
+ * // => { 'a': 1, 'b': 2 }
3334
+ *
3335
+ * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
3336
+ * // => { 'a': 1, 'b': 2, 'c': 3 }
3337
+ */
3338
+ function toPlainObject(value) {
3339
+ return copyObject(value, keysIn(value));
3340
+ }
3341
+
3342
+ /**
3343
+ * A specialized version of `baseMerge` for arrays and objects which performs
3344
+ * deep merges and tracks traversed objects enabling objects with circular
3345
+ * references to be merged.
3346
+ *
3347
+ * @private
3348
+ * @param {Object} object The destination object.
3349
+ * @param {Object} source The source object.
3350
+ * @param {string} key The key of the value to merge.
3351
+ * @param {number} srcIndex The index of `source`.
3352
+ * @param {Function} mergeFunc The function to merge values.
3353
+ * @param {Function} [customizer] The function to customize assigned values.
3354
+ * @param {Object} [stack] Tracks traversed source values and their merged
3355
+ * counterparts.
3356
+ */
3357
+ function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
3358
+ var objValue = safeGet(object, key),
3359
+ srcValue = safeGet(source, key),
3360
+ stacked = stack.get(srcValue);
3361
+
3362
+ if (stacked) {
3363
+ assignMergeValue(object, key, stacked);
3364
+ return;
3365
+ }
3366
+ var newValue = customizer
3367
+ ? customizer(objValue, srcValue, (key + ''), object, source, stack)
3368
+ : undefined;
3369
+
3370
+ var isCommon = newValue === undefined;
3371
+
3372
+ if (isCommon) {
3373
+ var isArr = isArray(srcValue),
3374
+ isBuff = !isArr && isBuffer(srcValue),
3375
+ isTyped = !isArr && !isBuff && isTypedArray(srcValue);
3376
+
3377
+ newValue = srcValue;
3378
+ if (isArr || isBuff || isTyped) {
3379
+ if (isArray(objValue)) {
3380
+ newValue = objValue;
3381
+ }
3382
+ else if (isArrayLikeObject(objValue)) {
3383
+ newValue = copyArray(objValue);
3384
+ }
3385
+ else if (isBuff) {
3386
+ isCommon = false;
3387
+ newValue = cloneBuffer(srcValue, true);
3388
+ }
3389
+ else if (isTyped) {
3390
+ isCommon = false;
3391
+ newValue = cloneTypedArray(srcValue, true);
3392
+ }
3393
+ else {
3394
+ newValue = [];
3395
+ }
3396
+ }
3397
+ else if (isPlainObject(srcValue) || isArguments(srcValue)) {
3398
+ newValue = objValue;
3399
+ if (isArguments(objValue)) {
3400
+ newValue = toPlainObject(objValue);
3401
+ }
3402
+ else if (!isObject(objValue) || isFunction(objValue)) {
3403
+ newValue = initCloneObject(srcValue);
3404
+ }
3405
+ }
3406
+ else {
3407
+ isCommon = false;
3408
+ }
3409
+ }
3410
+ if (isCommon) {
3411
+ // Recursively merge objects and arrays (susceptible to call stack limits).
3412
+ stack.set(srcValue, newValue);
3413
+ mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
3414
+ stack['delete'](srcValue);
3415
+ }
3416
+ assignMergeValue(object, key, newValue);
3417
+ }
3418
+
3419
+ /**
3420
+ * The base implementation of `_.merge` without support for multiple sources.
3421
+ *
3422
+ * @private
3423
+ * @param {Object} object The destination object.
3424
+ * @param {Object} source The source object.
3425
+ * @param {number} srcIndex The index of `source`.
3426
+ * @param {Function} [customizer] The function to customize merged values.
3427
+ * @param {Object} [stack] Tracks traversed source values and their merged
3428
+ * counterparts.
3429
+ */
3430
+ function baseMerge(object, source, srcIndex, customizer, stack) {
3431
+ if (object === source) {
3432
+ return;
3433
+ }
3434
+ baseFor(source, function(srcValue, key) {
3435
+ stack || (stack = new Stack);
3436
+ if (isObject(srcValue)) {
3437
+ baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
3438
+ }
3439
+ else {
3440
+ var newValue = customizer
3441
+ ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack)
3442
+ : undefined;
3443
+
3444
+ if (newValue === undefined) {
3445
+ newValue = srcValue;
3446
+ }
3447
+ assignMergeValue(object, key, newValue);
3448
+ }
3449
+ }, keysIn);
3450
+ }
3451
+
3180
3452
  /**
3181
3453
  * This function is like `arrayIncludes` except that it accepts a comparator.
3182
3454
  *
@@ -3275,6 +3547,41 @@ function parent(object, path) {
3275
3547
  return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
3276
3548
  }
3277
3549
 
3550
+ /**
3551
+ * This method is like `_.assign` except that it recursively merges own and
3552
+ * inherited enumerable string keyed properties of source objects into the
3553
+ * destination object. Source properties that resolve to `undefined` are
3554
+ * skipped if a destination value exists. Array and plain object properties
3555
+ * are merged recursively. Other objects and value types are overridden by
3556
+ * assignment. Source objects are applied from left to right. Subsequent
3557
+ * sources overwrite property assignments of previous sources.
3558
+ *
3559
+ * **Note:** This method mutates `object`.
3560
+ *
3561
+ * @static
3562
+ * @memberOf _
3563
+ * @since 0.5.0
3564
+ * @category Object
3565
+ * @param {Object} object The destination object.
3566
+ * @param {...Object} [sources] The source objects.
3567
+ * @returns {Object} Returns `object`.
3568
+ * @example
3569
+ *
3570
+ * var object = {
3571
+ * 'a': [{ 'b': 2 }, { 'd': 4 }]
3572
+ * };
3573
+ *
3574
+ * var other = {
3575
+ * 'a': [{ 'c': 3 }, { 'e': 5 }]
3576
+ * };
3577
+ *
3578
+ * _.merge(object, other);
3579
+ * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
3580
+ */
3581
+ var merge = createAssigner(function(object, source, srcIndex) {
3582
+ baseMerge(object, source, srcIndex);
3583
+ });
3584
+
3278
3585
  /**
3279
3586
  * The base implementation of `_.unset`.
3280
3587
  *
@@ -3591,22 +3898,6 @@ const traverseWithDereferencing = (schema, visitor) => {
3591
3898
  _traverseWithDereferencing(schema, schema, [], visitor);
3592
3899
  };
3593
3900
 
3594
- const transformRequestSchema = (schema) => {
3595
- // OpenAPI defines allOf to mean the union of all sub-schemas. JSON-Schema
3596
- // defines allOf to mean that *every* sub-schema needs to be satisfied. In
3597
- // draft 2019-09, JSON-Schema added "unevaluatedProperties" to support this
3598
- // behaviour
3599
- traverseWithDereferencing(schema, (s) => {
3600
- if (s.allOf) {
3601
- forEach(s.allOf, (ss) => {
3602
- delete ss.additionalProperties;
3603
- });
3604
- s.unevaluatedProperties = false;
3605
- }
3606
- });
3607
- return schema;
3608
- };
3609
-
3610
3901
  const transformResponseSchema = (schema, noTransformNonNullableResponseSchema) => {
3611
3902
  // a provider must provide a superset of what the consumer asks for
3612
3903
  // additionalProperties expected in pact response are disallowed
@@ -3630,30 +3921,62 @@ const transformResponseSchema = (schema, noTransformNonNullableResponseSchema) =
3630
3921
  }
3631
3922
  delete s.required;
3632
3923
  });
3633
- // OpenAPI defines allOf to mean the union of all sub-schemas. JSON-Schema
3634
- // defines allOf to mean that *every* sub-schema needs to be satisfied. In
3635
- // draft 2019-09, JSON-Schema added "unevaluatedProperties" to support this
3636
- // behaviour
3637
- traverseWithDereferencing(schema, (s) => {
3638
- if (s.allOf) {
3639
- forEach(s.allOf, (ss) => {
3640
- let subschema = ss;
3641
- if (subschema.$ref) {
3642
- subschema = get$1(schema, splitPath(subschema.$ref));
3643
- }
3644
- delete subschema.additionalProperties;
3645
- if (subschema.allOf) {
3646
- // traversal is depth-first; if nested allOf, remove
3647
- // unevaluatedProperties from previously set deeper schema
3648
- delete subschema.unevaluatedProperties;
3649
- }
3650
- });
3651
- s.unevaluatedProperties = false;
3652
- }
3653
- });
3654
3924
  return schema;
3655
3925
  };
3656
3926
 
3927
+ function _flat(s, root) {
3928
+ if (s.allOf) {
3929
+ const { allOf, ...others } = s;
3930
+ return merge(others, ...allOf.map((ss) => {
3931
+ let dereferenced;
3932
+ if (ss.$ref) {
3933
+ const { $ref, ...others } = ss;
3934
+ dereferenced = {
3935
+ ...others,
3936
+ ...get$1(root, splitPath($ref)),
3937
+ };
3938
+ }
3939
+ return _flat(dereferenced || ss, root);
3940
+ }));
3941
+ }
3942
+ if (s.properties) {
3943
+ for (const ss in s.properties) {
3944
+ s.properties[ss] = _flat(s.properties[ss], root);
3945
+ }
3946
+ return s;
3947
+ }
3948
+ for (const key of [
3949
+ "oneOf",
3950
+ "anyOf",
3951
+ "not",
3952
+ "items",
3953
+ "additionalProperties",
3954
+ ]) {
3955
+ if (s[key]) {
3956
+ return {
3957
+ ...s,
3958
+ [key]: Array.isArray(s[key])
3959
+ ? s[key].map((ss) => _flat(ss, root))
3960
+ : _flat(s[key], root),
3961
+ };
3962
+ }
3963
+ }
3964
+ return s;
3965
+ }
3966
+ // OpenAPI defines allOf to mean the union of all sub-schemas. JSON-Schema
3967
+ // defines allOf to mean that *every* sub-schema needs to be satisfied.
3968
+ // To handle the difference, we flatten 'allOf'
3969
+ function flattenAllOf(s, refs) {
3970
+ // main schema
3971
+ const flattened = _flat(s, s);
3972
+ // any other references
3973
+ for (const ref of refs) {
3974
+ const path = splitPath(ref);
3975
+ set(flattened, path, _flat(get$1(s, path), s));
3976
+ }
3977
+ return flattened;
3978
+ }
3979
+
3657
3980
  // draft-06 onwards converts exclusiveMinimum and exclusiveMaximum to numbers
3658
3981
  const convertExclusiveMinMax = (s) => {
3659
3982
  if (s.exclusiveMaximum === true) {
@@ -3716,13 +4039,13 @@ const minimumSchema = (originalSchema, oas) => {
3716
4039
  const subschema = cloneDeep(get$1(oas, path, {}));
3717
4040
  delete subschema.description;
3718
4041
  delete subschema.example;
3719
- traverse(schema, cleanupDiscriminators);
4042
+ traverse(subschema, cleanupDiscriminators);
3720
4043
  traverse(subschema, collectReferences);
3721
4044
  traverse(subschema, handleNullableSchema);
3722
4045
  traverse(subschema, convertExclusiveMinMax);
3723
4046
  set(schema, path, subschema);
3724
4047
  }
3725
- return schema;
4048
+ return flattenAllOf(schema, refAdded);
3726
4049
  };
3727
4050
 
3728
4051
  const isSimpleSchema = (s, oas) => {
@@ -7336,7 +7659,7 @@ function* compareReqBody(ajv, route, interaction, index, config) {
7336
7659
  : true)) {
7337
7660
  const value = parseBody(body, requestContentType, config.get("legacy-parser"));
7338
7661
  const schemaId = `[root].paths.${path}.${method}.requestBody.content.${contentType}`;
7339
- const validate = getValidateFunction(ajv, schemaId, () => transformRequestSchema(minimumSchema(schema, oas)));
7662
+ const validate = getValidateFunction(ajv, schemaId, () => minimumSchema(schema, oas));
7340
7663
  if (!validate(value)) {
7341
7664
  for (const error of validate.errors) {
7342
7665
  yield {