( current_doc: &DocumentPath, json: &mut Value, original: &Value, original_cache: &mut OriginalDocumentsHash, resolved_cache: &mut ResolvedDocumentsHash, )
| 99 | original: &Value, |
| 100 | original_cache: &mut OriginalDocumentsHash, |
| 101 | resolved_cache: &mut ResolvedDocumentsHash, |
| 102 | ) -> Result<(), ResolverError> { |
| 103 | match json { |
| 104 | Value::Array(a) => { |
| 105 | for v in a { |
| 106 | resolve_refs_recurse(current_doc, v, original, original_cache, resolved_cache)?; |
| 107 | } |
| 108 | Ok(()) |
| 109 | } |
| 110 | Value::Object(obj) => { |
| 111 | match obj.remove(REF) { |
| 112 | Some(Value::String(ref_value)) => { |
| 113 | let ref_info = RefInfo::parse(current_doc, &ref_value)?; |
| 114 | |
| 115 | let is_nested = ref_info.document_path == *current_doc; |
| 116 | |
| 117 | let new_value = if is_nested { |
| 118 | let mut v = fetch_reference_value(original, &ref_info.path)?; |
| 119 | resolve_refs_recurse(current_doc, &mut v, original, original_cache, resolved_cache)?; |
| 120 | v |
| 121 | } else { |
| 122 | let doc_path = ref_info.document_path; |
| 123 | let json = get_resolved_or_original(&doc_path, original_cache, resolved_cache)?; |
| 124 | match json { |
| 125 | Json::Resolved(j) => fetch_reference_value(&j, &ref_info.path)?, |
| 126 | Json::Original(j) => { |
| 127 | let mut v = fetch_reference_value(&j, &ref_info.path)?; |
| 128 | resolve_refs_recurse(&doc_path, &mut v, &j, original_cache, resolved_cache)?; |
| 129 | v |
| 130 | } |
| 131 | } |
| 132 | }; |
| 133 | |
| 134 | if let Value::Object(m) = new_value { |
| 135 | for (k, v) in m { |
| 136 | obj.insert(k, v); |
| 137 | } |
| 138 | obj.insert(FROM_REF.into(), Value::String(ref_value)); |
| 139 | obj.insert( |
| 140 | REF_NAME.into(), |
| 141 | Value::String(ref_info.path.map(|p| get_ref_name(&p)).unwrap_or_default()), |
| 142 | ); |
| 143 | } else { |
| 144 | return Err(ResolverError::ShouldBeObject); |
| 145 | } |
| 146 | } |
| 147 | Some(_) => return Err(ResolverError::ShouldBeString), |
| 148 | None => {} |
| 149 | } |
| 150 | |
| 151 | for (_key, value) in obj.into_iter() { |
| 152 | resolve_refs_recurse(current_doc, value, original, original_cache, resolved_cache)?; |
| 153 | } |
| 154 | Ok(()) |
| 155 | } |
| 156 | _ => Ok(()), |
| 157 | } |
| 158 | } |
no test coverage detected