diff --git a/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/open-api-3-1/example/index.ts b/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/open-api-3-1/example/index.ts index 4977f960f8..b923fa55b6 100644 --- a/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/open-api-3-1/example/index.ts +++ b/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/open-api-3-1/example/index.ts @@ -1,5 +1,6 @@ import stampit from 'stampit'; import { always } from 'ramda'; +import { ObjectElement, isStringElement } from 'apidom'; import ExampleElement from '../../../../elements/Example'; import FallbackVisitor from '../../FallbackVisitor'; @@ -13,6 +14,19 @@ const ExampleVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, { init() { this.element = new ExampleElement(); }, + methods: { + ObjectElement(objectElement: ObjectElement) { + // @ts-ignore + const result = FixedFieldsVisitor.compose.methods.ObjectElement.call(this, objectElement); + + // mark this ExampleElement with reference metadata + if (isStringElement(this.element.externalValue)) { + this.element.classes.push('reference-element'); + } + + return result; + }, + }, }); export default ExampleVisitor; diff --git a/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/open-api-3-1/link/OperationIdVisitor.ts b/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/open-api-3-1/link/OperationIdVisitor.ts index 2f69218814..e89edb4d24 100644 --- a/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/open-api-3-1/link/OperationIdVisitor.ts +++ b/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/open-api-3-1/link/OperationIdVisitor.ts @@ -1,5 +1,17 @@ +import stampit from 'stampit'; +import { StringElement, BREAK } from 'apidom'; + import FallbackVisitor from '../../FallbackVisitor'; -const OperationIdVisitor = FallbackVisitor; +const OperationIdVisitor = stampit(FallbackVisitor, { + methods: { + StringElement(stringElement: StringElement) { + this.element = stringElement.clone(); + this.element.classes.push('reference-value'); + + return BREAK; + }, + }, +}); export default OperationIdVisitor; diff --git a/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/open-api-3-1/link/index.ts b/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/open-api-3-1/link/index.ts index 07766ae30c..8599c9cf49 100644 --- a/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/open-api-3-1/link/index.ts +++ b/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/open-api-3-1/link/index.ts @@ -1,5 +1,6 @@ import stampit from 'stampit'; import { always } from 'ramda'; +import { isStringElement, ObjectElement } from 'apidom'; import LinkElement from '../../../../elements/Link'; import FallbackVisitor from '../../FallbackVisitor'; @@ -13,6 +14,19 @@ const LinkVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, { init() { this.element = new LinkElement(); }, + methods: { + ObjectElement(objectElement: ObjectElement) { + // @ts-ignore + const result = FixedFieldsVisitor.compose.methods.ObjectElement.call(this, objectElement); + + // mark this LinkElement with reference metadata + if (isStringElement(this.element.operationId) || isStringElement(this.element.operationRef)) { + this.element.classes.push('reference-element'); + } + + return result; + }, + }, }); export default LinkVisitor; diff --git a/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/open-api-3-1/path-item/index.ts b/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/open-api-3-1/path-item/index.ts index 473b87df0c..7f4f3b3445 100644 --- a/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/open-api-3-1/path-item/index.ts +++ b/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/open-api-3-1/path-item/index.ts @@ -1,6 +1,6 @@ import stampit from 'stampit'; import { always } from 'ramda'; -import { StringElement, ObjectElement } from 'apidom'; +import { StringElement, ObjectElement, isStringElement } from 'apidom'; import PathItemElement from '../../../../elements/PathItem'; import OperationElement from '../../../../elements/Operation'; @@ -29,6 +29,11 @@ const PathItemVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, { operationElement.setMetaProperty('httpMethod', httpMethodElementCS); }); + // mark this PathItemElement with reference metadata + if (isStringElement(this.element.$ref)) { + this.element.classes.push('reference-element'); + } + return result; }, }, diff --git a/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/open-api-3-1/reference/index.ts b/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/open-api-3-1/reference/index.ts index 7ecc3f7d0e..0aac88ba6d 100644 --- a/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/open-api-3-1/reference/index.ts +++ b/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/open-api-3-1/reference/index.ts @@ -1,5 +1,6 @@ import stampit from 'stampit'; import { always } from 'ramda'; +import { ObjectElement, isStringElement } from 'apidom'; import ReferenceElement from '../../../../elements/Reference'; import FixedFieldsVisitor from '../../generics/FixedFieldsVisitor'; @@ -13,6 +14,19 @@ const ReferenceVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, { init() { this.element = new ReferenceElement(); }, + methods: { + ObjectElement(objectElement: ObjectElement) { + // @ts-ignore + const result = FixedFieldsVisitor.compose.methods.ObjectElement.call(this, objectElement); + + // mark this ReferenceElement with reference metadata + if (isStringElement(this.element.$ref)) { + this.element.classes.push('reference-element'); + } + + return result; + }, + }, }); export default ReferenceVisitor; diff --git a/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/open-api-3-1/schema/index.ts b/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/open-api-3-1/schema/index.ts index 6c01b01769..6460e09385 100644 --- a/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/open-api-3-1/schema/index.ts +++ b/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/open-api-3-1/schema/index.ts @@ -79,14 +79,6 @@ const SchemaVisitor = stampit(FixedFieldsVisitor, ParentSchemaAwareVisitor, Fall this.element.setMetaProperty('inherited$id', inherited$id); }; - const appendReferenceMetadata = (objectElement: ObjectElement) => { - const $ref = objectElement.get('$ref')?.toValue(); - - if (isNonEmptyString($ref)) { - this.element.classes.push('reference-element'); - } - }; - /** * Public Api. */ @@ -94,12 +86,18 @@ const SchemaVisitor = stampit(FixedFieldsVisitor, ParentSchemaAwareVisitor, Fall this.element = new SchemaElement(); handle$schema(objectElement); handle$id(objectElement); - appendReferenceMetadata(objectElement); // for further processing consider this Schema Element as parent for all embedded Schema Elements this.parent = this.element; // @ts-ignore - return FixedFieldsVisitor.compose.methods.ObjectElement.call(this, objectElement); + const result = FixedFieldsVisitor.compose.methods.ObjectElement.call(this, objectElement); + + // mark this SchemaElement with reference metadata + if (isStringElement(this.element.$ref)) { + this.element.classes.push('reference-element'); + } + + return result; }; this.BooleanElement = function _BooleanElement(booleanElement: BooleanElement) { diff --git a/apidom/packages/apidom-ns-openapi-3-1/test/refractor/__snapshots__/index.ts.snap b/apidom/packages/apidom-ns-openapi-3-1/test/refractor/__snapshots__/index.ts.snap index abc2ce0c41..abb19eaea9 100644 --- a/apidom/packages/apidom-ns-openapi-3-1/test/refractor/__snapshots__/index.ts.snap +++ b/apidom/packages/apidom-ns-openapi-3-1/test/refractor/__snapshots__/index.ts.snap @@ -1201,6 +1201,10 @@ exports[`refractor given generic ApiDOM object in OpenApi 3.1 shape should refra { "element": "string", "content": "openapi-reference" + }, + { + "element": "string", + "content": "reference-element" } ] }, @@ -1503,6 +1507,17 @@ exports[`refractor given generic ApiDOM object in OpenApi 3.1 shape should refra }, "value": { "element": "example", + "meta": { + "classes": { + "element": "array", + "content": [ + { + "element": "string", + "content": "reference-element" + } + ] + } + }, "content": [ { "element": "member", @@ -1642,6 +1657,10 @@ exports[`refractor given generic ApiDOM object in OpenApi 3.1 shape should refra { "element": "string", "content": "openapi-reference" + }, + { + "element": "string", + "content": "reference-element" } ] }, @@ -1947,6 +1966,10 @@ exports[`refractor given generic ApiDOM object in OpenApi 3.1 shape should refra { "element": "string", "content": "openapi-reference" + }, + { + "element": "string", + "content": "reference-element" } ] }, @@ -2304,6 +2327,17 @@ exports[`refractor given generic ApiDOM object in OpenApi 3.1 shape should refra }, "value": { "element": "link", + "meta": { + "classes": { + "element": "array", + "content": [ + { + "element": "string", + "content": "reference-element" + } + ] + } + }, "content": [ { "element": "member", @@ -2360,6 +2394,17 @@ exports[`refractor given generic ApiDOM object in OpenApi 3.1 shape should refra }, "value": { "element": "string", + "meta": { + "classes": { + "element": "array", + "content": [ + { + "element": "string", + "content": "reference-value" + } + ] + } + }, "content": "operationId-1" } } @@ -2526,6 +2571,10 @@ exports[`refractor given generic ApiDOM object in OpenApi 3.1 shape should refra { "element": "string", "content": "openapi-reference" + }, + { + "element": "string", + "content": "reference-element" } ] }, @@ -2609,6 +2658,10 @@ exports[`refractor given generic ApiDOM object in OpenApi 3.1 shape should refra { "element": "string", "content": "openapi-reference" + }, + { + "element": "string", + "content": "reference-element" } ] }, @@ -3061,6 +3114,10 @@ exports[`refractor given generic ApiDOM object in OpenApi 3.1 shape should refra { "element": "string", "content": "openapi-reference" + }, + { + "element": "string", + "content": "reference-element" } ] }, @@ -3515,6 +3572,10 @@ exports[`refractor given generic ApiDOM object in OpenApi 3.1 shape should refra { "element": "string", "content": "openapi-reference" + }, + { + "element": "string", + "content": "reference-element" } ] }, @@ -3611,6 +3672,10 @@ exports[`refractor given generic ApiDOM object in OpenApi 3.1 shape should refra { "element": "string", "content": "openapi-reference" + }, + { + "element": "string", + "content": "reference-element" } ] }, @@ -4248,6 +4313,10 @@ exports[`refractor given generic ApiDOM object in OpenApi 3.1 shape should refra { "element": "string", "content": "openapi-reference" + }, + { + "element": "string", + "content": "reference-element" } ] }, @@ -4323,6 +4392,15 @@ exports[`refractor given generic ApiDOM object in OpenApi 3.1 shape should refra "value": { "element": "pathItem", "meta": { + "classes": { + "element": "array", + "content": [ + { + "element": "string", + "content": "reference-element" + } + ] + }, "path": { "element": "string", "content": "/path2" @@ -4633,6 +4711,10 @@ exports[`refractor given generic ApiDOM object in OpenApi 3.1 shape should refra { "element": "string", "content": "openapi-reference" + }, + { + "element": "string", + "content": "reference-element" } ] }, @@ -5145,6 +5227,10 @@ exports[`refractor given generic ApiDOM object in OpenApi 3.1 shape should refra { "element": "string", "content": "openapi-reference" + }, + { + "element": "string", + "content": "reference-element" } ] }, @@ -5490,6 +5576,10 @@ exports[`refractor given generic ApiDOM object in OpenApi 3.1 shape should refra { "element": "string", "content": "openapi-reference" + }, + { + "element": "string", + "content": "reference-element" } ] }, @@ -5594,6 +5684,17 @@ exports[`refractor given generic ApiDOM object in OpenApi 3.1 shape should refra }, "value": { "element": "example", + "meta": { + "classes": { + "element": "array", + "content": [ + { + "element": "string", + "content": "reference-element" + } + ] + } + }, "content": [ { "element": "member", @@ -5733,6 +5834,10 @@ exports[`refractor given generic ApiDOM object in OpenApi 3.1 shape should refra { "element": "string", "content": "openapi-reference" + }, + { + "element": "string", + "content": "reference-element" } ] }, @@ -5917,6 +6022,10 @@ exports[`refractor given generic ApiDOM object in OpenApi 3.1 shape should refra { "element": "string", "content": "openapi-reference" + }, + { + "element": "string", + "content": "reference-element" } ] }, @@ -6141,6 +6250,10 @@ exports[`refractor given generic ApiDOM object in OpenApi 3.1 shape should refra { "element": "string", "content": "openapi-reference" + }, + { + "element": "string", + "content": "reference-element" } ] }, @@ -6471,6 +6584,10 @@ exports[`refractor given generic ApiDOM object in OpenApi 3.1 shape should refra { "element": "string", "content": "openapi-reference" + }, + { + "element": "string", + "content": "reference-element" } ] }, @@ -6631,6 +6748,10 @@ exports[`refractor given generic ApiDOM object in OpenApi 3.1 shape should refra { "element": "string", "content": "openapi-reference" + }, + { + "element": "string", + "content": "reference-element" } ] }, @@ -7083,6 +7204,10 @@ exports[`refractor given generic ApiDOM object in OpenApi 3.1 shape should refra { "element": "string", "content": "openapi-reference" + }, + { + "element": "string", + "content": "reference-element" } ] }, @@ -7342,6 +7467,10 @@ exports[`refractor given generic ApiDOM object in OpenApi 3.1 shape should refra { "element": "string", "content": "openapi-reference" + }, + { + "element": "string", + "content": "reference-element" } ] },