From 674ee87e2883bc25c644f4b22ed68a2efa4e6817 Mon Sep 17 00:00:00 2001 From: Vladimir Gorej Date: Thu, 26 Dec 2024 14:15:42 +0100 Subject: [PATCH] refactor(reference): align naming with OpenAPI 3.0.4 Root document became entry document. Refs #4612 --- .../strategies/openapi-2/visitor.ts | 20 +++++++++---------- .../strategies/openapi-3-0/visitor.ts | 12 +++++------ .../{root.json => entry.json} | 0 .../fixtures/nested/{root.json => entry.json} | 0 .../substitute/{root.json => entry.json} | 0 .../strategies/apidom/remote/index.ts | 6 +++--- .../local/fixtures/{root.json => entry.json} | 0 .../resolve/strategies/apidom/local/index.ts | 2 +- .../resolve/strategies/apidom/remote/index.ts | 2 +- 9 files changed, 21 insertions(+), 21 deletions(-) rename packages/apidom-reference/test/dereference/strategies/apidom/remote/fixtures/external-disabled/{root.json => entry.json} (100%) rename packages/apidom-reference/test/dereference/strategies/apidom/remote/fixtures/nested/{root.json => entry.json} (100%) rename packages/apidom-reference/test/dereference/strategies/apidom/remote/fixtures/substitute/{root.json => entry.json} (100%) rename packages/apidom-reference/test/resolve/strategies/apidom/local/fixtures/{root.json => entry.json} (100%) diff --git a/packages/apidom-reference/src/dereference/strategies/openapi-2/visitor.ts b/packages/apidom-reference/src/dereference/strategies/openapi-2/visitor.ts index 1e388596bc..872fd06b64 100644 --- a/packages/apidom-reference/src/dereference/strategies/openapi-2/visitor.ts +++ b/packages/apidom-reference/src/dereference/strategies/openapi-2/visitor.ts @@ -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) @@ -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) @@ -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) diff --git a/packages/apidom-reference/src/dereference/strategies/openapi-3-0/visitor.ts b/packages/apidom-reference/src/dereference/strategies/openapi-3-0/visitor.ts index d8ac6523cc..1b444e7adf 100644 --- a/packages/apidom-reference/src/dereference/strategies/openapi-3-0/visitor.ts +++ b/packages/apidom-reference/src/dereference/strategies/openapi-3-0/visitor.ts @@ -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) @@ -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) diff --git a/packages/apidom-reference/test/dereference/strategies/apidom/remote/fixtures/external-disabled/root.json b/packages/apidom-reference/test/dereference/strategies/apidom/remote/fixtures/external-disabled/entry.json similarity index 100% rename from packages/apidom-reference/test/dereference/strategies/apidom/remote/fixtures/external-disabled/root.json rename to packages/apidom-reference/test/dereference/strategies/apidom/remote/fixtures/external-disabled/entry.json diff --git a/packages/apidom-reference/test/dereference/strategies/apidom/remote/fixtures/nested/root.json b/packages/apidom-reference/test/dereference/strategies/apidom/remote/fixtures/nested/entry.json similarity index 100% rename from packages/apidom-reference/test/dereference/strategies/apidom/remote/fixtures/nested/root.json rename to packages/apidom-reference/test/dereference/strategies/apidom/remote/fixtures/nested/entry.json diff --git a/packages/apidom-reference/test/dereference/strategies/apidom/remote/fixtures/substitute/root.json b/packages/apidom-reference/test/dereference/strategies/apidom/remote/fixtures/substitute/entry.json similarity index 100% rename from packages/apidom-reference/test/dereference/strategies/apidom/remote/fixtures/substitute/root.json rename to packages/apidom-reference/test/dereference/strategies/apidom/remote/fixtures/substitute/entry.json diff --git a/packages/apidom-reference/test/dereference/strategies/apidom/remote/index.ts b/packages/apidom-reference/test/dereference/strategies/apidom/remote/index.ts index c29875ffc4..8161c77834 100644 --- a/packages/apidom-reference/test/dereference/strategies/apidom/remote/index.ts +++ b/packages/apidom-reference/test/dereference/strategies/apidom/remote/index.ts @@ -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' }, }); @@ -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' }, }); @@ -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 }, diff --git a/packages/apidom-reference/test/resolve/strategies/apidom/local/fixtures/root.json b/packages/apidom-reference/test/resolve/strategies/apidom/local/fixtures/entry.json similarity index 100% rename from packages/apidom-reference/test/resolve/strategies/apidom/local/fixtures/root.json rename to packages/apidom-reference/test/resolve/strategies/apidom/local/fixtures/entry.json diff --git a/packages/apidom-reference/test/resolve/strategies/apidom/local/index.ts b/packages/apidom-reference/test/resolve/strategies/apidom/local/index.ts index 82e75b2751..0fcdb91e00 100644 --- a/packages/apidom-reference/test/resolve/strategies/apidom/local/index.ts +++ b/packages/apidom-reference/test/resolve/strategies/apidom/local/index.ts @@ -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' }, }); diff --git a/packages/apidom-reference/test/resolve/strategies/apidom/remote/index.ts b/packages/apidom-reference/test/resolve/strategies/apidom/remote/index.ts index ca77b89b1e..13ca37be19 100644 --- a/packages/apidom-reference/test/resolve/strategies/apidom/remote/index.ts +++ b/packages/apidom-reference/test/resolve/strategies/apidom/remote/index.ts @@ -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);