From 9082912cc28d532dc45b9af4f500437df0388014 Mon Sep 17 00:00:00 2001 From: Vladimir Gorej Date: Wed, 4 Oct 2023 16:01:11 +0200 Subject: [PATCH] refactor(reference): base all errors on apidom-error package Refs #3039 --- package-lock.json | 1 + packages/apidom-core/src/media-types.ts | 8 +++--- .../src/validator/openapi-3-1/validator.ts | 4 +-- packages/apidom-reference/package.json | 12 ++++----- .../apidom-reference/src/dereference/index.ts | 4 +-- .../strategies/DereferenceStrategy.ts | 6 +++-- .../strategies/asyncapi-2/visitor.ts | 8 +++--- .../strategies/openapi-3-0/visitor.ts | 18 ++++++++----- .../{$anchor/index.ts => $anchor.ts} | 6 +++-- .../EvaluationJsonSchema$anchorError.ts | 3 --- .../errors/InvalidJsonSchema$anchorError.ts | 7 ----- .../selectors/$anchor/errors/index.ts | 2 -- .../selectors/{uri/index.ts => uri.ts} | 9 ++++--- .../errors/EvaluationJsonSchemaUriError.ts | 3 --- .../openapi-3-1/selectors/uri/errors/index.ts | 2 -- .../strategies/openapi-3-1/visitor.ts | 22 +++++++++------ .../src/{util => }/errors/DereferenceError.ts | 0 .../EvaluationJsonSchema$anchorError.ts | 5 ++++ .../errors/EvaluationJsonSchemaUriError.ts | 5 ++++ .../errors/InvalidJsonSchema$anchorError.ts | 9 +++++++ .../src/errors/JsonSchema$anchorError.ts | 5 ++++ .../src/errors/JsonSchemaUriError.ts | 5 ++++ .../errors/MaximumDereferenceDepthError.ts | 0 .../errors/MaximumResolverDepthError.ts | 0 .../src/{util => }/errors/ParserError.ts | 0 .../src/{util => }/errors/PluginError.ts | 0 .../src/{util => }/errors/ResolverError.ts | 0 .../UnmatchedDereferenceStrategyError.ts | 0 .../errors/UnmatchedResolveStrategyError.ts | 0 .../errors/UnmatchedResolverError.ts | 0 packages/apidom-reference/src/index.ts | 27 ++++++++++--------- packages/apidom-reference/src/parse/index.ts | 3 ++- .../src/parse/parsers/Parser.ts | 6 ++--- .../parsers/api-design-systems-json/index.ts | 2 +- .../parsers/api-design-systems-yaml/index.ts | 2 +- .../parse/parsers/asyncapi-json-2/index.ts | 2 +- .../parse/parsers/asyncapi-yaml-2/index.ts | 2 +- .../src/parse/parsers/binary/index-browser.ts | 2 +- .../src/parse/parsers/binary/index-node.ts | 2 +- .../src/parse/parsers/json/index.ts | 2 +- .../parse/parsers/openapi-json-3-0/index.ts | 2 +- .../parse/parsers/openapi-json-3-1/index.ts | 2 +- .../parse/parsers/openapi-yaml-3-0/index.ts | 2 +- .../parse/parsers/openapi-yaml-3-1/index.ts | 2 +- .../src/parse/parsers/yaml-1-2/index.ts | 2 +- .../apidom-reference/src/resolve/index.ts | 3 ++- .../src/resolve/resolvers/HttpResolver.ts | 8 +++--- .../src/resolve/resolvers/Resolver.ts | 4 +-- .../resolve/resolvers/file/index-browser.ts | 2 +- .../src/resolve/resolvers/file/index-node.ts | 2 +- .../src/resolve/resolvers/http-axios/index.ts | 2 +- .../src/resolve/strategies/ResolveStrategy.ts | 6 +++-- .../resolve/strategies/asyncapi-2/visitor.ts | 8 +++--- .../resolve/strategies/openapi-3-0/visitor.ts | 14 ++++++---- .../resolve/strategies/openapi-3-1/visitor.ts | 18 ++++++++----- packages/apidom-reference/src/resolve/util.ts | 3 ++- .../src/util/errors/InvalidSelectorError.ts | 5 ---- .../src/util/errors/NotImplementedError.ts | 9 ------- .../apidom-reference/src/util/errors/index.ts | 11 -------- packages/apidom-reference/src/util/plugins.ts | 2 +- .../asyncapi-2/channel-item-object/index.ts | 3 ++- .../asyncapi-2/reference-object/index.ts | 8 +++--- .../openapi-3-0/example-object/index.ts | 2 +- .../openapi-3-0/link-object/index.ts | 2 +- .../openapi-3-0/path-item-object/index.ts | 3 ++- .../openapi-3-0/reference-object/index.ts | 8 +++--- .../openapi-3-1/example-object/index.ts | 2 +- .../openapi-3-1/link-object/index.ts | 2 +- .../openapi-3-1/path-item-object/index.ts | 3 ++- .../openapi-3-1/reference-object/index.ts | 8 +++--- .../openapi-3-1/schema-object/index.ts | 14 +++++----- packages/apidom-reference/test/parse/index.ts | 4 ++- .../apidom-reference/test/resolve/index.ts | 4 ++- .../test/resolve/resolvers/file/index.ts | 2 +- .../resolve/resolvers/http-axios/index.ts | 2 +- .../asyncapi-2/channel-item-object/index.ts | 3 ++- .../asyncapi-2/reference-object/index.ts | 8 +++--- .../openapi-3-0/example-object/index.ts | 2 +- .../openapi-3-0/link-object/index.ts | 2 +- .../openapi-3-0/path-item-object/index.ts | 3 ++- .../openapi-3-0/reference-object/index.ts | 8 +++--- .../openapi-3-1/example-object/index.ts | 2 +- .../openapi-3-1/link-object/index.ts | 2 +- .../openapi-3-1/path-item-object/index.ts | 3 ++- .../openapi-3-1/reference-object/index.ts | 8 +++--- .../openapi-3-1/schema-object/index.ts | 10 +++---- .../apidom-reference/test/util/plugins.ts | 2 +- 87 files changed, 220 insertions(+), 201 deletions(-) rename packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/{$anchor/index.ts => $anchor.ts} (81%) delete mode 100644 packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/$anchor/errors/EvaluationJsonSchema$anchorError.ts delete mode 100644 packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/$anchor/errors/InvalidJsonSchema$anchorError.ts delete mode 100644 packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/$anchor/errors/index.ts rename packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/{uri/index.ts => uri.ts} (84%) delete mode 100644 packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/uri/errors/EvaluationJsonSchemaUriError.ts delete mode 100644 packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/uri/errors/index.ts rename packages/apidom-reference/src/{util => }/errors/DereferenceError.ts (100%) create mode 100644 packages/apidom-reference/src/errors/EvaluationJsonSchema$anchorError.ts create mode 100644 packages/apidom-reference/src/errors/EvaluationJsonSchemaUriError.ts create mode 100644 packages/apidom-reference/src/errors/InvalidJsonSchema$anchorError.ts create mode 100644 packages/apidom-reference/src/errors/JsonSchema$anchorError.ts create mode 100644 packages/apidom-reference/src/errors/JsonSchemaUriError.ts rename packages/apidom-reference/src/{util => }/errors/MaximumDereferenceDepthError.ts (100%) rename packages/apidom-reference/src/{util => }/errors/MaximumResolverDepthError.ts (100%) rename packages/apidom-reference/src/{util => }/errors/ParserError.ts (100%) rename packages/apidom-reference/src/{util => }/errors/PluginError.ts (100%) rename packages/apidom-reference/src/{util => }/errors/ResolverError.ts (100%) rename packages/apidom-reference/src/{util => }/errors/UnmatchedDereferenceStrategyError.ts (100%) rename packages/apidom-reference/src/{util => }/errors/UnmatchedResolveStrategyError.ts (100%) rename packages/apidom-reference/src/{util => }/errors/UnmatchedResolverError.ts (100%) delete mode 100644 packages/apidom-reference/src/util/errors/InvalidSelectorError.ts delete mode 100644 packages/apidom-reference/src/util/errors/NotImplementedError.ts delete mode 100644 packages/apidom-reference/src/util/errors/index.ts diff --git a/package-lock.json b/package-lock.json index fbf2b89a12..82f535cde9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -34812,6 +34812,7 @@ } }, "packages/apidom-ns-openapi-2": { + "name": "@swagger-api/apidom-ns-openapi-2", "version": "0.77.0", "license": "Apache-2.0", "dependencies": { diff --git a/packages/apidom-core/src/media-types.ts b/packages/apidom-core/src/media-types.ts index f5df27cdb9..d7dd3b39b4 100644 --- a/packages/apidom-core/src/media-types.ts +++ b/packages/apidom-core/src/media-types.ts @@ -5,17 +5,19 @@ class MediaTypes extends Array { // eslint-disable-next-line class-methods-use-this filterByFormat() { - throw new NotImplementedError('"filterByFormat" method is not implemented.'); + throw new NotImplementedError( + 'filterByFormat method in MediaTypes class is not yet implemented.', + ); } // eslint-disable-next-line class-methods-use-this findBy() { - throw new NotImplementedError('"findBy" method is not implemented.'); + throw new NotImplementedError('findBy method in MediaTypes class is not yet implemented.'); } // eslint-disable-next-line class-methods-use-this latest() { - throw new NotImplementedError('"latest" method is not implemented.'); + throw new NotImplementedError('latest method in MediaTypes class is not yet implemented.'); } } diff --git a/packages/apidom-ns-api-design-systems/src/validator/openapi-3-1/validator.ts b/packages/apidom-ns-api-design-systems/src/validator/openapi-3-1/validator.ts index d80285d1a8..6ec3b11b97 100644 --- a/packages/apidom-ns-api-design-systems/src/validator/openapi-3-1/validator.ts +++ b/packages/apidom-ns-api-design-systems/src/validator/openapi-3-1/validator.ts @@ -33,9 +33,7 @@ const makeMessage = ( return `"${primitiveValue}" not allowed for subject ${primitiveStandardIdentifier}`; } - throw new NotImplementedError( - '[Requirement levels] other than "may" are currently not implemented.', - ); + throw new NotImplementedError('[Requirement levels] other than "may" are not yet implemented.'); }; // @ts-ignore diff --git a/packages/apidom-reference/package.json b/packages/apidom-reference/package.json index 77235ac99c..40f7e97296 100644 --- a/packages/apidom-reference/package.json +++ b/packages/apidom-reference/package.json @@ -146,14 +146,14 @@ "types": "./types/dereference/strategies/openapi-3-1/index.d.ts" }, "./dereference/strategies/openapi-3-1/selectors/$anchor": { - "import": "./es/dereference/strategies/openapi-3-1/selectors/$anchor/index.mjs", - "require": "./cjs/dereference/strategies/openapi-3-1/selectors/$anchor/index.cjs", - "types": "./types/dereference/strategies/openapi-3-1/selectors/$anchor/index.d.ts" + "import": "./es/dereference/strategies/openapi-3-1/selectors/$anchor.mjs", + "require": "./cjs/dereference/strategies/openapi-3-1/selectors/$anchor.cjs", + "types": "./types/dereference/strategies/openapi-3-1/selectors/$anchor.d.ts" }, "./dereference/strategies/openapi-3-1/selectors/uri": { - "import": "./es/dereference/strategies/openapi-3-1/selectors/uri/index.mjs", - "require": "./cjs/dereference/strategies/openapi-3-1/selectors/uri/index.cjs", - "types": "./types/dereference/strategies/openapi-3-1/selectors/uri/index.d.ts" + "import": "./es/dereference/strategies/openapi-3-1/selectors/uri.mjs", + "require": "./cjs/dereference/strategies/openapi-3-1/selectors/uri.cjs", + "types": "./types/dereference/strategies/openapi-3-1/selectors/uri.d.ts" } }, "imports": { diff --git a/packages/apidom-reference/src/dereference/index.ts b/packages/apidom-reference/src/dereference/index.ts index 0a4fb5f136..2cff0c66b5 100644 --- a/packages/apidom-reference/src/dereference/index.ts +++ b/packages/apidom-reference/src/dereference/index.ts @@ -8,8 +8,8 @@ import { import File from '../util/File'; import * as plugins from '../util/plugins'; -import { UnmatchedDereferenceStrategyError } from '../util/errors'; -import DereferenceError from '../util/errors/DereferenceError'; +import UnmatchedDereferenceStrategyError from '../errors/UnmatchedDereferenceStrategyError'; +import DereferenceError from '../errors/DereferenceError'; import { ReferenceOptions as IReferenceOptions } from '../types'; import parse from '../parse'; import { merge as mergeOptions } from '../options/util'; diff --git a/packages/apidom-reference/src/dereference/strategies/DereferenceStrategy.ts b/packages/apidom-reference/src/dereference/strategies/DereferenceStrategy.ts index 648a9300c0..556a9bd586 100644 --- a/packages/apidom-reference/src/dereference/strategies/DereferenceStrategy.ts +++ b/packages/apidom-reference/src/dereference/strategies/DereferenceStrategy.ts @@ -1,7 +1,7 @@ import stampit from 'stampit'; +import { NotImplementedError } from '@swagger-api/apidom-error'; import { DereferenceStrategy as IDereferenceStrategy } from '../../types'; -import { NotImplementedError } from '../../util/errors'; const DereferenceStrategy: stampit.Stamp = stampit({ props: { @@ -13,7 +13,9 @@ const DereferenceStrategy: stampit.Stamp = stampit({ }, async dereference(): Promise { - throw new NotImplementedError(); + throw new NotImplementedError( + 'dereference method in DereferenceStrategy stamp is not yet implemented.', + ); }, }, }); 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 9455b1ff48..3a0533f3b2 100644 --- a/packages/apidom-reference/src/dereference/strategies/asyncapi-2/visitor.ts +++ b/packages/apidom-reference/src/dereference/strategies/asyncapi-2/visitor.ts @@ -11,6 +11,7 @@ import { visit, toValue, } from '@swagger-api/apidom-core'; +import { ApiDOMError } from '@swagger-api/apidom-error'; import { evaluate, uriToPointer } from '@swagger-api/apidom-json-pointer'; import { ChannelItemElement, @@ -23,7 +24,8 @@ import { } from '@swagger-api/apidom-ns-asyncapi-2'; import { Reference as IReference } from '../../../types'; -import { MaximumDereferenceDepthError, MaximumResolverDepthError } from '../../../util/errors'; +import MaximumDereferenceDepthError from '../../../errors/MaximumDereferenceDepthError'; +import MaximumResolverDepthError from '../../../errors/MaximumResolverDepthError'; import { AncestorLineage } from '../../util'; import * as url from '../../../util/url'; import parse from '../../../parse'; @@ -141,7 +143,7 @@ const AsyncApi2DereferenceVisitor = stampit({ // detect direct or circular reference if (this.indirections.includes(referencedElement)) { - throw new Error('Recursive Reference Object detected'); + throw new ApiDOMError('Recursive Reference Object detected'); } // detect maximum depth of dereferencing @@ -242,7 +244,7 @@ const AsyncApi2DereferenceVisitor = stampit({ // detect direct or indirect reference if (this.indirections.includes(referencedElement)) { - throw new Error('Recursive Channel Item Object reference detected'); + throw new ApiDOMError('Recursive Channel Item Object reference detected'); } // detect maximum depth of dereferencing 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 8faadf885d..4c2109bbe9 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 @@ -13,6 +13,7 @@ import { toValue, isMemberElement, } from '@swagger-api/apidom-core'; +import { ApiDOMError } from '@swagger-api/apidom-error'; import { evaluate, uriToPointer } from '@swagger-api/apidom-json-pointer'; import { getNodeType, @@ -30,7 +31,8 @@ import { } from '@swagger-api/apidom-ns-openapi-3-0'; import { Reference as IReference } from '../../../types'; -import { MaximumDereferenceDepthError, MaximumResolverDepthError } from '../../../util/errors'; +import MaximumDereferenceDepthError from '../../../errors/MaximumDereferenceDepthError'; +import MaximumResolverDepthError from '../../../errors/MaximumResolverDepthError'; import { AncestorLineage } from '../../util'; import * as url from '../../../util/url'; import parse from '../../../parse'; @@ -149,7 +151,7 @@ const OpenApi3_0DereferenceVisitor = stampit({ // detect direct or circular reference if (this.indirections.includes(referencedElement)) { - throw new Error('Recursive Reference Object detected'); + throw new ApiDOMError('Recursive Reference Object detected'); } // detect maximum depth of dereferencing @@ -251,7 +253,7 @@ const OpenApi3_0DereferenceVisitor = stampit({ // detect direct or indirect reference if (this.indirections.includes(referencedElement)) { - throw new Error('Recursive Path Item Object reference detected'); + throw new ApiDOMError('Recursive Path Item Object reference detected'); } // detect maximum depth of dereferencing @@ -336,7 +338,9 @@ const OpenApi3_0DereferenceVisitor = stampit({ // operationRef and operationId fields are mutually exclusive if (isStringElement(linkElement.operationRef) && isStringElement(linkElement.operationId)) { - throw new Error('LinkElement operationRef and operationId fields are mutually exclusive.'); + throw new ApiDOMError( + 'LinkElement operationRef and operationId fields are mutually exclusive.', + ); } let operationElement: any; @@ -369,7 +373,7 @@ const OpenApi3_0DereferenceVisitor = stampit({ ); // OperationElement not found by its operationId if (isUndefined(operationElement)) { - throw new Error(`OperationElement(operationId=${operationId}) not found.`); + throw new ApiDOMError(`OperationElement(operationId=${operationId}) not found.`); } const linkElementCopy = cloneShallow(linkElement); @@ -406,7 +410,9 @@ const OpenApi3_0DereferenceVisitor = stampit({ // value and externalValue fields are mutually exclusive if (exampleElement.hasKey('value') && isStringElement(exampleElement.externalValue)) { - throw new Error('ExampleElement value and externalValue fields are mutually exclusive.'); + throw new ApiDOMError( + 'ExampleElement value and externalValue fields are mutually exclusive.', + ); } const reference = await this.toReference(toValue(exampleElement.externalValue)); diff --git a/packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/$anchor/index.ts b/packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/$anchor.ts similarity index 81% rename from packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/$anchor/index.ts rename to packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/$anchor.ts index f0da533584..91c62c5883 100644 --- a/packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/$anchor/index.ts +++ b/packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/$anchor.ts @@ -2,8 +2,9 @@ import { trimCharsStart, isUndefined } from 'ramda-adjunct'; import { Element, find, toValue } from '@swagger-api/apidom-core'; import { isSchemaElement } from '@swagger-api/apidom-ns-openapi-3-1'; -import { getHash } from '../../../../../util/url'; -import { EvaluationJsonSchema$anchorError, InvalidJsonSchema$anchorError } from './errors'; +import { getHash } from '../../../../util/url'; +import EvaluationJsonSchema$anchorError from '../../../../errors/EvaluationJsonSchema$anchorError'; +import InvalidJsonSchema$anchorError from '../../../../errors/InvalidJsonSchema$anchorError'; // isAnchor :: String -> Boolean export const isAnchor = (uri: string) => { @@ -47,3 +48,4 @@ export const evaluate = (anchor: string, element: T): Element }; export { EvaluationJsonSchema$anchorError, InvalidJsonSchema$anchorError }; +export { default as JsonSchema$anchorError } from '../../../../errors/JsonSchema$anchorError'; diff --git a/packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/$anchor/errors/EvaluationJsonSchema$anchorError.ts b/packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/$anchor/errors/EvaluationJsonSchema$anchorError.ts deleted file mode 100644 index 63a001936c..0000000000 --- a/packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/$anchor/errors/EvaluationJsonSchema$anchorError.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { ApiDOMError } from '@swagger-api/apidom-error'; - -export default class EvaluationJsonSchema$anchorError extends ApiDOMError {} diff --git a/packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/$anchor/errors/InvalidJsonSchema$anchorError.ts b/packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/$anchor/errors/InvalidJsonSchema$anchorError.ts deleted file mode 100644 index c3d027f797..0000000000 --- a/packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/$anchor/errors/InvalidJsonSchema$anchorError.ts +++ /dev/null @@ -1,7 +0,0 @@ -import InvalidSelectorError from '../../../../../../util/errors/InvalidSelectorError'; - -export default class InvalidJsonSchema$anchorError extends InvalidSelectorError { - constructor(anchor: string) { - super(`Invalid JSON Schema $anchor "${anchor}".`); - } -} diff --git a/packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/$anchor/errors/index.ts b/packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/$anchor/errors/index.ts deleted file mode 100644 index 32cdc667ce..0000000000 --- a/packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/$anchor/errors/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as EvaluationJsonSchema$anchorError } from './EvaluationJsonSchema$anchorError'; -export { default as InvalidJsonSchema$anchorError } from './InvalidJsonSchema$anchorError'; diff --git a/packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/uri/index.ts b/packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/uri.ts similarity index 84% rename from packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/uri/index.ts rename to packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/uri.ts index 4033370b0e..48f16b9931 100644 --- a/packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/uri/index.ts +++ b/packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/uri.ts @@ -3,10 +3,10 @@ import { Element, filter } from '@swagger-api/apidom-core'; import { isSchemaElement, SchemaElement } from '@swagger-api/apidom-ns-openapi-3-1'; import { uriToPointer, evaluate as jsonPointerEvaluate } from '@swagger-api/apidom-json-pointer'; -import * as url from '../../../../../util/url'; -import { EvaluationJsonSchemaUriError } from './errors'; -import { isAnchor, uriToAnchor, evaluate as $anchorEvaluate } from '../$anchor'; -import { resolveSchema$idField } from '../../../../../resolve/strategies/openapi-3-1/util'; +import * as url from '../../../../util/url'; +import EvaluationJsonSchemaUriError from '../../../../errors/EvaluationJsonSchemaUriError'; +import { isAnchor, uriToAnchor, evaluate as $anchorEvaluate } from './$anchor'; +import { resolveSchema$idField } from '../../../../resolve/strategies/openapi-3-1/util'; /** * Evaluates JSON Schema $ref containing unknown URI against ApiDOM fragment. @@ -50,3 +50,4 @@ export const evaluate = (uri: string, element: T): Element | evaluate.cache = new WeakMap(); export { EvaluationJsonSchemaUriError }; +export { default as JsonSchemaUriError } from '../../../../errors/JsonSchemaUriError'; diff --git a/packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/uri/errors/EvaluationJsonSchemaUriError.ts b/packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/uri/errors/EvaluationJsonSchemaUriError.ts deleted file mode 100644 index 1c1355304a..0000000000 --- a/packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/uri/errors/EvaluationJsonSchemaUriError.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { ApiDOMError } from '@swagger-api/apidom-error'; - -export default class EvaluationJsonSchemaUriError extends ApiDOMError {} diff --git a/packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/uri/errors/index.ts b/packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/uri/errors/index.ts deleted file mode 100644 index 16b7d25858..0000000000 --- a/packages/apidom-reference/src/dereference/strategies/openapi-3-1/selectors/uri/errors/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -// eslint-disable-next-line import/prefer-default-export -export { default as EvaluationJsonSchemaUriError } from './EvaluationJsonSchemaUriError'; 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 d6dbae72c8..22194efdea 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 @@ -14,6 +14,7 @@ import { toValue, Element, } from '@swagger-api/apidom-core'; +import { ApiDOMError } from '@swagger-api/apidom-error'; import { evaluate as jsonPointerEvaluate, uriToPointer } from '@swagger-api/apidom-json-pointer'; import { getNodeType, @@ -35,7 +36,8 @@ import { import { isAnchor, uriToAnchor, evaluate as $anchorEvaluate } from './selectors/$anchor'; import { evaluate as uriEvaluate } from './selectors/uri'; import { Reference as IReference, Resolver as IResolver } from '../../../types'; -import { MaximumDereferenceDepthError, MaximumResolverDepthError } from '../../../util/errors'; +import MaximumDereferenceDepthError from '../../../errors/MaximumDereferenceDepthError'; +import MaximumResolverDepthError from '../../../errors/MaximumResolverDepthError'; import * as url from '../../../util/url'; import parse from '../../../parse'; import Reference from '../../../Reference'; @@ -45,7 +47,7 @@ import { maybeRefractToSchemaElement, } from '../../../resolve/strategies/openapi-3-1/util'; import { AncestorLineage } from '../../util'; -import EvaluationJsonSchemaUriError from './selectors/uri/errors/EvaluationJsonSchemaUriError'; +import EvaluationJsonSchemaUriError from '../../../errors/EvaluationJsonSchemaUriError'; // @ts-ignore const visitAsync = visit[Symbol.for('nodejs.util.promisify.custom')]; @@ -162,7 +164,7 @@ const OpenApi3_1DereferenceVisitor = stampit({ // detect direct or indirect reference if (this.indirections.includes(referencedElement)) { - throw new Error('Recursive Reference Object detected'); + throw new ApiDOMError('Recursive Reference Object detected'); } // detect maximum depth of dereferencing @@ -283,7 +285,7 @@ const OpenApi3_1DereferenceVisitor = stampit({ // detect direct or indirect reference if (this.indirections.includes(referencedElement)) { - throw new Error('Recursive Path Item Object reference detected'); + throw new ApiDOMError('Recursive Path Item Object reference detected'); } // detect maximum depth of dereferencing @@ -368,7 +370,9 @@ const OpenApi3_1DereferenceVisitor = stampit({ // operationRef and operationId fields are mutually exclusive if (isStringElement(linkElement.operationRef) && isStringElement(linkElement.operationId)) { - throw new Error('LinkElement operationRef and operationId fields are mutually exclusive.'); + throw new ApiDOMError( + 'LinkElement operationRef and operationId fields are mutually exclusive.', + ); } let operationElement: any; @@ -401,7 +405,7 @@ const OpenApi3_1DereferenceVisitor = stampit({ ); // OperationElement not found by its operationId if (isUndefined(operationElement)) { - throw new Error(`OperationElement(operationId=${operationId}) not found.`); + throw new ApiDOMError(`OperationElement(operationId=${operationId}) not found.`); } const linkElementCopy = cloneShallow(linkElement); @@ -438,7 +442,9 @@ const OpenApi3_1DereferenceVisitor = stampit({ // value and externalValue fields are mutually exclusive if (exampleElement.hasKey('value') && isStringElement(exampleElement.externalValue)) { - throw new Error('ExampleElement value and externalValue fields are mutually exclusive.'); + throw new ApiDOMError( + 'ExampleElement value and externalValue fields are mutually exclusive.', + ); } const reference = await this.toReference(toValue(exampleElement.externalValue)); @@ -545,7 +551,7 @@ const OpenApi3_1DereferenceVisitor = stampit({ // detect direct or indirect reference if (this.indirections.includes(referencedElement)) { - throw new Error('Recursive Schema Object reference detected'); + throw new ApiDOMError('Recursive Schema Object reference detected'); } // detect maximum depth of dereferencing diff --git a/packages/apidom-reference/src/util/errors/DereferenceError.ts b/packages/apidom-reference/src/errors/DereferenceError.ts similarity index 100% rename from packages/apidom-reference/src/util/errors/DereferenceError.ts rename to packages/apidom-reference/src/errors/DereferenceError.ts diff --git a/packages/apidom-reference/src/errors/EvaluationJsonSchema$anchorError.ts b/packages/apidom-reference/src/errors/EvaluationJsonSchema$anchorError.ts new file mode 100644 index 0000000000..80f7b057e0 --- /dev/null +++ b/packages/apidom-reference/src/errors/EvaluationJsonSchema$anchorError.ts @@ -0,0 +1,5 @@ +import JsonSchema$anchorError from './JsonSchema$anchorError'; + +class EvaluationJsonSchema$anchorError extends JsonSchema$anchorError {} + +export default EvaluationJsonSchema$anchorError; diff --git a/packages/apidom-reference/src/errors/EvaluationJsonSchemaUriError.ts b/packages/apidom-reference/src/errors/EvaluationJsonSchemaUriError.ts new file mode 100644 index 0000000000..6b2395491a --- /dev/null +++ b/packages/apidom-reference/src/errors/EvaluationJsonSchemaUriError.ts @@ -0,0 +1,5 @@ +import JsonSchemaUriError from './JsonSchemaUriError'; + +class EvaluationJsonSchemaUriError extends JsonSchemaUriError {} + +export default EvaluationJsonSchemaUriError; diff --git a/packages/apidom-reference/src/errors/InvalidJsonSchema$anchorError.ts b/packages/apidom-reference/src/errors/InvalidJsonSchema$anchorError.ts new file mode 100644 index 0000000000..e9933f0708 --- /dev/null +++ b/packages/apidom-reference/src/errors/InvalidJsonSchema$anchorError.ts @@ -0,0 +1,9 @@ +import JsonSchema$anchorError from './JsonSchema$anchorError'; + +class InvalidJsonSchema$anchorError extends JsonSchema$anchorError { + constructor(anchor: string) { + super(`Invalid JSON Schema $anchor "${anchor}".`); + } +} + +export default InvalidJsonSchema$anchorError; diff --git a/packages/apidom-reference/src/errors/JsonSchema$anchorError.ts b/packages/apidom-reference/src/errors/JsonSchema$anchorError.ts new file mode 100644 index 0000000000..ed89b8c96b --- /dev/null +++ b/packages/apidom-reference/src/errors/JsonSchema$anchorError.ts @@ -0,0 +1,5 @@ +import { ApiDOMError } from '@swagger-api/apidom-error'; + +class JsonSchema$anchorError extends ApiDOMError {} + +export default JsonSchema$anchorError; diff --git a/packages/apidom-reference/src/errors/JsonSchemaUriError.ts b/packages/apidom-reference/src/errors/JsonSchemaUriError.ts new file mode 100644 index 0000000000..2bc032a6c4 --- /dev/null +++ b/packages/apidom-reference/src/errors/JsonSchemaUriError.ts @@ -0,0 +1,5 @@ +import { ApiDOMError } from '@swagger-api/apidom-error'; + +class JsonSchemaUriError extends ApiDOMError {} + +export default JsonSchemaUriError; diff --git a/packages/apidom-reference/src/util/errors/MaximumDereferenceDepthError.ts b/packages/apidom-reference/src/errors/MaximumDereferenceDepthError.ts similarity index 100% rename from packages/apidom-reference/src/util/errors/MaximumDereferenceDepthError.ts rename to packages/apidom-reference/src/errors/MaximumDereferenceDepthError.ts diff --git a/packages/apidom-reference/src/util/errors/MaximumResolverDepthError.ts b/packages/apidom-reference/src/errors/MaximumResolverDepthError.ts similarity index 100% rename from packages/apidom-reference/src/util/errors/MaximumResolverDepthError.ts rename to packages/apidom-reference/src/errors/MaximumResolverDepthError.ts diff --git a/packages/apidom-reference/src/util/errors/ParserError.ts b/packages/apidom-reference/src/errors/ParserError.ts similarity index 100% rename from packages/apidom-reference/src/util/errors/ParserError.ts rename to packages/apidom-reference/src/errors/ParserError.ts diff --git a/packages/apidom-reference/src/util/errors/PluginError.ts b/packages/apidom-reference/src/errors/PluginError.ts similarity index 100% rename from packages/apidom-reference/src/util/errors/PluginError.ts rename to packages/apidom-reference/src/errors/PluginError.ts diff --git a/packages/apidom-reference/src/util/errors/ResolverError.ts b/packages/apidom-reference/src/errors/ResolverError.ts similarity index 100% rename from packages/apidom-reference/src/util/errors/ResolverError.ts rename to packages/apidom-reference/src/errors/ResolverError.ts diff --git a/packages/apidom-reference/src/util/errors/UnmatchedDereferenceStrategyError.ts b/packages/apidom-reference/src/errors/UnmatchedDereferenceStrategyError.ts similarity index 100% rename from packages/apidom-reference/src/util/errors/UnmatchedDereferenceStrategyError.ts rename to packages/apidom-reference/src/errors/UnmatchedDereferenceStrategyError.ts diff --git a/packages/apidom-reference/src/util/errors/UnmatchedResolveStrategyError.ts b/packages/apidom-reference/src/errors/UnmatchedResolveStrategyError.ts similarity index 100% rename from packages/apidom-reference/src/util/errors/UnmatchedResolveStrategyError.ts rename to packages/apidom-reference/src/errors/UnmatchedResolveStrategyError.ts diff --git a/packages/apidom-reference/src/util/errors/UnmatchedResolverError.ts b/packages/apidom-reference/src/errors/UnmatchedResolverError.ts similarity index 100% rename from packages/apidom-reference/src/util/errors/UnmatchedResolverError.ts rename to packages/apidom-reference/src/errors/UnmatchedResolverError.ts diff --git a/packages/apidom-reference/src/index.ts b/packages/apidom-reference/src/index.ts index ff2af411f4..7671bf3e09 100644 --- a/packages/apidom-reference/src/index.ts +++ b/packages/apidom-reference/src/index.ts @@ -27,19 +27,20 @@ export { merge as mergeOptions } from './options/util'; export { default as Reference } from './Reference'; export { default as ReferenceSet } from './ReferenceSet'; -export { - DereferenceError, - InvalidSelectorError, - MaximumDereferenceDepthError, - MaximumResolverDepthError, - NotImplementedError, - ParserError, - PluginError, - ResolverError, - UnmatchedDereferenceStrategyError, - UnmatchedResolveStrategyError, - UnmatchedResolverError, -} from './util/errors'; +export { default as DereferenceError } from './errors/DereferenceError'; +export { default as EvaluationJsonSchema$anchorError } from './errors/EvaluationJsonSchema$anchorError'; +export { default as EvaluationJsonSchemaUriError } from './errors/EvaluationJsonSchemaUriError'; +export { default as InvalidJsonSchema$anchorError } from './errors/InvalidJsonSchema$anchorError'; +export { default as JsonSchema$anchorError } from './errors/JsonSchema$anchorError'; +export { default as JsonSchemaURIError } from './errors/JsonSchemaUriError'; +export { default as MaximumDereferenceDepthError } from './errors/MaximumDereferenceDepthError'; +export { default as MaximumResolverDepthError } from './errors/MaximumResolverDepthError'; +export { default as ParserError } from './errors/ParserError'; +export { default as PluginError } from './errors/PluginError'; +export { default as ResolverError } from './errors/ResolverError'; +export { default as UnmatchedDereferenceStrategyError } from './errors/UnmatchedDereferenceStrategyError'; +export { default as UnmatchedResolveStrategyError } from './errors/UnmatchedResolveStrategyError'; +export { default as UnmatchedResolverError } from './errors/UnmatchedResolverError'; export const readFile = async (uri: string, options = {}): Promise => { const mergedOptions = mergeOptions(defaultOptions, options); diff --git a/packages/apidom-reference/src/parse/index.ts b/packages/apidom-reference/src/parse/index.ts index a913127ea1..93d0dc9ad5 100644 --- a/packages/apidom-reference/src/parse/index.ts +++ b/packages/apidom-reference/src/parse/index.ts @@ -5,7 +5,8 @@ import * as url from '../util/url'; import File from '../util/File'; import * as plugins from '../util/plugins'; import { ReferenceOptions as IReferenceOptions, File as IFile, Parser as IParser } from '../types'; -import { ParserError, UnmatchedResolverError } from '../util/errors'; +import ParserError from '../errors/ParserError'; +import UnmatchedResolverError from '../errors/UnmatchedResolverError'; import { readFile } from '../resolve/util'; /** diff --git a/packages/apidom-reference/src/parse/parsers/Parser.ts b/packages/apidom-reference/src/parse/parsers/Parser.ts index 997602e96e..5372453910 100644 --- a/packages/apidom-reference/src/parse/parsers/Parser.ts +++ b/packages/apidom-reference/src/parse/parsers/Parser.ts @@ -1,8 +1,8 @@ import stampit from 'stampit'; import { ParseResultElement } from '@swagger-api/apidom-core'; +import { NotImplementedError } from '@swagger-api/apidom-error'; import { Parser as IParser } from '../../types'; -import { NotImplementedError } from '../../util/errors'; const Parser: stampit.Stamp = stampit({ props: { @@ -41,10 +41,10 @@ const Parser: stampit.Stamp = stampit({ }, methods: { async canParse(): Promise { - throw new NotImplementedError(); + throw new NotImplementedError('canParse method in Parser stamp is not yet implemented.'); }, async parse(): Promise { - throw new NotImplementedError(); + throw new NotImplementedError('parse method in Parser stamp is not yet implemented.'); }, }, }); diff --git a/packages/apidom-reference/src/parse/parsers/api-design-systems-json/index.ts b/packages/apidom-reference/src/parse/parsers/api-design-systems-json/index.ts index 2e1f1dd6f3..b86397b30a 100644 --- a/packages/apidom-reference/src/parse/parsers/api-design-systems-json/index.ts +++ b/packages/apidom-reference/src/parse/parsers/api-design-systems-json/index.ts @@ -7,7 +7,7 @@ import { detect, } from '@swagger-api/apidom-parser-adapter-api-design-systems-json'; -import { ParserError } from '../../../util/errors'; +import ParserError from '../../../errors/ParserError'; import { File as IFile, Parser as IParser } from '../../../types'; import Parser from '../Parser'; diff --git a/packages/apidom-reference/src/parse/parsers/api-design-systems-yaml/index.ts b/packages/apidom-reference/src/parse/parsers/api-design-systems-yaml/index.ts index 4bbf8769bf..fed9a40047 100644 --- a/packages/apidom-reference/src/parse/parsers/api-design-systems-yaml/index.ts +++ b/packages/apidom-reference/src/parse/parsers/api-design-systems-yaml/index.ts @@ -7,7 +7,7 @@ import { detect, } from '@swagger-api/apidom-parser-adapter-api-design-systems-yaml'; -import { ParserError } from '../../../util/errors'; +import ParserError from '../../../errors/ParserError'; import { File as IFile, Parser as IParser } from '../../../types'; import Parser from '../Parser'; diff --git a/packages/apidom-reference/src/parse/parsers/asyncapi-json-2/index.ts b/packages/apidom-reference/src/parse/parsers/asyncapi-json-2/index.ts index 9311f644fd..67ee68e249 100644 --- a/packages/apidom-reference/src/parse/parsers/asyncapi-json-2/index.ts +++ b/packages/apidom-reference/src/parse/parsers/asyncapi-json-2/index.ts @@ -3,7 +3,7 @@ import { pick } from 'ramda'; import { ParseResultElement } from '@swagger-api/apidom-core'; import { parse, mediaTypes, detect } from '@swagger-api/apidom-parser-adapter-asyncapi-json-2'; -import { ParserError } from '../../../util/errors'; +import ParserError from '../../../errors/ParserError'; import { File as IFile, Parser as IParser } from '../../../types'; import Parser from '../Parser'; diff --git a/packages/apidom-reference/src/parse/parsers/asyncapi-yaml-2/index.ts b/packages/apidom-reference/src/parse/parsers/asyncapi-yaml-2/index.ts index 97135a2fe7..c2b07a9700 100644 --- a/packages/apidom-reference/src/parse/parsers/asyncapi-yaml-2/index.ts +++ b/packages/apidom-reference/src/parse/parsers/asyncapi-yaml-2/index.ts @@ -3,7 +3,7 @@ import { pick } from 'ramda'; import { ParseResultElement } from '@swagger-api/apidom-core'; import { parse, mediaTypes, detect } from '@swagger-api/apidom-parser-adapter-asyncapi-yaml-2'; -import { ParserError } from '../../../util/errors'; +import ParserError from '../../../errors/ParserError'; import { File as IFile, Parser as IParser } from '../../../types'; import Parser from '../Parser'; diff --git a/packages/apidom-reference/src/parse/parsers/binary/index-browser.ts b/packages/apidom-reference/src/parse/parsers/binary/index-browser.ts index 8d72f031cb..875a162529 100644 --- a/packages/apidom-reference/src/parse/parsers/binary/index-browser.ts +++ b/packages/apidom-reference/src/parse/parsers/binary/index-browser.ts @@ -1,7 +1,7 @@ import stampit from 'stampit'; import { ParseResultElement, StringElement } from '@swagger-api/apidom-core'; -import { ParserError } from '../../../util/errors'; +import ParserError from '../../../errors/ParserError'; import { Parser as IParser, File as IFile } from '../../../types'; import Parser from '../Parser'; diff --git a/packages/apidom-reference/src/parse/parsers/binary/index-node.ts b/packages/apidom-reference/src/parse/parsers/binary/index-node.ts index e2d1f34bec..7a70de5bc1 100644 --- a/packages/apidom-reference/src/parse/parsers/binary/index-node.ts +++ b/packages/apidom-reference/src/parse/parsers/binary/index-node.ts @@ -2,7 +2,7 @@ import { Buffer } from '#buffer'; // eslint-disable-line import/order import stampit from 'stampit'; import { ParseResultElement, StringElement } from '@swagger-api/apidom-core'; -import { ParserError } from '../../../util/errors'; +import ParserError from '../../../errors/ParserError'; import { Parser as IParser, File as IFile } from '../../../types'; import Parser from '../Parser'; diff --git a/packages/apidom-reference/src/parse/parsers/json/index.ts b/packages/apidom-reference/src/parse/parsers/json/index.ts index 8b66acb371..63d68f15fb 100644 --- a/packages/apidom-reference/src/parse/parsers/json/index.ts +++ b/packages/apidom-reference/src/parse/parsers/json/index.ts @@ -3,7 +3,7 @@ import { pick } from 'ramda'; import { ParseResultElement } from '@swagger-api/apidom-core'; import { parse, mediaTypes, detect } from '@swagger-api/apidom-parser-adapter-json'; -import { ParserError } from '../../../util/errors'; +import ParserError from '../../../errors/ParserError'; import { Parser as IParser, File as IFile } from '../../../types'; import Parser from '../Parser'; diff --git a/packages/apidom-reference/src/parse/parsers/openapi-json-3-0/index.ts b/packages/apidom-reference/src/parse/parsers/openapi-json-3-0/index.ts index 1e22ad5c8e..756abec5c7 100644 --- a/packages/apidom-reference/src/parse/parsers/openapi-json-3-0/index.ts +++ b/packages/apidom-reference/src/parse/parsers/openapi-json-3-0/index.ts @@ -3,7 +3,7 @@ import { pick } from 'ramda'; import { ParseResultElement } from '@swagger-api/apidom-core'; import { parse, mediaTypes, detect } from '@swagger-api/apidom-parser-adapter-openapi-json-3-0'; -import { ParserError } from '../../../util/errors'; +import ParserError from '../../../errors/ParserError'; import { File as IFile, Parser as IParser } from '../../../types'; import Parser from '../Parser'; diff --git a/packages/apidom-reference/src/parse/parsers/openapi-json-3-1/index.ts b/packages/apidom-reference/src/parse/parsers/openapi-json-3-1/index.ts index e416f10375..c1f434a61f 100644 --- a/packages/apidom-reference/src/parse/parsers/openapi-json-3-1/index.ts +++ b/packages/apidom-reference/src/parse/parsers/openapi-json-3-1/index.ts @@ -3,7 +3,7 @@ import { pick } from 'ramda'; import { ParseResultElement } from '@swagger-api/apidom-core'; import { parse, mediaTypes, detect } from '@swagger-api/apidom-parser-adapter-openapi-json-3-1'; -import { ParserError } from '../../../util/errors'; +import ParserError from '../../../errors/ParserError'; import { File as IFile, Parser as IParser } from '../../../types'; import Parser from '../Parser'; diff --git a/packages/apidom-reference/src/parse/parsers/openapi-yaml-3-0/index.ts b/packages/apidom-reference/src/parse/parsers/openapi-yaml-3-0/index.ts index 760bb726da..54ab3bb816 100644 --- a/packages/apidom-reference/src/parse/parsers/openapi-yaml-3-0/index.ts +++ b/packages/apidom-reference/src/parse/parsers/openapi-yaml-3-0/index.ts @@ -3,7 +3,7 @@ import { pick } from 'ramda'; import { ParseResultElement } from '@swagger-api/apidom-core'; import { parse, mediaTypes, detect } from '@swagger-api/apidom-parser-adapter-openapi-yaml-3-0'; -import { ParserError } from '../../../util/errors'; +import ParserError from '../../../errors/ParserError'; import { File as IFile, Parser as IParser } from '../../../types'; import Parser from '../Parser'; diff --git a/packages/apidom-reference/src/parse/parsers/openapi-yaml-3-1/index.ts b/packages/apidom-reference/src/parse/parsers/openapi-yaml-3-1/index.ts index ea42d3b700..b07ba22f69 100644 --- a/packages/apidom-reference/src/parse/parsers/openapi-yaml-3-1/index.ts +++ b/packages/apidom-reference/src/parse/parsers/openapi-yaml-3-1/index.ts @@ -3,7 +3,7 @@ import { pick } from 'ramda'; import { ParseResultElement } from '@swagger-api/apidom-core'; import { parse, mediaTypes, detect } from '@swagger-api/apidom-parser-adapter-openapi-yaml-3-1'; -import { ParserError } from '../../../util/errors'; +import ParserError from '../../../errors/ParserError'; import { File as IFile, Parser as IParser } from '../../../types'; import Parser from '../Parser'; diff --git a/packages/apidom-reference/src/parse/parsers/yaml-1-2/index.ts b/packages/apidom-reference/src/parse/parsers/yaml-1-2/index.ts index 562cf8748c..e8696d43a5 100644 --- a/packages/apidom-reference/src/parse/parsers/yaml-1-2/index.ts +++ b/packages/apidom-reference/src/parse/parsers/yaml-1-2/index.ts @@ -2,7 +2,7 @@ import stampit from 'stampit'; import { ParseResultElement } from '@swagger-api/apidom-core'; import { parse, mediaTypes, detect } from '@swagger-api/apidom-parser-adapter-yaml-1-2'; -import { ParserError } from '../../../util/errors'; +import ParserError from '../../../errors/ParserError'; import { File as IFile, Parser as IParser } from '../../../types'; import Parser from '../Parser'; diff --git a/packages/apidom-reference/src/resolve/index.ts b/packages/apidom-reference/src/resolve/index.ts index 1fd19d5af9..329f58bbfa 100644 --- a/packages/apidom-reference/src/resolve/index.ts +++ b/packages/apidom-reference/src/resolve/index.ts @@ -11,7 +11,8 @@ import { ReferenceOptions as IReferenceOptions, ReferenceSet as IReferenceSet } import parse from '../parse'; import * as plugins from '../util/plugins'; import File from '../util/File'; -import { ResolverError, UnmatchedResolveStrategyError } from '../util/errors'; +import ResolverError from '../errors/ResolverError'; +import UnmatchedResolveStrategyError from '../errors/UnmatchedResolveStrategyError'; import * as url from '../util/url'; /** diff --git a/packages/apidom-reference/src/resolve/resolvers/HttpResolver.ts b/packages/apidom-reference/src/resolve/resolvers/HttpResolver.ts index 9745a8031d..da5dcf54c6 100644 --- a/packages/apidom-reference/src/resolve/resolvers/HttpResolver.ts +++ b/packages/apidom-reference/src/resolve/resolvers/HttpResolver.ts @@ -1,8 +1,8 @@ import stampit from 'stampit'; +import { NotImplementedError } from '@swagger-api/apidom-error'; import Resolver from './Resolver'; import * as url from '../../util/url'; -import NotImplementedError from '../../util/errors/NotImplementedError'; import { HttpResolver as IHttpResolver, File as IFile } from '../../types'; interface HttpResolverConstructorParameters { @@ -35,11 +35,13 @@ const HttpResolver: stampit.Stamp = stampit(Resolver, { }, async read(): Promise { - throw new NotImplementedError(); + throw new NotImplementedError('read method in HttpResolver stamp is not yet implemented.'); }, getHttpClient(): unknown { - throw new NotImplementedError(); + throw new NotImplementedError( + 'getHttpClient method in HttpResolver stamp is not yet implemented.', + ); }, }, }); diff --git a/packages/apidom-reference/src/resolve/resolvers/Resolver.ts b/packages/apidom-reference/src/resolve/resolvers/Resolver.ts index ed14c30c70..8eb7d4d9a7 100644 --- a/packages/apidom-reference/src/resolve/resolvers/Resolver.ts +++ b/packages/apidom-reference/src/resolve/resolvers/Resolver.ts @@ -1,6 +1,6 @@ import stampit from 'stampit'; +import { NotImplementedError } from '@swagger-api/apidom-error'; -import { NotImplementedError } from '../../util/errors'; import { Resolver as IResolver } from '../../types'; const Resolver: stampit.Stamp = stampit({ @@ -12,7 +12,7 @@ const Resolver: stampit.Stamp = stampit({ return false; }, async read(): Promise { - throw new NotImplementedError(); + throw new NotImplementedError('read method in Resolver stamp is not yet implemented.'); }, }, }); diff --git a/packages/apidom-reference/src/resolve/resolvers/file/index-browser.ts b/packages/apidom-reference/src/resolve/resolvers/file/index-browser.ts index 8e24682cec..a208220153 100644 --- a/packages/apidom-reference/src/resolve/resolvers/file/index-browser.ts +++ b/packages/apidom-reference/src/resolve/resolvers/file/index-browser.ts @@ -2,7 +2,7 @@ import stampit from 'stampit'; import { Resolver as IResolver } from '../../../types'; import Resolver from '../Resolver'; -import { ResolverError } from '../../../util/errors'; +import ResolverError from '../../../errors/ResolverError'; const FileResolver: stampit.Stamp = stampit(Resolver, { init() { diff --git a/packages/apidom-reference/src/resolve/resolvers/file/index-node.ts b/packages/apidom-reference/src/resolve/resolvers/file/index-node.ts index f2cc3588db..526dda80b8 100644 --- a/packages/apidom-reference/src/resolve/resolvers/file/index-node.ts +++ b/packages/apidom-reference/src/resolve/resolvers/file/index-node.ts @@ -6,7 +6,7 @@ import minimatch from 'minimatch'; import { FileResolver as IFileResolver, File as IFile } from '../../../types'; import Resolver from '../Resolver'; import * as url from '../../../util/url'; -import { ResolverError } from '../../../util/errors'; +import ResolverError from '../../../errors/ResolverError'; const FileResolver: stampit.Stamp = stampit(Resolver, { props: { diff --git a/packages/apidom-reference/src/resolve/resolvers/http-axios/index.ts b/packages/apidom-reference/src/resolve/resolvers/http-axios/index.ts index a1a227395e..824bf7fd62 100644 --- a/packages/apidom-reference/src/resolve/resolvers/http-axios/index.ts +++ b/packages/apidom-reference/src/resolve/resolvers/http-axios/index.ts @@ -3,7 +3,7 @@ import { omit, pathOr } from 'ramda'; import { ensureArray } from 'ramda-adjunct'; import axios, { AxiosInstance } from 'axios'; -import ResolverError from '../../../util/errors/ResolverError'; +import ResolverError from '../../../errors/ResolverError'; import { HttpResolver as IHttpResolver, File as IFile } from '../../../types'; import HttpResolver from '../HttpResolver'; diff --git a/packages/apidom-reference/src/resolve/strategies/ResolveStrategy.ts b/packages/apidom-reference/src/resolve/strategies/ResolveStrategy.ts index f08e53ac0c..61693ad3b4 100644 --- a/packages/apidom-reference/src/resolve/strategies/ResolveStrategy.ts +++ b/packages/apidom-reference/src/resolve/strategies/ResolveStrategy.ts @@ -1,7 +1,7 @@ import stampit from 'stampit'; +import { NotImplementedError } from '@swagger-api/apidom-error'; import { ResolveStrategy as IResolveStrategy } from '../../types'; -import { NotImplementedError } from '../../util/errors'; const ResolveStrategy: stampit.Stamp = stampit({ props: { @@ -12,7 +12,9 @@ const ResolveStrategy: stampit.Stamp = stampit({ return false; }, async resolve(): Promise { - throw new NotImplementedError(); + throw new NotImplementedError( + 'resolve method in ResolveStrategy stamp is not yet implemented.', + ); }, }, }); diff --git a/packages/apidom-reference/src/resolve/strategies/asyncapi-2/visitor.ts b/packages/apidom-reference/src/resolve/strategies/asyncapi-2/visitor.ts index cd2f974721..0b22fbcd81 100644 --- a/packages/apidom-reference/src/resolve/strategies/asyncapi-2/visitor.ts +++ b/packages/apidom-reference/src/resolve/strategies/asyncapi-2/visitor.ts @@ -2,6 +2,7 @@ import stampit from 'stampit'; import { propEq, values, has, pipe } from 'ramda'; import { allP } from 'ramda-adjunct'; import { isPrimitiveElement, isStringElement, visit, toValue } from '@swagger-api/apidom-core'; +import { ApiDOMError } from '@swagger-api/apidom-error'; import { evaluate, uriToPointer } from '@swagger-api/apidom-json-pointer'; import { getNodeType, @@ -16,7 +17,8 @@ import { } from '@swagger-api/apidom-ns-asyncapi-2'; import { Reference as IReference } from '../../../types'; -import { MaximumDereferenceDepthError, MaximumResolverDepthError } from '../../../util/errors'; +import MaximumDereferenceDepthError from '../../../errors/MaximumDereferenceDepthError'; +import MaximumResolverDepthError from '../../../errors/MaximumResolverDepthError'; import * as url from '../../../util/url'; import parse from '../../../parse'; import Reference from '../../../Reference'; @@ -146,7 +148,7 @@ const AsyncApi2ResolveVisitor = stampit({ // detect direct or circular reference if (this.indirections.includes(fragment)) { - throw new Error('Recursive Reference Object detected'); + throw new ApiDOMError('Recursive Reference Object detected'); } // detect maximum depth of dereferencing @@ -186,7 +188,7 @@ const AsyncApi2ResolveVisitor = stampit({ // detect direct or indirect reference if (this.indirections.includes(referencedElement)) { - throw new Error('Recursive Channel Item Object reference detected'); + throw new ApiDOMError('Recursive Channel Item Object reference detected'); } // detect maximum depth of dereferencing diff --git a/packages/apidom-reference/src/resolve/strategies/openapi-3-0/visitor.ts b/packages/apidom-reference/src/resolve/strategies/openapi-3-0/visitor.ts index 2f3c374de3..5635ae4508 100644 --- a/packages/apidom-reference/src/resolve/strategies/openapi-3-0/visitor.ts +++ b/packages/apidom-reference/src/resolve/strategies/openapi-3-0/visitor.ts @@ -2,6 +2,7 @@ import stampit from 'stampit'; import { propEq, values, has, pipe } from 'ramda'; import { allP } from 'ramda-adjunct'; import { isPrimitiveElement, isStringElement, visit, toValue } from '@swagger-api/apidom-core'; +import { ApiDOMError } from '@swagger-api/apidom-error'; import { evaluate, uriToPointer } from '@swagger-api/apidom-json-pointer'; import { getNodeType, @@ -19,7 +20,8 @@ import { } from '@swagger-api/apidom-ns-openapi-3-0'; import { Reference as IReference } from '../../../types'; -import { MaximumDereferenceDepthError, MaximumResolverDepthError } from '../../../util/errors'; +import MaximumDereferenceDepthError from '../../../errors/MaximumDereferenceDepthError'; +import MaximumResolverDepthError from '../../../errors/MaximumResolverDepthError'; import * as url from '../../../util/url'; import parse from '../../../parse'; import Reference from '../../../Reference'; @@ -135,7 +137,7 @@ const OpenApi3_0ResolveVisitor = stampit({ // operationRef and operationId are mutually exclusive if (isStringElement(linkElement.operationRef) && isStringElement(linkElement.operationId)) { - throw new Error('LinkElement operationRef and operationId are mutually exclusive.'); + throw new ApiDOMError('LinkElement operationRef and operationId are mutually exclusive.'); } if (isLinkElementExternal(linkElement)) { @@ -163,7 +165,9 @@ const OpenApi3_0ResolveVisitor = stampit({ // value and externalValue fields are mutually exclusive if (exampleElement.hasKey('value') && isStringElement(exampleElement.externalValue)) { - throw new Error('ExampleElement value and externalValue fields are mutually exclusive.'); + throw new ApiDOMError( + 'ExampleElement value and externalValue fields are mutually exclusive.', + ); } const uri = toValue(exampleElement.externalValue); @@ -204,7 +208,7 @@ const OpenApi3_0ResolveVisitor = stampit({ // detect direct or circular reference if (this.indirections.includes(fragment)) { - throw new Error('Recursive Reference Object detected'); + throw new ApiDOMError('Recursive Reference Object detected'); } // detect maximum depth of dereferencing @@ -245,7 +249,7 @@ const OpenApi3_0ResolveVisitor = stampit({ // detect direct or indirect reference if (this.indirections.includes(referencedElement)) { - throw new Error('Recursive Path Item Object reference detected'); + throw new ApiDOMError('Recursive Path Item Object reference detected'); } // detect maximum depth of dereferencing diff --git a/packages/apidom-reference/src/resolve/strategies/openapi-3-1/visitor.ts b/packages/apidom-reference/src/resolve/strategies/openapi-3-1/visitor.ts index 28cd1a9ded..03d1e45389 100644 --- a/packages/apidom-reference/src/resolve/strategies/openapi-3-1/visitor.ts +++ b/packages/apidom-reference/src/resolve/strategies/openapi-3-1/visitor.ts @@ -2,6 +2,7 @@ import stampit from 'stampit'; import { propEq, values, has, pipe, none } from 'ramda'; import { allP } from 'ramda-adjunct'; import { isPrimitiveElement, isStringElement, visit, toValue } from '@swagger-api/apidom-core'; +import { ApiDOMError } from '@swagger-api/apidom-error'; import { evaluate as jsonPointerEvaluate, uriToPointer } from '@swagger-api/apidom-json-pointer'; import { getNodeType, @@ -21,7 +22,9 @@ import { } from '@swagger-api/apidom-ns-openapi-3-1'; import { Reference as IReference, Resolver as IResolver } from '../../../types'; -import { MaximumDereferenceDepthError, MaximumResolverDepthError } from '../../../util/errors'; +import MaximumDereferenceDepthError from '../../../errors/MaximumDereferenceDepthError'; +import MaximumResolverDepthError from '../../../errors/MaximumResolverDepthError'; +import EvaluationJsonSchemaUriError from '../../../errors/EvaluationJsonSchemaUriError'; import * as url from '../../../util/url'; import parse from '../../../parse'; import Reference from '../../../Reference'; @@ -33,7 +36,6 @@ import { isAnchor, uriToAnchor, } from '../../../dereference/strategies/openapi-3-1/selectors/$anchor'; -import EvaluationJsonSchemaUriError from '../../../dereference/strategies/openapi-3-1/selectors/uri/errors/EvaluationJsonSchemaUriError'; // @ts-ignore const visitAsync = visit[Symbol.for('nodejs.util.promisify.custom')]; @@ -148,7 +150,7 @@ const OpenApi3_1ResolveVisitor = stampit({ // operationRef and operationId are mutually exclusive if (isStringElement(linkElement.operationRef) && isStringElement(linkElement.operationId)) { - throw new Error('LinkElement operationRef and operationId are mutually exclusive.'); + throw new ApiDOMError('LinkElement operationRef and operationId are mutually exclusive.'); } if (isLinkElementExternal(linkElement)) { @@ -176,7 +178,9 @@ const OpenApi3_1ResolveVisitor = stampit({ // value and externalValue fields are mutually exclusive if (exampleElement.hasKey('value') && isStringElement(exampleElement.externalValue)) { - throw new Error('ExampleElement value and externalValue fields are mutually exclusive.'); + throw new ApiDOMError( + 'ExampleElement value and externalValue fields are mutually exclusive.', + ); } const uri = toValue(exampleElement.externalValue); @@ -275,7 +279,7 @@ const OpenApi3_1ResolveVisitor = stampit({ // detect direct or circular reference if (this.indirections.includes(fragment)) { - throw new Error('Recursive Reference Object detected'); + throw new ApiDOMError('Recursive Reference Object detected'); } // detect maximum depth of dereferencing @@ -316,7 +320,7 @@ const OpenApi3_1ResolveVisitor = stampit({ // detect direct or indirect reference if (this.indirections.includes(referencedElement)) { - throw new Error('Recursive Path Item Object reference detected'); + throw new ApiDOMError('Recursive Path Item Object reference detected'); } // detect maximum depth of dereferencing @@ -406,7 +410,7 @@ const OpenApi3_1ResolveVisitor = stampit({ // detect direct or indirect reference if (this.indirections.includes(referencedElement)) { - throw new Error('Recursive Schema Object reference detected'); + throw new ApiDOMError('Recursive Schema Object reference detected'); } // detect maximum depth of dereferencing diff --git a/packages/apidom-reference/src/resolve/util.ts b/packages/apidom-reference/src/resolve/util.ts index 9c2023fb3a..0a825d3cfd 100644 --- a/packages/apidom-reference/src/resolve/util.ts +++ b/packages/apidom-reference/src/resolve/util.ts @@ -6,7 +6,8 @@ import { Resolver as IResolver, } from '../types'; import * as plugins from '../util/plugins'; -import { ResolverError, UnmatchedResolverError } from '../util/errors'; +import ResolverError from '../errors/ResolverError'; +import UnmatchedResolverError from '../errors/UnmatchedResolverError'; /** * Reads the given file, using the configured resolver plugins. diff --git a/packages/apidom-reference/src/util/errors/InvalidSelectorError.ts b/packages/apidom-reference/src/util/errors/InvalidSelectorError.ts deleted file mode 100644 index b782c820ea..0000000000 --- a/packages/apidom-reference/src/util/errors/InvalidSelectorError.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { ApiDOMError } from '@swagger-api/apidom-error'; - -class InvalidSelectorError extends ApiDOMError {} - -export default InvalidSelectorError; diff --git a/packages/apidom-reference/src/util/errors/NotImplementedError.ts b/packages/apidom-reference/src/util/errors/NotImplementedError.ts deleted file mode 100644 index bf7c777468..0000000000 --- a/packages/apidom-reference/src/util/errors/NotImplementedError.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { ApiDOMError, ApiDOMErrorOptions } from '@swagger-api/apidom-error'; - -class NotImplementedError extends ApiDOMError { - constructor(message = 'Not Implemented', options?: ApiDOMErrorOptions) { - super(message, options); - } -} - -export default NotImplementedError; diff --git a/packages/apidom-reference/src/util/errors/index.ts b/packages/apidom-reference/src/util/errors/index.ts deleted file mode 100644 index 2d94ed0e6f..0000000000 --- a/packages/apidom-reference/src/util/errors/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -export { default as NotImplementedError } from './NotImplementedError'; -export { default as ResolverError } from './ResolverError'; -export { default as UnmatchedResolverError } from './UnmatchedResolverError'; -export { default as ParserError } from './ParserError'; -export { default as UnmatchedResolveStrategyError } from './UnmatchedResolveStrategyError'; -export { default as PluginError } from './PluginError'; -export { default as InvalidSelectorError } from './InvalidSelectorError'; -export { default as MaximumResolverDepthError } from './MaximumResolverDepthError'; -export { default as DereferenceError } from './DereferenceError'; -export { default as UnmatchedDereferenceStrategyError } from './UnmatchedDereferenceStrategyError'; -export { default as MaximumDereferenceDepthError } from './MaximumDereferenceDepthError'; diff --git a/packages/apidom-reference/src/util/plugins.ts b/packages/apidom-reference/src/util/plugins.ts index 85a4688a86..c146e221a0 100644 --- a/packages/apidom-reference/src/util/plugins.ts +++ b/packages/apidom-reference/src/util/plugins.ts @@ -1,7 +1,7 @@ import { invokeArgs } from 'ramda-adjunct'; import { File as IFile } from '../types'; -import { PluginError } from './errors'; +import PluginError from '../errors/PluginError'; /** * Filters the given plugins, returning only the ones return `true` for the given method. diff --git a/packages/apidom-reference/test/dereference/strategies/asyncapi-2/channel-item-object/index.ts b/packages/apidom-reference/test/dereference/strategies/asyncapi-2/channel-item-object/index.ts index 9076c0e5c4..9f199601bb 100644 --- a/packages/apidom-reference/test/dereference/strategies/asyncapi-2/channel-item-object/index.ts +++ b/packages/apidom-reference/test/dereference/strategies/asyncapi-2/channel-item-object/index.ts @@ -5,7 +5,8 @@ import { mediaTypes } from '@swagger-api/apidom-ns-asyncapi-2'; import { loadJsonFile } from '../../../../helpers'; import { dereference } from '../../../../../src'; -import { DereferenceError, MaximumDereferenceDepthError } from '../../../../../src/util/errors'; +import DereferenceError from '../../../../../src/errors/DereferenceError'; +import MaximumDereferenceDepthError from '../../../../../src/errors/MaximumDereferenceDepthError'; const rootFixturePath = path.join(__dirname, 'fixtures'); diff --git a/packages/apidom-reference/test/dereference/strategies/asyncapi-2/reference-object/index.ts b/packages/apidom-reference/test/dereference/strategies/asyncapi-2/reference-object/index.ts index 781b754f3c..bcc8f752d9 100644 --- a/packages/apidom-reference/test/dereference/strategies/asyncapi-2/reference-object/index.ts +++ b/packages/apidom-reference/test/dereference/strategies/asyncapi-2/reference-object/index.ts @@ -6,11 +6,9 @@ import { evaluate } from '@swagger-api/apidom-json-pointer'; import { loadJsonFile } from '../../../../helpers'; import { dereference, resolve } from '../../../../../src'; -import { - DereferenceError, - MaximumDereferenceDepthError, - MaximumResolverDepthError, -} from '../../../../../src/util/errors'; +import DereferenceError from '../../../../../src/errors/DereferenceError'; +import MaximumDereferenceDepthError from '../../../../../src/errors/MaximumDereferenceDepthError'; +import MaximumResolverDepthError from '../../../../../src/errors/MaximumResolverDepthError'; const rootFixturePath = path.join(__dirname, 'fixtures'); diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-0/example-object/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-0/example-object/index.ts index 5f124859fa..5790c03a03 100644 --- a/packages/apidom-reference/test/dereference/strategies/openapi-3-0/example-object/index.ts +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-0/example-object/index.ts @@ -5,7 +5,7 @@ import { mediaTypes } from '@swagger-api/apidom-ns-openapi-3-0'; import { loadJsonFile } from '../../../../helpers'; import { dereference } from '../../../../../src'; -import { DereferenceError } from '../../../../../src/util/errors'; +import DereferenceError from '../../../../../src/errors/DereferenceError'; const rootFixturePath = path.join(__dirname, 'fixtures'); diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-0/link-object/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-0/link-object/index.ts index 617216d6b9..7d9586a513 100644 --- a/packages/apidom-reference/test/dereference/strategies/openapi-3-0/link-object/index.ts +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-0/link-object/index.ts @@ -6,7 +6,7 @@ import { evaluate } from '@swagger-api/apidom-json-pointer'; import { loadJsonFile } from '../../../../helpers'; import { dereference } from '../../../../../src'; -import { DereferenceError } from '../../../../../src/util/errors'; +import DereferenceError from '../../../../../src/errors/DereferenceError'; const rootFixturePath = path.join(__dirname, 'fixtures'); diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-0/path-item-object/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-0/path-item-object/index.ts index 28edb70be0..28e3ebc010 100644 --- a/packages/apidom-reference/test/dereference/strategies/openapi-3-0/path-item-object/index.ts +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-0/path-item-object/index.ts @@ -5,7 +5,8 @@ import { mediaTypes } from '@swagger-api/apidom-ns-openapi-3-0'; import { loadJsonFile } from '../../../../helpers'; import { dereference } from '../../../../../src'; -import { DereferenceError, MaximumDereferenceDepthError } from '../../../../../src/util/errors'; +import DereferenceError from '../../../../../src/errors/DereferenceError'; +import MaximumDereferenceDepthError from '../../../../../src/errors/MaximumDereferenceDepthError'; const rootFixturePath = path.join(__dirname, 'fixtures'); diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-0/reference-object/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-0/reference-object/index.ts index 155cc73cc1..6313fd1939 100644 --- a/packages/apidom-reference/test/dereference/strategies/openapi-3-0/reference-object/index.ts +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-0/reference-object/index.ts @@ -6,11 +6,9 @@ import { evaluate } from '@swagger-api/apidom-json-pointer'; import { loadJsonFile } from '../../../../helpers'; import { resolve, dereference } from '../../../../../src'; -import { - DereferenceError, - MaximumDereferenceDepthError, - MaximumResolverDepthError, -} from '../../../../../src/util/errors'; +import DereferenceError from '../../../../../src/errors/DereferenceError'; +import MaximumDereferenceDepthError from '../../../../../src/errors/MaximumDereferenceDepthError'; +import MaximumResolverDepthError from '../../../../../src/errors/MaximumResolverDepthError'; const rootFixturePath = path.join(__dirname, 'fixtures'); diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1/example-object/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1/example-object/index.ts index 62666c6077..ac354fd830 100644 --- a/packages/apidom-reference/test/dereference/strategies/openapi-3-1/example-object/index.ts +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1/example-object/index.ts @@ -5,7 +5,7 @@ import { mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1'; import { loadJsonFile } from '../../../../helpers'; import { dereference } from '../../../../../src'; -import { DereferenceError } from '../../../../../src/util/errors'; +import DereferenceError from '../../../../../src/errors/DereferenceError'; const rootFixturePath = path.join(__dirname, 'fixtures'); diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1/link-object/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1/link-object/index.ts index cb1e6391dc..7f034238bb 100644 --- a/packages/apidom-reference/test/dereference/strategies/openapi-3-1/link-object/index.ts +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1/link-object/index.ts @@ -6,7 +6,7 @@ import { evaluate } from '@swagger-api/apidom-json-pointer'; import { loadJsonFile } from '../../../../helpers'; import { dereference } from '../../../../../src'; -import { DereferenceError } from '../../../../../src/util/errors'; +import DereferenceError from '../../../../../src/errors/DereferenceError'; const rootFixturePath = path.join(__dirname, 'fixtures'); diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1/path-item-object/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1/path-item-object/index.ts index 339ebe65c3..082def9201 100644 --- a/packages/apidom-reference/test/dereference/strategies/openapi-3-1/path-item-object/index.ts +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1/path-item-object/index.ts @@ -5,7 +5,8 @@ import { mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1'; import { loadJsonFile } from '../../../../helpers'; import { dereference } from '../../../../../src'; -import { DereferenceError, MaximumDereferenceDepthError } from '../../../../../src/util/errors'; +import DereferenceError from '../../../../../src/errors/DereferenceError'; +import MaximumDereferenceDepthError from '../../../../../src/errors/MaximumDereferenceDepthError'; const rootFixturePath = path.join(__dirname, 'fixtures'); diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1/reference-object/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1/reference-object/index.ts index 3cf9167b93..06ff46c785 100644 --- a/packages/apidom-reference/test/dereference/strategies/openapi-3-1/reference-object/index.ts +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1/reference-object/index.ts @@ -6,11 +6,9 @@ import { evaluate } from '@swagger-api/apidom-json-pointer'; import { loadJsonFile } from '../../../../helpers'; import { dereference, dereferenceApiDOM, resolve, parse } from '../../../../../src'; -import { - DereferenceError, - MaximumDereferenceDepthError, - MaximumResolverDepthError, -} from '../../../../../src/util/errors'; +import DereferenceError from '../../../../../src/errors/DereferenceError'; +import MaximumDereferenceDepthError from '../../../../../src/errors/MaximumDereferenceDepthError'; +import MaximumResolverDepthError from '../../../../../src/errors/MaximumResolverDepthError'; import Reference from '../../../../../src/Reference'; import ReferenceSet from '../../../../../src/ReferenceSet'; diff --git a/packages/apidom-reference/test/dereference/strategies/openapi-3-1/schema-object/index.ts b/packages/apidom-reference/test/dereference/strategies/openapi-3-1/schema-object/index.ts index 453414de54..0c1db6aedc 100644 --- a/packages/apidom-reference/test/dereference/strategies/openapi-3-1/schema-object/index.ts +++ b/packages/apidom-reference/test/dereference/strategies/openapi-3-1/schema-object/index.ts @@ -5,15 +5,13 @@ import { isSchemaElement, mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1' import { evaluate } from '@swagger-api/apidom-json-pointer'; import { dereference, parse, Reference, ReferenceSet } from '../../../../../src'; -import { - DereferenceError, - MaximumDereferenceDepthError, - MaximumResolverDepthError, - ResolverError, -} from '../../../../../src/util/errors'; +import DereferenceError from '../../../../../src/errors/DereferenceError'; +import MaximumDereferenceDepthError from '../../../../../src/errors/MaximumDereferenceDepthError'; +import MaximumResolverDepthError from '../../../../../src/errors/MaximumResolverDepthError'; +import ResolverError from '../../../../../src/errors/ResolverError'; +import EvaluationJsonSchema$anchorError from '../../../../../src/errors/EvaluationJsonSchema$anchorError'; +import EvaluationJsonSchemaUriError from '../../../../../src/errors/EvaluationJsonSchemaUriError'; import { loadJsonFile } from '../../../../helpers'; -import { EvaluationJsonSchema$anchorError } from '../../../../../src/dereference/strategies/openapi-3-1/selectors/$anchor/errors'; -import { EvaluationJsonSchemaUriError } from '../../../../../src/dereference/strategies/openapi-3-1/selectors/uri/errors'; const rootFixturePath = path.join(__dirname, 'fixtures'); diff --git a/packages/apidom-reference/test/parse/index.ts b/packages/apidom-reference/test/parse/index.ts index 6fb36c9f17..2bb7858775 100644 --- a/packages/apidom-reference/test/parse/index.ts +++ b/packages/apidom-reference/test/parse/index.ts @@ -7,7 +7,9 @@ import { mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1'; import defaultOptions from '../../src/options'; import { merge as mergeOptions } from '../../src/options/util'; import parse from '../../src/parse'; -import { ParserError, ResolverError, UnmatchedResolverError } from '../../src/util/errors'; +import ParserError from '../../src/errors/ParserError'; +import ResolverError from '../../src/errors/ResolverError'; +import UnmatchedResolverError from '../../src/errors/UnmatchedResolverError'; import OpenApiJson3_1Parser from '../../src/parse/parsers/openapi-json-3-1'; describe('parse', function () { diff --git a/packages/apidom-reference/test/resolve/index.ts b/packages/apidom-reference/test/resolve/index.ts index 4240e9b59d..2d8c4fbf5e 100644 --- a/packages/apidom-reference/test/resolve/index.ts +++ b/packages/apidom-reference/test/resolve/index.ts @@ -4,7 +4,9 @@ import { mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1'; import { resolve, resolveApiDOM, parse } from '../../src'; import FileResolver from '../../src/resolve/resolvers/file/index-node'; -import { UnmatchedResolveStrategyError, ResolverError, ParserError } from '../../src/util/errors'; +import UnmatchedResolveStrategyError from '../../src/errors/UnmatchedResolveStrategyError'; +import ResolverError from '../../src/errors/ResolverError'; +import ParserError from '../../src/errors/ParserError'; import OpenApiJson3_1Parser from '../../src/parse/parsers/openapi-json-3-1'; const fixturePath = path.join( diff --git a/packages/apidom-reference/test/resolve/resolvers/file/index.ts b/packages/apidom-reference/test/resolve/resolvers/file/index.ts index 0be1913333..d8b091f2ff 100644 --- a/packages/apidom-reference/test/resolve/resolvers/file/index.ts +++ b/packages/apidom-reference/test/resolve/resolvers/file/index.ts @@ -2,7 +2,7 @@ import path from 'node:path'; import { assert } from 'chai'; import FileResolver from '../../../../src/resolve/resolvers/file/index-node'; -import { ResolverError } from '../../../../src/util/errors'; +import ResolverError from '../../../../src/errors/ResolverError'; import File from '../../../../src/util/File'; describe('resolve', function () { diff --git a/packages/apidom-reference/test/resolve/resolvers/http-axios/index.ts b/packages/apidom-reference/test/resolve/resolvers/http-axios/index.ts index 3a3f115938..e2f7f70b5f 100644 --- a/packages/apidom-reference/test/resolve/resolvers/http-axios/index.ts +++ b/packages/apidom-reference/test/resolve/resolvers/http-axios/index.ts @@ -6,7 +6,7 @@ import MockAdapter from 'axios-mock-adapter'; import { identity } from 'ramda'; import HttpResolverAxios from '../../../../src/resolve/resolvers/http-axios'; -import { ResolverError } from '../../../../src/util/errors'; +import ResolverError from '../../../../src/errors/ResolverError'; import File from '../../../../src/util/File'; describe('resolve', function () { diff --git a/packages/apidom-reference/test/resolve/strategies/asyncapi-2/channel-item-object/index.ts b/packages/apidom-reference/test/resolve/strategies/asyncapi-2/channel-item-object/index.ts index b16e2f5c50..52fb67ef62 100644 --- a/packages/apidom-reference/test/resolve/strategies/asyncapi-2/channel-item-object/index.ts +++ b/packages/apidom-reference/test/resolve/strategies/asyncapi-2/channel-item-object/index.ts @@ -3,7 +3,8 @@ import { assert } from 'chai'; import { mediaTypes } from '@swagger-api/apidom-ns-asyncapi-2'; import { resolve } from '../../../../../src'; -import { ResolverError, MaximumDereferenceDepthError } from '../../../../../src/util/errors'; +import ResolverError from '../../../../../src/errors/ResolverError'; +import MaximumDereferenceDepthError from '../../../../../src/errors/MaximumDereferenceDepthError'; const rootFixturePath = path.join(__dirname, 'fixtures'); diff --git a/packages/apidom-reference/test/resolve/strategies/asyncapi-2/reference-object/index.ts b/packages/apidom-reference/test/resolve/strategies/asyncapi-2/reference-object/index.ts index 775d9ebf7e..667261caa1 100644 --- a/packages/apidom-reference/test/resolve/strategies/asyncapi-2/reference-object/index.ts +++ b/packages/apidom-reference/test/resolve/strategies/asyncapi-2/reference-object/index.ts @@ -3,11 +3,9 @@ import { assert } from 'chai'; import { mediaTypes } from '@swagger-api/apidom-ns-asyncapi-2'; import { resolve } from '../../../../../src'; -import { - MaximumDereferenceDepthError, - MaximumResolverDepthError, - ResolverError, -} from '../../../../../src/util/errors'; +import MaximumDereferenceDepthError from '../../../../../src/errors/MaximumDereferenceDepthError'; +import MaximumResolverDepthError from '../../../../../src/errors/MaximumResolverDepthError'; +import ResolverError from '../../../../../src/errors/ResolverError'; const rootFixturePath = path.join(__dirname, 'fixtures'); diff --git a/packages/apidom-reference/test/resolve/strategies/openapi-3-0/example-object/index.ts b/packages/apidom-reference/test/resolve/strategies/openapi-3-0/example-object/index.ts index 7cce1f58b5..8950b89f57 100644 --- a/packages/apidom-reference/test/resolve/strategies/openapi-3-0/example-object/index.ts +++ b/packages/apidom-reference/test/resolve/strategies/openapi-3-0/example-object/index.ts @@ -3,7 +3,7 @@ import { assert } from 'chai'; import { mediaTypes } from '@swagger-api/apidom-ns-openapi-3-0'; import { resolve } from '../../../../../src'; -import { ResolverError } from '../../../../../src/util/errors'; +import ResolverError from '../../../../../src/errors/ResolverError'; const rootFixturePath = path.join(__dirname, 'fixtures'); diff --git a/packages/apidom-reference/test/resolve/strategies/openapi-3-0/link-object/index.ts b/packages/apidom-reference/test/resolve/strategies/openapi-3-0/link-object/index.ts index 095fb9b785..54b08319ad 100644 --- a/packages/apidom-reference/test/resolve/strategies/openapi-3-0/link-object/index.ts +++ b/packages/apidom-reference/test/resolve/strategies/openapi-3-0/link-object/index.ts @@ -3,7 +3,7 @@ import { assert } from 'chai'; import { mediaTypes } from '@swagger-api/apidom-ns-openapi-3-0'; import { resolve } from '../../../../../src'; -import { ResolverError } from '../../../../../src/util/errors'; +import ResolverError from '../../../../../src/errors/ResolverError'; const rootFixturePath = path.join(__dirname, 'fixtures'); diff --git a/packages/apidom-reference/test/resolve/strategies/openapi-3-0/path-item-object/index.ts b/packages/apidom-reference/test/resolve/strategies/openapi-3-0/path-item-object/index.ts index b8c81ab1a4..8102a5e195 100644 --- a/packages/apidom-reference/test/resolve/strategies/openapi-3-0/path-item-object/index.ts +++ b/packages/apidom-reference/test/resolve/strategies/openapi-3-0/path-item-object/index.ts @@ -3,7 +3,8 @@ import { assert } from 'chai'; import { mediaTypes } from '@swagger-api/apidom-ns-openapi-3-0'; import { resolve } from '../../../../../src'; -import { MaximumDereferenceDepthError, ResolverError } from '../../../../../src/util/errors'; +import MaximumDereferenceDepthError from '../../../../../src/errors/MaximumDereferenceDepthError'; +import ResolverError from '../../../../../src/errors/ResolverError'; const rootFixturePath = path.join(__dirname, 'fixtures'); diff --git a/packages/apidom-reference/test/resolve/strategies/openapi-3-0/reference-object/index.ts b/packages/apidom-reference/test/resolve/strategies/openapi-3-0/reference-object/index.ts index 7a7ca2e183..e5ccf9e656 100644 --- a/packages/apidom-reference/test/resolve/strategies/openapi-3-0/reference-object/index.ts +++ b/packages/apidom-reference/test/resolve/strategies/openapi-3-0/reference-object/index.ts @@ -3,11 +3,9 @@ import { assert } from 'chai'; import { mediaTypes } from '@swagger-api/apidom-ns-openapi-3-0'; import { resolve } from '../../../../../src'; -import { - MaximumResolverDepthError, - MaximumDereferenceDepthError, - ResolverError, -} from '../../../../../src/util/errors'; +import MaximumResolverDepthError from '../../../../../src/errors/MaximumResolverDepthError'; +import MaximumDereferenceDepthError from '../../../../../src/errors/MaximumDereferenceDepthError'; +import ResolverError from '../../../../../src/errors/ResolverError'; const rootFixturePath = path.join(__dirname, 'fixtures'); diff --git a/packages/apidom-reference/test/resolve/strategies/openapi-3-1/example-object/index.ts b/packages/apidom-reference/test/resolve/strategies/openapi-3-1/example-object/index.ts index 275b7e3e0a..6099a906eb 100644 --- a/packages/apidom-reference/test/resolve/strategies/openapi-3-1/example-object/index.ts +++ b/packages/apidom-reference/test/resolve/strategies/openapi-3-1/example-object/index.ts @@ -3,7 +3,7 @@ import { assert } from 'chai'; import { mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1'; import { resolve } from '../../../../../src'; -import { ResolverError } from '../../../../../src/util/errors'; +import ResolverError from '../../../../../src/errors/ResolverError'; const rootFixturePath = path.join(__dirname, 'fixtures'); diff --git a/packages/apidom-reference/test/resolve/strategies/openapi-3-1/link-object/index.ts b/packages/apidom-reference/test/resolve/strategies/openapi-3-1/link-object/index.ts index ca6066dc0c..624de2ba38 100644 --- a/packages/apidom-reference/test/resolve/strategies/openapi-3-1/link-object/index.ts +++ b/packages/apidom-reference/test/resolve/strategies/openapi-3-1/link-object/index.ts @@ -3,7 +3,7 @@ import { assert } from 'chai'; import { mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1'; import { resolve } from '../../../../../src'; -import { ResolverError } from '../../../../../src/util/errors'; +import ResolverError from '../../../../../src/errors/ResolverError'; const rootFixturePath = path.join(__dirname, 'fixtures'); diff --git a/packages/apidom-reference/test/resolve/strategies/openapi-3-1/path-item-object/index.ts b/packages/apidom-reference/test/resolve/strategies/openapi-3-1/path-item-object/index.ts index ef9ee3a2a7..f887488b90 100644 --- a/packages/apidom-reference/test/resolve/strategies/openapi-3-1/path-item-object/index.ts +++ b/packages/apidom-reference/test/resolve/strategies/openapi-3-1/path-item-object/index.ts @@ -3,7 +3,8 @@ import { assert } from 'chai'; import { mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1'; import { resolve } from '../../../../../src'; -import { MaximumDereferenceDepthError, ResolverError } from '../../../../../src/util/errors'; +import MaximumDereferenceDepthError from '../../../../../src/errors/MaximumDereferenceDepthError'; +import ResolverError from '../../../../../src/errors/ResolverError'; const rootFixturePath = path.join(__dirname, 'fixtures'); diff --git a/packages/apidom-reference/test/resolve/strategies/openapi-3-1/reference-object/index.ts b/packages/apidom-reference/test/resolve/strategies/openapi-3-1/reference-object/index.ts index f0f832cb80..9c2e6e89c1 100644 --- a/packages/apidom-reference/test/resolve/strategies/openapi-3-1/reference-object/index.ts +++ b/packages/apidom-reference/test/resolve/strategies/openapi-3-1/reference-object/index.ts @@ -3,11 +3,9 @@ import { assert } from 'chai'; import { mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1'; import { resolve } from '../../../../../src'; -import { - MaximumResolverDepthError, - MaximumDereferenceDepthError, - ResolverError, -} from '../../../../../src/util/errors'; +import MaximumDereferenceDepthError from '../../../../../src/errors/MaximumDereferenceDepthError'; +import MaximumResolverDepthError from '../../../../../src/errors/MaximumResolverDepthError'; +import ResolverError from '../../../../../src/errors/ResolverError'; const rootFixturePath = path.join(__dirname, 'fixtures'); diff --git a/packages/apidom-reference/test/resolve/strategies/openapi-3-1/schema-object/index.ts b/packages/apidom-reference/test/resolve/strategies/openapi-3-1/schema-object/index.ts index eca3787304..3ef21ab9f4 100644 --- a/packages/apidom-reference/test/resolve/strategies/openapi-3-1/schema-object/index.ts +++ b/packages/apidom-reference/test/resolve/strategies/openapi-3-1/schema-object/index.ts @@ -3,12 +3,10 @@ import { assert } from 'chai'; import { mediaTypes } from '@swagger-api/apidom-ns-openapi-3-1'; import { resolve } from '../../../../../src'; -import { - MaximumDereferenceDepthError, - MaximumResolverDepthError, - ResolverError, -} from '../../../../../src/util/errors'; -import { EvaluationJsonSchema$anchorError } from '../../../../../src/dereference/strategies/openapi-3-1/selectors/$anchor/errors'; +import MaximumDereferenceDepthError from '../../../../../src/errors/MaximumDereferenceDepthError'; +import MaximumResolverDepthError from '../../../../../src/errors/MaximumResolverDepthError'; +import ResolverError from '../../../../../src/errors/ResolverError'; +import EvaluationJsonSchema$anchorError from '../../../../../src/errors/EvaluationJsonSchema$anchorError'; const rootFixturePath = path.join(__dirname, 'fixtures'); diff --git a/packages/apidom-reference/test/util/plugins.ts b/packages/apidom-reference/test/util/plugins.ts index b7d02d4de7..a37563bdd5 100644 --- a/packages/apidom-reference/test/util/plugins.ts +++ b/packages/apidom-reference/test/util/plugins.ts @@ -3,7 +3,7 @@ import { assert } from 'chai'; import File from '../../src/util/File'; import { filter, run } from '../../src/util/plugins'; -import { PluginError } from '../../src/util/errors'; +import PluginError from '../../src/errors/PluginError'; import defaultOptions from '../../src/options'; describe('util', function () {