Skip to content

Commit

Permalink
refactor(reference): distinguish Schema with $ref field in dereference (
Browse files Browse the repository at this point in the history
#2342)

Refs #2289
  • Loading branch information
char0n authored Dec 7, 2022
1 parent 2e89af4 commit 8a88f4b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ const OpenApi3_1DereferenceVisitor = stampit({
if (this.visited.SchemaElement.has(referencingElement)) {
return false;
}
if (this.visited.SchemaElementReference.has(referencingElement)) {
return undefined;
}
// skip current referencing schema as $ref keyword was not defined
if (!isStringElement(referencingElement.$ref)) {
// mark current referencing schema as visited
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { toValue } from '@swagger-api/apidom-core';
import { isSchemaElement, mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1';
import { evaluate } from '@swagger-api/apidom-json-pointer';

import { dereference, parse } from '../../../../../src';
import Reference from '../../../../../src/Reference';
import ReferenceSet from '../../../../../src/ReferenceSet';
import { dereference, resolve } from '../../../../../src';
import {
DereferenceError,
MaximumDereferenceDepthError,
Expand Down Expand Up @@ -124,13 +122,10 @@ describe('dereference', function () {
specify('should avoid cycles by skipping transclusion', async function () {
const fixturePath = path.join(rootFixturePath, 'cycle-internal-disabled');
const rootFilePath = path.join(fixturePath, 'root.json');
const reference = Reference({
value: await parse(rootFilePath, {
parse: { mediaType: mediaTypes.latest('json') },
}),
uri: '/home/smartbear/root.json',
const refSet = await resolve(rootFilePath, {
parse: { mediaType: mediaTypes.latest('json') },
});
const refSet = ReferenceSet({ refs: [reference] });
refSet.refs[0].uri = '/home/smartbear/root.json';
const actual = await dereference('/home/smartbear/root.json', {
parse: { mediaType: mediaTypes.latest('json') },
dereference: {
Expand Down Expand Up @@ -196,19 +191,11 @@ describe('dereference', function () {
specify('should avoid cycles by skipping transclusion', async function () {
const fixturePath = path.join(rootFixturePath, 'cycle-external-disabled');
const rootFilePath = path.join(fixturePath, 'root.json');
const reference1 = Reference({
value: await parse(rootFilePath, {
parse: { mediaType: mediaTypes.latest('json') },
}),
uri: '/home/smartbear/root.json',
});
const reference2 = Reference({
value: await parse(path.join(fixturePath, 'ex.json'), {
parse: { mediaType: mediaTypes.latest('json') },
}),
uri: '/home/smartbear/ex.json',
const refSet = await resolve(rootFilePath, {
parse: { mediaType: mediaTypes.latest('json') },
});
const refSet = ReferenceSet({ refs: [reference1, reference2] });
refSet.refs[0].uri = '/home/smartbear/root.json';
refSet.refs[1].uri = '/home/smartbear/ex.json';
const actual = await dereference('/home/smartbear/root.json', {
parse: { mediaType: mediaTypes.latest('json') },
dereference: {
Expand Down

0 comments on commit 8a88f4b

Please sign in to comment.