@@ -310,7 +310,7 @@ module.exports = {
310
310
// {{text}} will not be converted
311
311
// https://regex101.com/r/9N1520/1
312
312
return url
313
- . replace ( / ( \{ [ ^ \/ \{ \} ] + \} ) (? ! \} ) / g, '{$1}' ) ;
313
+ . replace ( / ( \{ [ ^ \/ \{ \} ] + \} ) / g, '{$1}' ) ;
314
314
} ,
315
315
316
316
/**
@@ -2810,6 +2810,43 @@ module.exports = {
2810
2810
return jsonContentType ;
2811
2811
} ,
2812
2812
2813
+ /**
2814
+ * Converts existing JSON values of mismatch objects to serialised value based on
2815
+ * serilasation params defined in schema.
2816
+ *
2817
+ * @param {Array } mismatches - Array of mismatch objects
2818
+ * @param {Array } resolvedSchemaParams - All resolved schema params
2819
+ * @param {Object } components - Components in the spec that the schema might refer to
2820
+ * @param {Object } schemaCache - object storing schemaFaker and schmeResolution caches
2821
+ * @param {Object } options - Global options
2822
+ * @returns {Array } - Array of mismatch objects with updated value
2823
+ */
2824
+ convertToSerialisedValues : function ( mismatches , resolvedSchemaParams , components , schemaCache , options ) {
2825
+ // fetches property name from schem path
2826
+ let getPropNameFromSchemPath = ( schemaPath ) => {
2827
+ let regex = / \. p r o p e r t i e s \[ ( .+ ) \] / gm;
2828
+ return _ . last ( regex . exec ( schemaPath ) ) ;
2829
+ } ;
2830
+
2831
+ return _ . map ( mismatches , ( mismatchObj ) => {
2832
+ if ( ! _ . isEmpty ( mismatchObj ) ) {
2833
+ let propertyName = getPropNameFromSchemPath ( mismatchObj . schemaJsonPath ) ,
2834
+ schemaParam = _ . find ( resolvedSchemaParams , ( param ) => { return param . name === propertyName ; } ) ,
2835
+ serializedParamValue ;
2836
+
2837
+ if ( schemaParam ) {
2838
+ // serialize param value (to be used in suggested value)
2839
+ serializedParamValue = _ . get ( this . convertParamsWithStyle ( schemaParam , _ . get ( mismatchObj ,
2840
+ 'suggestedFix.suggestedValue' ) , PARAMETER_SOURCE . REQUEST , components , schemaCache , options ) ,
2841
+ '[0].value' ) ;
2842
+ _ . set ( mismatchObj , 'suggestedFix.actualValue' , schemaParam . actualValue ) ;
2843
+ _ . set ( mismatchObj , 'suggestedFix.suggestedValue' , serializedParamValue ) ;
2844
+ }
2845
+ }
2846
+ return mismatchObj ;
2847
+ } ) ;
2848
+ } ,
2849
+
2813
2850
/**
2814
2851
*
2815
2852
* @param {String } property - one of QUERYPARAM, PATHVARIABLE, HEADER, BODY, RESPONSE_HEADER, RESPONSE_BODY
@@ -3355,7 +3392,8 @@ module.exports = {
3355
3392
resolvedSchemaParams . push ( {
3356
3393
name : propName ,
3357
3394
schema : propSchema ,
3358
- isResolvedParam : true ,
3395
+ required : param . required || false , // treat exploded param as required if parent param is required
3396
+ isResolvedParam : ! _ . includes ( [ 'array' , 'object' ] , _ . get ( propSchema , 'type' ) ) ,
3359
3397
pathPrefix
3360
3398
} ) ;
3361
3399
} ) ;
@@ -3389,10 +3427,21 @@ module.exports = {
3389
3427
// assign parameter example(s) as schema examples;
3390
3428
this . assignParameterExamples ( schemaParam ) ;
3391
3429
3392
- if ( ! schemaParam . isResolvedParam ) {
3430
+ if ( schemaParam . isResolvedParam === false ) {
3431
+ // simply parse value which will be not serialised and is stringified
3432
+ try {
3433
+ resolvedParamValue = JSON . parse ( pQuery . value ) ;
3434
+ }
3435
+ catch ( err ) {
3436
+ console . warn ( `Unable to parse value for parameter ${ schemaParam . name } ` ) ;
3437
+ }
3438
+ }
3439
+ else if ( ! schemaParam . isResolvedParam ) {
3393
3440
resolvedParamValue = this . deserialiseParamValue ( schemaParam , pQuery . value , PARAMETER_SOURCE . REQUEST ,
3394
3441
components , schemaCache ) ;
3395
3442
}
3443
+ // store existing value to be used in mismatch object
3444
+ schemaParam . actualValue = pQuery . value ;
3396
3445
3397
3446
// query found in spec. check query's schema
3398
3447
setTimeout ( ( ) => {
@@ -3414,7 +3463,7 @@ module.exports = {
3414
3463
let mismatches = [ ] ,
3415
3464
mismatchObj ;
3416
3465
3417
- _ . each ( _ . filter ( schemaParams , ( q ) => { return q . required ; } ) , ( qp ) => {
3466
+ _ . each ( _ . filter ( resolvedSchemaParams , ( q ) => { return q . required ; } ) , ( qp ) => {
3418
3467
if ( ! _ . find ( requestQueryParams , ( param ) => { return param . key === qp . name ; } ) ) {
3419
3468
3420
3469
// assign parameter example(s) as schema examples;
@@ -3443,7 +3492,11 @@ module.exports = {
3443
3492
mismatches . push ( mismatchObj ) ;
3444
3493
}
3445
3494
} ) ;
3446
- return callback ( null , _ . concat ( _ . flatten ( res ) , mismatches ) ) ;
3495
+
3496
+ mismatches = this . convertToSerialisedValues ( _ . concat ( _ . flatten ( res ) , mismatches ) , resolvedSchemaParams ,
3497
+ components , schemaCache , options ) ;
3498
+
3499
+ return callback ( null , mismatches ) ;
3447
3500
} ) ;
3448
3501
} ,
3449
3502
@@ -3864,7 +3917,8 @@ module.exports = {
3864
3917
resolvedSchemaParams . push ( {
3865
3918
name : key ,
3866
3919
schema : value ,
3867
- isResolvedParam : true
3920
+ required : resolvedProp . required || false , // treat exploded param as required if parent param is required
3921
+ isResolvedParam : ! _ . includes ( [ 'array' , 'object' ] , _ . get ( propSchema , 'type' ) )
3868
3922
} ) ;
3869
3923
} ) ;
3870
3924
}
@@ -3894,7 +3948,16 @@ module.exports = {
3894
3948
return cb ( null , mismatches ) ;
3895
3949
}
3896
3950
3897
- if ( ! schemaParam . isResolvedParam ) {
3951
+ if ( schemaParam . isResolvedParam === false ) {
3952
+ // simply parse value which will be not serialised and is stringified
3953
+ try {
3954
+ resolvedParamValue = JSON . parse ( uParam . value ) ;
3955
+ }
3956
+ catch ( err ) {
3957
+ console . warn ( `Unable to parse value for parameter ${ schemaParam . name } ` ) ;
3958
+ }
3959
+ }
3960
+ else if ( ! schemaParam . isResolvedParam ) {
3898
3961
resolvedParamValue = this . deserialiseParamValue ( schemaParam , uParam . value , PARAMETER_SOURCE . REQUEST ,
3899
3962
components , schemaCache ) ;
3900
3963
}
@@ -3919,30 +3982,7 @@ module.exports = {
3919
3982
} , 0 ) ;
3920
3983
} , ( err , res ) => {
3921
3984
let mismatches = [ ] ,
3922
- mismatchObj ,
3923
- // fetches property name from schem path
3924
- getPropNameFromSchemPath = ( schemaPath ) => {
3925
- let regex = / \. p r o p e r t i e s \[ ( .+ ) \] / gm;
3926
- return _ . last ( regex . exec ( schemaPath ) ) ;
3927
- } ;
3928
-
3929
- // update actual value and suggested value from JSON to serialized strings
3930
- _ . forEach ( _ . flatten ( res ) , ( mismatchObj ) => {
3931
- if ( ! _ . isEmpty ( mismatchObj ) ) {
3932
- let propertyName = getPropNameFromSchemPath ( mismatchObj . schemaJsonPath ) ,
3933
- schemaParam = _ . find ( resolvedSchemaParams , ( param ) => { return param . name === propertyName ; } ) ,
3934
- serializedParamValue ;
3935
-
3936
- if ( schemaParam ) {
3937
- // serialize param value (to be used in suggested value)
3938
- serializedParamValue = _ . get ( this . convertParamsWithStyle ( schemaParam , _ . get ( mismatchObj ,
3939
- 'suggestedFix.suggestedValue' ) , PARAMETER_SOURCE . REQUEST , components , schemaCache , options ) ,
3940
- '[0].value' ) ;
3941
- _ . set ( mismatchObj , 'suggestedFix.actualValue' , schemaParam . actualValue ) ;
3942
- _ . set ( mismatchObj , 'suggestedFix.suggestedValue' , serializedParamValue ) ;
3943
- }
3944
- }
3945
- } ) ;
3985
+ mismatchObj ;
3946
3986
3947
3987
_ . each ( resolvedSchemaParams , ( uParam ) => {
3948
3988
// report mismatches only for reuired properties
@@ -3970,7 +4010,12 @@ module.exports = {
3970
4010
mismatches . push ( mismatchObj ) ;
3971
4011
}
3972
4012
} ) ;
3973
- return callback ( null , _ . concat ( _ . flatten ( res ) , mismatches ) ) ;
4013
+
4014
+ // update actual value and suggested value from JSON to serialized strings
4015
+ mismatches = this . convertToSerialisedValues ( _ . concat ( _ . flatten ( res ) , mismatches ) , resolvedSchemaParams ,
4016
+ components , schemaCache , options ) ;
4017
+
4018
+ return callback ( null , mismatches ) ;
3974
4019
} ) ;
3975
4020
}
3976
4021
else {
0 commit comments