-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ns-json-schema-draft-7): use inheritance for visitors (#4686)
- Loading branch information
Showing
6 changed files
with
20 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 4 additions & 55 deletions
59
packages/apidom-ns-json-schema-draft-7/src/refractor/visitors/json-schema/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
21 changes: 4 additions & 17 deletions
21
...pidom-ns-json-schema-draft-7/src/refractor/visitors/json-schema/link-description/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 2 additions & 10 deletions
12
packages/apidom-ns-json-schema-draft-7/src/traversal/visitor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters