From 13efde8bf0887cbf956b95d2f01b1fcd8e131cb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Gorej?= Date: Sat, 25 Jan 2025 21:26:35 +0100 Subject: [PATCH] refactor(ns-json-schema-2019-09): use inheritance for visitors (#4687) --- .../src/index.ts | 6 +-- .../refractor/visitors/json-schema/index.ts | 49 ++----------------- .../json-schema/link-description/index.ts | 21 ++------ 3 files changed, 11 insertions(+), 65 deletions(-) diff --git a/packages/apidom-ns-json-schema-2019-09/src/index.ts b/packages/apidom-ns-json-schema-2019-09/src/index.ts index 1b595b690..062ece4a2 100644 --- a/packages/apidom-ns-json-schema-2019-09/src/index.ts +++ b/packages/apidom-ns-json-schema-2019-09/src/index.ts @@ -48,10 +48,8 @@ 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 type { default as $defsVisitor, $defsVisitorOptions, diff --git a/packages/apidom-ns-json-schema-2019-09/src/refractor/visitors/json-schema/index.ts b/packages/apidom-ns-json-schema-2019-09/src/refractor/visitors/json-schema/index.ts index 4500c6f6c..bb60b0ace 100644 --- a/packages/apidom-ns-json-schema-2019-09/src/refractor/visitors/json-schema/index.ts +++ b/packages/apidom-ns-json-schema-2019-09/src/refractor/visitors/json-schema/index.ts @@ -1,42 +1,23 @@ -import { Mixin } from 'ts-mixer'; -import { always } from 'ramda'; -import { ObjectElement, BooleanElement, isStringElement } from '@swagger-api/apidom-core'; +import { ObjectElement, isStringElement } from '@swagger-api/apidom-core'; import { FixedFieldsVisitor, - FixedFieldsVisitorOptions, - ParentSchemaAwareVisitor, - ParentSchemaAwareVisitorOptions, - FallbackVisitor, - FallbackVisitorOptions, - SpecPath, JSONSchemaVisitor as JSONSchemaDraft7Visitor, + JSONSchemaVisitorOptions, } from '@swagger-api/apidom-ns-json-schema-draft-7'; 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 JSONSchemaDraft7Visitor { 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 @@ -45,7 +26,6 @@ class JSONSchemaVisitor extends Mixin( } ObjectElement(objectElement: ObjectElement) { - this.element = new JSONSchemaElement(); this.handleDialectIdentifier(objectElement); this.handleSchemaIdentifier(objectElement); @@ -61,25 +41,6 @@ class JSONSchemaVisitor extends Mixin( return result; } - - BooleanElement(booleanElement: BooleanElement) { - const result = this.enter(booleanElement); - this.element.classes.push('boolean-json-schema'); - - return result; - } - - handleDialectIdentifier(objectElement: ObjectElement): void { - return JSONSchemaDraft7Visitor.prototype.handleDialectIdentifier.call(this, objectElement); - } - - handleSchemaIdentifier(objectElement: ObjectElement, identifierKeyword: string = '$id'): void { - return JSONSchemaDraft7Visitor.prototype.handleSchemaIdentifier.call( - this, - objectElement, - identifierKeyword, - ); - } } export default JSONSchemaVisitor; diff --git a/packages/apidom-ns-json-schema-2019-09/src/refractor/visitors/json-schema/link-description/index.ts b/packages/apidom-ns-json-schema-2019-09/src/refractor/visitors/json-schema/link-description/index.ts index acf4b4993..76492f840 100644 --- a/packages/apidom-ns-json-schema-2019-09/src/refractor/visitors/json-schema/link-description/index.ts +++ b/packages/apidom-ns-json-schema-2019-09/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 JSONSchemaDraft7LinkDescriptionVisitor, + LinkDescriptionVisitorOptions, } from '@swagger-api/apidom-ns-json-schema-draft-7'; 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 JSONSchemaDraft7LinkDescriptionVisitor { 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']); } }