Skip to content

Commit 2379a4e

Browse files
chore: revert previous fix
1 parent bb9e3e7 commit 2379a4e

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

packages/core/src/__tests__/resolve.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ describe('collect refs', () => {
163163
// expect(resolvedRefs.size).toEqual(2);
164164
expect(Array.from(resolvedRefs.keys()).map((ref) => ref.substring(cwd.length + 1))).toEqual([
165165
'foobar.yaml::./externalInfo.yaml#/info',
166-
'foobar.yaml::./externalLicense.yaml',
166+
'externalInfo.yaml::./externalLicense.yaml',
167167
]);
168168

169169
expect(Array.from(resolvedRefs.values()).map((info) => info.node)).toEqual([
@@ -201,9 +201,9 @@ describe('collect refs', () => {
201201
.sort()
202202
).toMatchInlineSnapshot(`
203203
[
204-
"openapi-with-back.yaml::../openapi-with-back.yaml#/components/schemas/TypeB",
205204
"openapi-with-back.yaml::./schemas/type-a.yaml#/",
206205
"openapi-with-back.yaml::./schemas/type-b.yaml#/",
206+
"schemas/type-a.yaml::../openapi-with-back.yaml#/components/schemas/TypeB",
207207
]
208208
`);
209209

@@ -277,8 +277,8 @@ describe('collect refs', () => {
277277
"openapi.yaml::#/components/schemas/Local/properties/string",
278278
"openapi.yaml::./External.yaml#/properties/string",
279279
"openapi.yaml::./External.yaml",
280-
"openapi.yaml::./External2.yaml",
281-
"openapi.yaml::./External.yaml#/properties",
280+
"External.yaml::./External2.yaml",
281+
"External2.yaml::./External.yaml#/properties",
282282
]
283283
`);
284284

packages/core/src/resolve.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ export async function resolveDocument(opts: {
377377
document,
378378
nodePointer: ref.$ref,
379379
};
380-
const refId = makeRefId(rootDocument.source.absoluteRef, ref.$ref);
380+
const refId = makeRefId(document.source.absoluteRef, ref.$ref);
381381
resolvedRefMap.set(refId, resolvedRef);
382382
return resolvedRef;
383383
}
@@ -404,7 +404,7 @@ export async function resolveDocument(opts: {
404404
document: undefined,
405405
error: error,
406406
};
407-
const refId = makeRefId(rootDocument.source.absoluteRef, ref.$ref);
407+
const refId = makeRefId(document.source.absoluteRef, ref.$ref);
408408
resolvedRefMap.set(refId, resolvedRef);
409409
return resolvedRef;
410410
}
@@ -446,7 +446,7 @@ export async function resolveDocument(opts: {
446446

447447
resolvedRef.node = target;
448448
resolvedRef.document = targetDoc;
449-
const refId = makeRefId(rootDocument.source.absoluteRef, ref.$ref);
449+
const refId = makeRefId(document.source.absoluteRef, ref.$ref);
450450
if (resolvedRef.document && isRef(target)) {
451451
resolvedRef = await followRef(resolvedRef.document, target, pushRef(refStack, target));
452452
}

packages/core/src/rules/ajv.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ function getAjv(resolve: ResolveFn, allowAdditionalProperties: boolean) {
2525
allowUnionTypes: true,
2626
validateFormats: true,
2727
defaultUnevaluatedProperties: allowAdditionalProperties,
28-
loadSchemaSync(_: string, $ref: string, $id: string) {
29-
const resolvedRef = resolve({ $ref });
28+
loadSchemaSync(base: string, $ref: string, $id: string) {
29+
const resolvedRef = resolve({ $ref }, base.split('#')[0]);
3030
if (!resolvedRef || !resolvedRef.location) return false;
3131
return { $id: resolvedRef.location.source.absoluteRef + '#' + $id, ...resolvedRef.node };
3232
},

packages/core/src/walk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export function walkDocument<T extends BaseVisitor>(opts: {
141141
parent: any,
142142
key: string | number
143143
) {
144-
const resolve: ResolveFn = (ref, from = document.source.absoluteRef) => {
144+
const resolve: ResolveFn = (ref, from = currentLocation.source.absoluteRef) => {
145145
if (!isRef(ref)) return { location, node: ref };
146146
const refId = makeRefId(from, ref.$ref);
147147
const resolvedRef = resolvedRefMap.get(refId);

0 commit comments

Comments
 (0)