From 48b4eb4d99c198802431af9fcf75b706534853a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Fri, 29 Mar 2024 08:38:09 +0100 Subject: [PATCH] perf(reference): dereference fragments as quick as possible (#3981) Refs #3974 --- .../src/dereference/strategies/asyncapi-2/visitor.ts | 4 ++-- .../src/dereference/strategies/openapi-2/visitor.ts | 6 +++--- .../src/dereference/strategies/openapi-3-0/visitor.ts | 4 ++-- .../src/dereference/strategies/openapi-3-1/visitor.ts | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/apidom-reference/src/dereference/strategies/asyncapi-2/visitor.ts b/packages/apidom-reference/src/dereference/strategies/asyncapi-2/visitor.ts index 635a48424..a2b13c088 100644 --- a/packages/apidom-reference/src/dereference/strategies/asyncapi-2/visitor.ts +++ b/packages/apidom-reference/src/dereference/strategies/asyncapi-2/visitor.ts @@ -233,7 +233,7 @@ const AsyncApi2DereferenceVisitor = stampit({ * 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 = reference.refSet.rootRef.uri !== reference.uri; + const isNonRootDocument = url.stripHash(reference.refSet.rootRef.uri) !== reference.uri; const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular); if ( (isExternalReference || @@ -430,7 +430,7 @@ const AsyncApi2DereferenceVisitor = stampit({ * 3. Fragment is a Channel 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 = reference.refSet.rootRef.uri !== reference.uri; + const isNonRootDocument = url.stripHash(reference.refSet.rootRef.uri) !== reference.uri; const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular); if ( (isExternalReference || 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 d9914868e..3640f6553 100644 --- a/packages/apidom-reference/src/dereference/strategies/openapi-2/visitor.ts +++ b/packages/apidom-reference/src/dereference/strategies/openapi-2/visitor.ts @@ -234,7 +234,7 @@ const OpenApi2DereferenceVisitor = stampit({ * 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 = reference.refSet.rootRef.uri !== reference.uri; + const isNonRootDocument = url.stripHash(reference.refSet.rootRef.uri) !== reference.uri; const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular); if ( (isExternalReference || @@ -406,7 +406,7 @@ const OpenApi2DereferenceVisitor = stampit({ * 3. Fragment is a Paht 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 = reference.refSet.rootRef.uri !== reference.uri; + const isNonRootDocument = url.stripHash(reference.refSet.rootRef.uri) !== reference.uri; const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular); if ( (isExternalReference || @@ -593,7 +593,7 @@ const OpenApi2DereferenceVisitor = stampit({ * 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 = reference.refSet.rootRef.uri !== reference.uri; + const isNonRootDocument = url.stripHash(reference.refSet.rootRef.uri) !== reference.uri; const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular); if ( (isExternalReference || 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 3bd3649f5..72ffb672d 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 @@ -238,7 +238,7 @@ const OpenApi3_0DereferenceVisitor = stampit({ * 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 = reference.refSet.rootRef.uri !== reference.uri; + const isNonRootDocument = url.stripHash(reference.refSet.rootRef.uri) !== reference.uri; const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular); if ( (isExternalReference || @@ -409,7 +409,7 @@ const OpenApi3_0DereferenceVisitor = stampit({ * 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 = reference.refSet.rootRef.uri !== reference.uri; + const isNonRootDocument = url.stripHash(reference.refSet.rootRef.uri) !== reference.uri; const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular); if ( (isExternalReference || diff --git a/packages/apidom-reference/src/dereference/strategies/openapi-3-1/visitor.ts b/packages/apidom-reference/src/dereference/strategies/openapi-3-1/visitor.ts index 3c6ca3c10..2688d41c4 100644 --- a/packages/apidom-reference/src/dereference/strategies/openapi-3-1/visitor.ts +++ b/packages/apidom-reference/src/dereference/strategies/openapi-3-1/visitor.ts @@ -246,7 +246,7 @@ const OpenApi3_1DereferenceVisitor = stampit({ * 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 = reference.refSet.rootRef.uri !== reference.uri; + const isNonRootDocument = url.stripHash(reference.refSet.rootRef.uri) !== reference.uri; const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular); if ( (isExternalReference || @@ -433,7 +433,7 @@ const OpenApi3_1DereferenceVisitor = stampit({ * 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 = reference.refSet.rootRef.uri !== reference.uri; + const isNonRootDocument = url.stripHash(reference.refSet.rootRef.uri) !== reference.uri; const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular); if ( (isExternalReference || @@ -857,7 +857,7 @@ const OpenApi3_1DereferenceVisitor = stampit({ * 3. Fragment is a Schema 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 = reference.refSet.rootRef.uri !== reference.uri; + const isNonRootDocument = url.stripHash(reference.refSet.rootRef.uri) !== reference.uri; const shouldDetectCircular = ['error', 'replace'].includes(this.options.dereference.circular); if ( (isExternalReference ||