@@ -269,16 +269,16 @@ let QUERYPARAM = 'query',
269269 * @param {Object } context - Global context object
270270 * @param {Object } readOnlyPropCache - readOnly properties cache to be merged
271271 * @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
273273 * @returns {void }
274274 */
275275 mergeReadWritePropCache = ( context , readOnlyPropCache , writeOnlyPropCache , currentPath = '' ) => {
276276 _ . forOwn ( readOnlyPropCache , ( value , key ) => {
277- context . readOnlyPropCache [ ` ${ currentPath } ${ key } ` ] = true ;
277+ context . readOnlyPropCache [ utils . mergeJsonPath ( currentPath , key ) ] = true ;
278278 } ) ;
279279
280280 _ . forOwn ( writeOnlyPropCache , ( value , key ) => {
281- context . writeOnlyPropCache [ ` ${ currentPath } ${ key } ` ] = true ;
281+ context . writeOnlyPropCache [ utils . mergeJsonPath ( currentPath , key ) ] = true ;
282282 } ) ;
283283 } ,
284284
@@ -487,7 +487,7 @@ let QUERYPARAM = 'query',
487487 * @param {Number } [stack] - Current recursion depth
488488 * @param {* } resolveFor - resolve refs for flow validation/conversion (value to be one of VALIDATION/CONVERSION)
489489 * @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
491491 *
492492 * @returns {Object } Resolved schema
493493 */
@@ -524,7 +524,7 @@ let QUERYPARAM = 'query',
524524 * @param {Number } [stack] - Current recursion depth
525525 * @param {String } resolveFor - For which action this resolution is to be done
526526 * @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
528528 * @todo : Explore using a directed graph/tree for maintaining seen ref
529529 *
530530 * @returns {Object } Returns the object that satisfies the schema
@@ -569,9 +569,9 @@ let QUERYPARAM = 'query',
569569 return _resolveSchema ( context , compositeSchema [ 0 ] , stack , resolveFor , _ . cloneDeep ( seenRef ) , currentPath ) ;
570570 }
571571
572- return { [ compositeKeyword ] : _ . map ( compositeSchema , ( schemaElement ) => {
572+ return { [ compositeKeyword ] : _ . map ( compositeSchema , ( schemaElement , index ) => {
573573 return _resolveSchema ( context , schemaElement , stack , resolveFor , _ . cloneDeep ( seenRef ) ,
574- ` ${ currentPath } . ${ compositeKeyword } ` ) ;
574+ utils . addToJsonPath ( currentPath , [ compositeKeyword , index ] ) ) ;
575575 } ) } ;
576576 }
577577
@@ -664,16 +664,7 @@ let QUERYPARAM = 'query',
664664 return ;
665665 }
666666
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 ] ) ;
677668
678669 resolvedSchemaProps [ propertyName ] = _resolveSchema ( context , property , stack , resolveFor ,
679670 _ . cloneDeep ( seenRef ) , currentPropPath ) ;
@@ -685,7 +676,7 @@ let QUERYPARAM = 'query',
685676 // If schema is of type array
686677 else if ( concreteUtils . compareTypes ( schema . type , SCHEMA_TYPES . array ) && schema . items ) {
687678 schema . items = _resolveSchema ( context , schema . items , stack , resolveFor , _ . cloneDeep ( seenRef ) ,
688- ` ${ currentPath } . items` ) ;
679+ utils . addToJsonPath ( currentPath , [ ' items' ] ) ) ;
689680 }
690681 // Any properties to ignored should not be available in schema
691682 else if ( _ . every ( SCHEMA_PROPERTIES_TO_EXCLUDE , ( schemaKey ) => { return ! schema . hasOwnProperty ( schemaKey ) ; } ) ) {
@@ -718,7 +709,7 @@ let QUERYPARAM = 'query',
718709 if ( schema . hasOwnProperty ( 'additionalProperties' ) ) {
719710 schema . additionalProperties = _ . isBoolean ( schema . additionalProperties ) ? schema . additionalProperties :
720711 _resolveSchema ( context , schema . additionalProperties , stack , resolveFor , _ . cloneDeep ( seenRef ) ,
721- ` ${ currentPath } . additionalProperties` ) ;
712+ utils . addToJsonPath ( currentPath , [ ' additionalProperties' ] ) ) ;
722713 schema . type = schema . type || SCHEMA_TYPES . object ;
723714 }
724715
@@ -733,6 +724,15 @@ let QUERYPARAM = 'query',
733724 } ) ;
734725 }
735726
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+
736736 return schema ;
737737 } ,
738738
@@ -769,12 +769,14 @@ let QUERYPARAM = 'query',
769769
770770 if ( isResponseSchema ) {
771771 _ . 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 ) ) ;
773774 } ) ;
774775 }
775776 else {
776777 _ . 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 ) ) ;
778780 } ) ;
779781 }
780782
0 commit comments