diff --git a/packages/apidom-ns-json-schema-draft-4/src/refractor/visitors/json-schema/index.ts b/packages/apidom-ns-json-schema-draft-4/src/refractor/visitors/json-schema/index.ts index ad064999e3..50d39bf199 100644 --- a/packages/apidom-ns-json-schema-draft-4/src/refractor/visitors/json-schema/index.ts +++ b/packages/apidom-ns-json-schema-draft-4/src/refractor/visitors/json-schema/index.ts @@ -42,6 +42,7 @@ class JSONSchemaVisitor extends Mixin( constructor(options: JSONSchemaVisitorOptions) { super(options); + this.element = new JSONSchemaElement(); this.specPath = always(['document', 'objects', 'JSONSchema']); } @@ -51,7 +52,6 @@ class JSONSchemaVisitor extends Mixin( } ObjectElement(objectElement: ObjectElement) { - this.element = new JSONSchemaElement(); this.handleDialectIdentifier(objectElement); this.handleSchemaIdentifier(objectElement); diff --git a/packages/apidom-ns-json-schema-draft-6/src/refractor/visitors/json-schema/index.ts b/packages/apidom-ns-json-schema-draft-6/src/refractor/visitors/json-schema/index.ts index 771872ed76..cca60b8ab0 100644 --- a/packages/apidom-ns-json-schema-draft-6/src/refractor/visitors/json-schema/index.ts +++ b/packages/apidom-ns-json-schema-draft-6/src/refractor/visitors/json-schema/index.ts @@ -1,6 +1,5 @@ import { ObjectElement, BooleanElement } from '@swagger-api/apidom-core'; import { - FixedFieldsVisitor, JSONSchemaVisitor as JSONSchemaDraft4Visitor, JSONSchemaVisitorOptions, } from '@swagger-api/apidom-ns-json-schema-draft-4'; @@ -15,22 +14,16 @@ export type { JSONSchemaVisitorOptions }; class JSONSchemaVisitor extends JSONSchemaDraft4Visitor { declare public element: JSONSchemaElement; + constructor(options: JSONSchemaVisitorOptions) { + super(options); + this.element = new JSONSchemaElement(); + } + // eslint-disable-next-line class-methods-use-this get defaultDialectIdentifier(): string { return 'http://json-schema.org/draft-06/schema#'; } - ObjectElement(objectElement: ObjectElement) { - this.element = new JSONSchemaElement(); - this.handleDialectIdentifier(objectElement); - this.handleSchemaIdentifier(objectElement); - - // for further processing consider this Schema Element as parent for all embedded Schema Elements - this.parent = this.element; - - return FixedFieldsVisitor.prototype.ObjectElement.call(this, objectElement); - } - BooleanElement(booleanElement: BooleanElement) { const result = this.enter(booleanElement); this.element.classes.push('boolean-json-schema'); @@ -39,11 +32,7 @@ class JSONSchemaVisitor extends JSONSchemaDraft4Visitor { } handleSchemaIdentifier(objectElement: ObjectElement, identifierKeyword: string = '$id'): void { - return JSONSchemaDraft4Visitor.prototype.handleSchemaIdentifier.call( - this, - objectElement, - identifierKeyword, - ); + return super.handleSchemaIdentifier(objectElement, identifierKeyword); } } diff --git a/packages/apidom-ns-json-schema-draft-7/src/index.ts b/packages/apidom-ns-json-schema-draft-7/src/index.ts index 15bb05106e..2bf4072415 100644 --- a/packages/apidom-ns-json-schema-draft-7/src/index.ts +++ b/packages/apidom-ns-json-schema-draft-7/src/index.ts @@ -71,10 +71,9 @@ export type { export { default as JSONSchemaVisitor } from './refractor/visitors/json-schema/index.ts'; export type { JSONSchemaVisitorOptions } from './refractor/visitors/json-schema/index.ts'; -export type { - default as LinkDescriptionVisitor, - LinkDescriptionVisitorOptions, -} from './refractor/visitors/json-schema/link-description/index.ts'; + +export { default as LinkDescriptionVisitor } from './refractor/visitors/json-schema/link-description/index.ts'; +export type { LinkDescriptionVisitorOptions } from './refractor/visitors/json-schema/link-description/index.ts'; export { keyMap, getNodeType } from './traversal/visitor.ts'; diff --git a/packages/apidom-ns-json-schema-draft-7/src/refractor/visitors/json-schema/index.ts b/packages/apidom-ns-json-schema-draft-7/src/refractor/visitors/json-schema/index.ts index 4549ab67f4..c1aef0b8aa 100644 --- a/packages/apidom-ns-json-schema-draft-7/src/refractor/visitors/json-schema/index.ts +++ b/packages/apidom-ns-json-schema-draft-7/src/refractor/visitors/json-schema/index.ts @@ -1,78 +1,27 @@ -import { Mixin } from 'ts-mixer'; -import { always } from 'ramda'; -import { ObjectElement, BooleanElement } from '@swagger-api/apidom-core'; import { - FixedFieldsVisitor, - FixedFieldsVisitorOptions, - ParentSchemaAwareVisitor, - ParentSchemaAwareVisitorOptions, - FallbackVisitor, - FallbackVisitorOptions, - SpecPath, JSONSchemaVisitor as JSONSchemaDraft6Visitor, + JSONSchemaVisitorOptions, } from '@swagger-api/apidom-ns-json-schema-draft-6'; import JSONSchemaElement from '../../../elements/JSONSchema.ts'; -/** - * @public - */ -export interface JSONSchemaVisitorOptions - extends FixedFieldsVisitorOptions, - ParentSchemaAwareVisitorOptions, - FallbackVisitorOptions {} +export type { JSONSchemaVisitorOptions }; /** * @public */ -class JSONSchemaVisitor extends Mixin( - FixedFieldsVisitor, - ParentSchemaAwareVisitor, - FallbackVisitor, -) { +class JSONSchemaVisitor extends JSONSchemaDraft6Visitor { declare public element: JSONSchemaElement; - declare protected readonly specPath: SpecPath<['document', 'objects', 'JSONSchema']>; - constructor(options: JSONSchemaVisitorOptions) { super(options); - this.specPath = always(['document', 'objects', 'JSONSchema']); + this.element = new JSONSchemaElement(); } // eslint-disable-next-line class-methods-use-this get defaultDialectIdentifier(): string { return 'http://json-schema.org/draft-07/schema#'; } - - ObjectElement(objectElement: ObjectElement) { - this.element = new JSONSchemaElement(); - this.handleDialectIdentifier(objectElement); - this.handleSchemaIdentifier(objectElement); - - // for further processing consider this Schema Element as parent for all embedded Schema Elements - this.parent = this.element; - - return FixedFieldsVisitor.prototype.ObjectElement.call(this, objectElement); - } - - BooleanElement(booleanElement: BooleanElement) { - const result = this.enter(booleanElement); - this.element.classes.push('boolean-json-schema'); - - return result; - } - - handleDialectIdentifier(objectElement: ObjectElement): void { - return JSONSchemaDraft6Visitor.prototype.handleDialectIdentifier.call(this, objectElement); - } - - handleSchemaIdentifier(objectElement: ObjectElement, identifierKeyword: string = '$id'): void { - return JSONSchemaDraft6Visitor.prototype.handleSchemaIdentifier.call( - this, - objectElement, - identifierKeyword, - ); - } } export default JSONSchemaVisitor; diff --git a/packages/apidom-ns-json-schema-draft-7/src/refractor/visitors/json-schema/link-description/index.ts b/packages/apidom-ns-json-schema-draft-7/src/refractor/visitors/json-schema/link-description/index.ts index 771036117b..c30b693609 100644 --- a/packages/apidom-ns-json-schema-draft-7/src/refractor/visitors/json-schema/link-description/index.ts +++ b/packages/apidom-ns-json-schema-draft-7/src/refractor/visitors/json-schema/link-description/index.ts @@ -1,34 +1,21 @@ -import { Mixin } from 'ts-mixer'; -import { always } from 'ramda'; import { - FixedFieldsVisitor, - FixedFieldsVisitorOptions, - FallbackVisitor, - FallbackVisitorOptions, - SpecPath, + LinkDescriptionVisitor as JSONSchemaDraft6LinkDescriptionVisitor, + LinkDescriptionVisitorOptions, } from '@swagger-api/apidom-ns-json-schema-draft-6'; import LinkDescriptionElement from '../../../../elements/LinkDescription.ts'; -/** - * @public - */ -export interface LinkDescriptionVisitorOptions - extends FixedFieldsVisitorOptions, - FallbackVisitorOptions {} +export type { LinkDescriptionVisitorOptions }; /** * @public */ -class LinkDescriptionVisitor extends Mixin(FixedFieldsVisitor, FallbackVisitor) { +class LinkDescriptionVisitor extends JSONSchemaDraft6LinkDescriptionVisitor { declare public readonly element: LinkDescriptionElement; - declare protected readonly specPath: SpecPath<['document', 'objects', 'LinkDescription']>; - constructor(options: LinkDescriptionVisitorOptions) { super(options); this.element = new LinkDescriptionElement(); - this.specPath = always(['document', 'objects', 'LinkDescription']); } } diff --git a/packages/apidom-ns-json-schema-draft-7/src/traversal/visitor.ts b/packages/apidom-ns-json-schema-draft-7/src/traversal/visitor.ts index c53b7e8db7..33d6bfa533 100644 --- a/packages/apidom-ns-json-schema-draft-7/src/traversal/visitor.ts +++ b/packages/apidom-ns-json-schema-draft-7/src/traversal/visitor.ts @@ -1,14 +1,6 @@ -import { keyMap as keyMapBase, isElement, Element } from '@swagger-api/apidom-core'; +import { keyMap as keyMapBase } from '@swagger-api/apidom-core'; -/** - * @public - */ -export const getNodeType = (element: T): string | undefined => { - if (!isElement(element)) { - return undefined; - } - return `${element.element.charAt(0).toUpperCase() + element.element.slice(1)}Element`; -}; +export { getNodeType } from '@swagger-api/apidom-ns-json-schema-draft-6'; /** * @public