@@ -269,16 +269,16 @@ let QUERYPARAM = 'query',
269
269
* @param {Object } context - Global context object
270
270
* @param {Object } readOnlyPropCache - readOnly properties cache to be merged
271
271
* @param {Object } writeOnlyPropCache - writeOnly properties cache to be merged
272
- * @param {Object } currentPath - Current path being resolved relative to original schema
272
+ * @param {Object } currentPath - Current path (json-pointer) being resolved relative to original schema
273
273
* @returns {void }
274
274
*/
275
275
mergeReadWritePropCache = ( context , readOnlyPropCache , writeOnlyPropCache , currentPath = '' ) => {
276
276
_ . forOwn ( readOnlyPropCache , ( value , key ) => {
277
- context . readOnlyPropCache [ ` ${ currentPath } ${ key } ` ] = true ;
277
+ context . readOnlyPropCache [ utils . mergeJsonPath ( currentPath , key ) ] = true ;
278
278
} ) ;
279
279
280
280
_ . forOwn ( writeOnlyPropCache , ( value , key ) => {
281
- context . writeOnlyPropCache [ ` ${ currentPath } ${ key } ` ] = true ;
281
+ context . writeOnlyPropCache [ utils . mergeJsonPath ( currentPath , key ) ] = true ;
282
282
} ) ;
283
283
} ,
284
284
@@ -487,7 +487,7 @@ let QUERYPARAM = 'query',
487
487
* @param {Number } [stack] - Current recursion depth
488
488
* @param {* } resolveFor - resolve refs for flow validation/conversion (value to be one of VALIDATION/CONVERSION)
489
489
* @param {Object } seenRef - Map of all the references that have been resolved
490
- * @param {String } currentPath - Current path being resolved relative to original schema
490
+ * @param {String } currentPath - Current path (json-pointer) being resolved relative to original schema
491
491
*
492
492
* @returns {Object } Resolved schema
493
493
*/
@@ -524,7 +524,7 @@ let QUERYPARAM = 'query',
524
524
* @param {Number } [stack] - Current recursion depth
525
525
* @param {String } resolveFor - For which action this resolution is to be done
526
526
* @param {Object } seenRef - Map of all the references that have been resolved
527
- * @param {String } currentPath - Current path being resolved relative to original schema
527
+ * @param {String } currentPath - Current path (json-pointer) being resolved relative to original schema
528
528
* @todo : Explore using a directed graph/tree for maintaining seen ref
529
529
*
530
530
* @returns {Object } Returns the object that satisfies the schema
@@ -569,9 +569,9 @@ let QUERYPARAM = 'query',
569
569
return _resolveSchema ( context , compositeSchema [ 0 ] , stack , resolveFor , _ . cloneDeep ( seenRef ) , currentPath ) ;
570
570
}
571
571
572
- return { [ compositeKeyword ] : _ . map ( compositeSchema , ( schemaElement ) => {
572
+ return { [ compositeKeyword ] : _ . map ( compositeSchema , ( schemaElement , index ) => {
573
573
return _resolveSchema ( context , schemaElement , stack , resolveFor , _ . cloneDeep ( seenRef ) ,
574
- ` ${ currentPath } . ${ compositeKeyword } ` ) ;
574
+ utils . addToJsonPath ( currentPath , [ compositeKeyword , index ] ) ) ;
575
575
} ) } ;
576
576
}
577
577
@@ -664,16 +664,7 @@ let QUERYPARAM = 'query',
664
664
return ;
665
665
}
666
666
667
- const currentPropPath = `${ currentPath } .properties.${ propertyName } ` ;
668
-
669
- // Keep track of readOnly and writeOnly properties to resolve request and responses accordingly later.
670
- if ( property . readOnly ) {
671
- context . readOnlyPropCache [ currentPropPath ] = true ;
672
- }
673
-
674
- if ( property . writeOnly ) {
675
- context . writeOnlyPropCache [ currentPropPath ] = true ;
676
- }
667
+ const currentPropPath = utils . addToJsonPath ( currentPath , [ 'properties' , propertyName ] ) ;
677
668
678
669
resolvedSchemaProps [ propertyName ] = _resolveSchema ( context , property , stack , resolveFor ,
679
670
_ . cloneDeep ( seenRef ) , currentPropPath ) ;
@@ -685,7 +676,7 @@ let QUERYPARAM = 'query',
685
676
// If schema is of type array
686
677
else if ( concreteUtils . compareTypes ( schema . type , SCHEMA_TYPES . array ) && schema . items ) {
687
678
schema . items = _resolveSchema ( context , schema . items , stack , resolveFor , _ . cloneDeep ( seenRef ) ,
688
- ` ${ currentPath } . items` ) ;
679
+ utils . addToJsonPath ( currentPath , [ ' items' ] ) ) ;
689
680
}
690
681
// Any properties to ignored should not be available in schema
691
682
else if ( _ . every ( SCHEMA_PROPERTIES_TO_EXCLUDE , ( schemaKey ) => { return ! schema . hasOwnProperty ( schemaKey ) ; } ) ) {
@@ -718,7 +709,7 @@ let QUERYPARAM = 'query',
718
709
if ( schema . hasOwnProperty ( 'additionalProperties' ) ) {
719
710
schema . additionalProperties = _ . isBoolean ( schema . additionalProperties ) ? schema . additionalProperties :
720
711
_resolveSchema ( context , schema . additionalProperties , stack , resolveFor , _ . cloneDeep ( seenRef ) ,
721
- ` ${ currentPath } . additionalProperties` ) ;
712
+ utils . addToJsonPath ( currentPath , [ ' additionalProperties' ] ) ) ;
722
713
schema . type = schema . type || SCHEMA_TYPES . object ;
723
714
}
724
715
@@ -733,6 +724,15 @@ let QUERYPARAM = 'query',
733
724
} ) ;
734
725
}
735
726
727
+ // Keep track of readOnly and writeOnly properties to resolve request and responses accordingly later.
728
+ if ( schema . readOnly ) {
729
+ context . readOnlyPropCache [ currentPath ] = true ;
730
+ }
731
+
732
+ if ( schema . writeOnly ) {
733
+ context . writeOnlyPropCache [ currentPath ] = true ;
734
+ }
735
+
736
736
return schema ;
737
737
} ,
738
738
@@ -769,12 +769,14 @@ let QUERYPARAM = 'query',
769
769
770
770
if ( isResponseSchema ) {
771
771
_ . forOwn ( context . writeOnlyPropCache , ( value , key ) => {
772
- _ . unset ( resolvedSchema , key . substring ( 1 ) ) ;
772
+ // We need to make sure to remove empty strings via _.compact that are added while forming json-pointer
773
+ _ . unset ( resolvedSchema , utils . getJsonPathArray ( key ) ) ;
773
774
} ) ;
774
775
}
775
776
else {
776
777
_ . forOwn ( context . readOnlyPropCache , ( value , key ) => {
777
- _ . unset ( resolvedSchema , key . substring ( 1 ) ) ;
778
+ // We need to make sure to remove empty strings via _.compact that are added while forming json-pointer
779
+ _ . unset ( resolvedSchema , utils . getJsonPathArray ( key ) ) ;
778
780
} ) ;
779
781
}
780
782
0 commit comments