(
ref: string,
context: {
currentSource: string;
currentDocument: unknown;
rawDocCache: Map<string, unknown>;
resolvingRefs: Set<string>;
}
)
| 133 | } |
| 134 | |
| 135 | private async resolveRef( |
| 136 | ref: string, |
| 137 | context: { |
| 138 | currentSource: string; |
| 139 | currentDocument: unknown; |
| 140 | rawDocCache: Map<string, unknown>; |
| 141 | resolvingRefs: Set<string>; |
| 142 | } |
| 143 | ): Promise<unknown> { |
| 144 | const { source, pointer } = this.splitRef(ref, context.currentSource); |
| 145 | const cacheKey = `${source}#${pointer}`; |
| 146 | |
| 147 | if (context.resolvingRefs.has(cacheKey)) { |
| 148 | return { $ref: ref }; |
| 149 | } |
| 150 | |
| 151 | context.resolvingRefs.add(cacheKey); |
| 152 | |
| 153 | const targetDocument = source === context.currentSource |
| 154 | ? context.currentDocument |
| 155 | : await this.loadDocument(source, context.rawDocCache); |
| 156 | |
| 157 | const targetValue = this.resolvePointer(targetDocument, pointer); |
| 158 | const resolvedValue = await this.resolveRefs(targetValue, { |
| 159 | currentSource: source, |
| 160 | currentDocument: targetDocument, |
| 161 | rawDocCache: context.rawDocCache, |
| 162 | resolvingRefs: context.resolvingRefs, |
| 163 | }); |
| 164 | |
| 165 | context.resolvingRefs.delete(cacheKey); |
| 166 | return resolvedValue; |
| 167 | } |
| 168 | |
| 169 | private splitRef(ref: string, currentSource: string): { source: string; pointer: string } { |
| 170 | const [refSource, pointer = ""] = ref.split("#", 2); |
no test coverage detected