Skip to content

refactor(reference): distinguish Schema with field in dereference #2342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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