Skip to content

Commit

Permalink
refactor(reference): align naming with OpenAPI 3.0.4
Browse files Browse the repository at this point in the history
Root document became entry document.

Refs #4612
  • Loading branch information
char0n committed Dec 26, 2024
1 parent 7341bf3 commit 674ee87
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,15 @@ class OpenAPI2DereferenceVisitor {
*
* Cases to consider:
* 1. We're crossing document boundary
* 2. Fragment is from non-root document
* 2. Fragment is from non-entry document
* 3. Fragment is a Reference Object. We need to follow it to get the eventual value
* 4. We are dereferencing the fragment lazily/eagerly depending on circular mode
*/
const isNonRootDocument = url.stripHash(reference.refSet!.rootRef!.uri) !== reference.uri;
const isNonEntryDocument = url.stripHash(reference.refSet!.rootRef!.uri) !== reference.uri;
const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular);
if (
(isExternalReference ||
isNonRootDocument ||
isNonEntryDocument ||
isReferenceElement(referencedElement) ||
shouldDetectCircular) &&
!ancestorsLineage.includesCycle(referencedElement)
Expand Down Expand Up @@ -432,15 +432,15 @@ class OpenAPI2DereferenceVisitor {
*
* Cases to consider:
* 1. We're crossing document boundary
* 2. Fragment is from non-root document
* 3. Fragment is a Paht Item Object with $ref field. We need to follow it to get the eventual value
* 2. Fragment is from non-entry document
* 3. Fragment is a Path Item Object with $ref field. We need to follow it to get the eventual value
* 4. We are dereferencing the fragment lazily/eagerly depending on circular mode
*/
const isNonRootDocument = url.stripHash(reference.refSet!.rootRef!.uri) !== reference.uri;
const isNonEntryDocument = url.stripHash(reference.refSet!.rootRef!.uri) !== reference.uri;
const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular);
if (
(isExternalReference ||
isNonRootDocument ||
isNonEntryDocument ||
(isPathItemElement(referencedElement) && isStringElement(referencedElement.$ref)) ||
shouldDetectCircular) &&
!ancestorsLineage.includesCycle(referencedElement)
Expand Down Expand Up @@ -612,15 +612,15 @@ class OpenAPI2DereferenceVisitor {
*
* Cases to consider:
* 1. We're crossing document boundary
2. Fragment is from non-root document
2. Fragment is from non-entry document
* 3. Fragment is a JSON Reference Object. We need to follow it to get the eventual value
* 4. We are dereferencing the fragment lazily/eagerly depending on circular mode
*/
const isNonRootDocument = url.stripHash(reference.refSet!.rootRef!.uri) !== reference.uri;
const isNonEntryDocument = url.stripHash(reference.refSet!.rootRef!.uri) !== reference.uri;
const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular);
if (
(isExternalReference ||
isNonRootDocument ||
isNonEntryDocument ||
isJSONReferenceElement(referencedElement) ||
shouldDetectCircular) &&
!ancestorsLineage.includesCycle(referencedElement)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,15 @@ class OpenAPI3_0DereferenceVisitor {
*
* Cases to consider:
* 1. We're crossing document boundary
* 2. Fragment is from non-root document
* 2. Fragment is from non-entry document
* 3. Fragment is a Reference Object. We need to follow it to get the eventual value
* 4. We are dereferencing the fragment lazily/eagerly depending on circular mode
*/
const isNonRootDocument = url.stripHash(reference.refSet!.rootRef!.uri) !== reference.uri;
const isNonEntryDocument = url.stripHash(reference.refSet!.rootRef!.uri) !== reference.uri;
const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular);
if (
(isExternalReference ||
isNonRootDocument ||
isNonEntryDocument ||
isReferenceElement(referencedElement) ||
shouldDetectCircular) &&
!ancestorsLineage.includesCycle(referencedElement)
Expand Down Expand Up @@ -433,15 +433,15 @@ class OpenAPI3_0DereferenceVisitor {
*
* Cases to consider:
* 1. We're crossing document boundary
* 2. Fragment is from non-root document
* 2. Fragment is from non-entry document
* 3. Fragment is a Path Item Object with $ref field. We need to follow it to get the eventual value
* 4. We are dereferencing the fragment lazily/eagerly depending on circular mode
*/
const isNonRootDocument = url.stripHash(reference.refSet!.rootRef!.uri) !== reference.uri;
const isNonEntryDocument = url.stripHash(reference.refSet!.rootRef!.uri) !== reference.uri;
const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular);
if (
(isExternalReference ||
isNonRootDocument ||
isNonEntryDocument ||
(isPathItemElement(referencedElement) && isStringElement(referencedElement.$ref)) ||
shouldDetectCircular) &&
!ancestorsLineage.includesCycle(referencedElement)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('dereference', function () {
context('apidom', function () {
context('remote', function () {
specify('should substitute Ref Element with the Element it references', async function () {
const uri = path.join(__dirname, 'fixtures', 'substitute', 'root.json');
const uri = path.join(__dirname, 'fixtures', 'substitute', 'entry.json');
const actual = await dereference(uri, {
parse: { mediaType: 'application/vnd.apidom' },
});
Expand All @@ -24,7 +24,7 @@ describe('dereference', function () {
specify(
'should process Ref Element nested in remote referenced element',
async function () {
const uri = path.join(__dirname, 'fixtures', 'nested', 'root.json');
const uri = path.join(__dirname, 'fixtures', 'nested', 'entry.json');
const actual = await dereference(uri, {
parse: { mediaType: 'application/vnd.apidom' },
});
Expand All @@ -37,7 +37,7 @@ describe('dereference', function () {

context('given external resolution disabled', function () {
specify('should not dereference', async function () {
const uri = path.join(__dirname, 'fixtures', 'external-disabled', 'root.json');
const uri = path.join(__dirname, 'fixtures', 'external-disabled', 'entry.json');
const actual = await dereference(uri, {
parse: { mediaType: 'application/vnd.apidom' },
resolve: { external: false },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('resolve', function () {
context('local', function () {
context('resolve', function () {
specify('should resolve', async function () {
const uri = path.resolve(__dirname, 'fixtures', 'root.json');
const uri = path.resolve(__dirname, 'fixtures', 'entry.json');
const refSet = await resolve(uri, {
parse: { mediaType: 'application/vnd.apidom' },
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('dereference', function () {
});
const refSet = await resolveApiDOM(element, {
parse: { mediaType: 'application/vnd.apidom' },
resolve: { baseURI: path.join(__dirname, 'fixtures', 'root.json') },
resolve: { baseURI: path.join(__dirname, 'fixtures', 'entry.json') },
});

assert.strictEqual(refSet.size, 2);
Expand Down

0 comments on commit 674ee87

Please sign in to comment.