Skip to content

Commit

Permalink
feat(ns-asyncapi-2): add reference metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
char0n committed Aug 2, 2021
1 parent 5ab586e commit 808073f
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import stampit from 'stampit';
import { always } from 'ramda';
import { ObjectElement, isStringElement } from 'apidom';

import ChannelItemElement from '../../../../elements/ChannelItem';
import FallbackVisitor from '../../FallbackVisitor';
Expand All @@ -13,6 +14,19 @@ const ChannelItemVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, {
init() {
this.element = new ChannelItemElement();
},
methods: {
ObjectElement(objectElement: ObjectElement) {
// @ts-ignore
const result = FixedFieldsVisitor.compose.methods.ObjectElement.call(this, objectElement);

// mark this ChannelItemElement with reference metadata
if (isStringElement(this.element.$ref)) {
this.element.classes.push('reference-element');
}

return result;
},
},
});

export default ChannelItemVisitor;
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,10 @@ exports[`refractor given generic ApiDOM object in AsyncApi 2.0 shape should refr
{
"element": "string",
"content": "asyncapi-reference"
},
{
"element": "string",
"content": "reference-element"
}
]
},
Expand Down Expand Up @@ -2120,6 +2124,10 @@ exports[`refractor given generic ApiDOM object in AsyncApi 2.0 shape should refr
{
"element": "string",
"content": "asyncapi-reference"
},
{
"element": "string",
"content": "reference-element"
}
]
},
Expand Down Expand Up @@ -2199,6 +2207,10 @@ exports[`refractor given generic ApiDOM object in AsyncApi 2.0 shape should refr
{
"element": "string",
"content": "asyncapi-reference"
},
{
"element": "string",
"content": "reference-element"
}
]
},
Expand Down Expand Up @@ -3927,6 +3939,10 @@ exports[`refractor given generic ApiDOM object in AsyncApi 2.0 shape should refr
{
"element": "string",
"content": "asyncapi-reference"
},
{
"element": "string",
"content": "reference-element"
}
]
},
Expand Down Expand Up @@ -4051,6 +4067,17 @@ exports[`refractor given generic ApiDOM object in AsyncApi 2.0 shape should refr
},
"value": {
"element": "channelItem",
"meta": {
"classes": {
"element": "array",
"content": [
{
"element": "string",
"content": "reference-element"
}
]
}
},
"content": [
{
"element": "member",
Expand Down Expand Up @@ -4496,6 +4523,10 @@ exports[`refractor given generic ApiDOM object in AsyncApi 2.0 shape should refr
{
"element": "string",
"content": "asyncapi-reference"
},
{
"element": "string",
"content": "reference-element"
}
]
},
Expand Down Expand Up @@ -4591,6 +4622,10 @@ exports[`refractor given generic ApiDOM object in AsyncApi 2.0 shape should refr
{
"element": "string",
"content": "asyncapi-reference"
},
{
"element": "string",
"content": "reference-element"
}
]
},
Expand Down Expand Up @@ -4672,6 +4707,10 @@ exports[`refractor given generic ApiDOM object in AsyncApi 2.0 shape should refr
{
"element": "string",
"content": "asyncapi-reference"
},
{
"element": "string",
"content": "reference-element"
}
]
},
Expand Down Expand Up @@ -4898,6 +4937,10 @@ exports[`refractor given generic ApiDOM object in AsyncApi 2.0 shape should refr
{
"element": "string",
"content": "asyncapi-reference"
},
{
"element": "string",
"content": "reference-element"
}
]
},
Expand Down Expand Up @@ -4981,6 +5024,10 @@ exports[`refractor given generic ApiDOM object in AsyncApi 2.0 shape should refr
{
"element": "string",
"content": "asyncapi-reference"
},
{
"element": "string",
"content": "reference-element"
}
]
},
Expand Down Expand Up @@ -5170,6 +5217,10 @@ exports[`refractor given generic ApiDOM object in AsyncApi 2.0 shape should refr
{
"element": "string",
"content": "asyncapi-reference"
},
{
"element": "string",
"content": "reference-element"
}
]
},
Expand Down Expand Up @@ -5308,6 +5359,10 @@ exports[`refractor given generic ApiDOM object in AsyncApi 2.0 shape should refr
{
"element": "string",
"content": "asyncapi-reference"
},
{
"element": "string",
"content": "reference-element"
}
]
},
Expand Down Expand Up @@ -5446,6 +5501,10 @@ exports[`refractor given generic ApiDOM object in AsyncApi 2.0 shape should refr
{
"element": "string",
"content": "asyncapi-reference"
},
{
"element": "string",
"content": "reference-element"
}
]
},
Expand Down Expand Up @@ -5683,6 +5742,10 @@ exports[`refractor given generic ApiDOM object in AsyncApi 2.0 shape should refr
{
"element": "string",
"content": "asyncapi-reference"
},
{
"element": "string",
"content": "reference-element"
}
]
},
Expand Down Expand Up @@ -5821,6 +5884,10 @@ exports[`refractor given generic ApiDOM object in AsyncApi 2.0 shape should refr
{
"element": "string",
"content": "asyncapi-reference"
},
{
"element": "string",
"content": "reference-element"
}
]
},
Expand Down Expand Up @@ -5959,6 +6026,10 @@ exports[`refractor given generic ApiDOM object in AsyncApi 2.0 shape should refr
{
"element": "string",
"content": "asyncapi-reference"
},
{
"element": "string",
"content": "reference-element"
}
]
},
Expand Down Expand Up @@ -6097,6 +6168,10 @@ exports[`refractor given generic ApiDOM object in AsyncApi 2.0 shape should refr
{
"element": "string",
"content": "asyncapi-reference"
},
{
"element": "string",
"content": "reference-element"
}
]
},
Expand Down Expand Up @@ -6260,6 +6335,10 @@ exports[`refractor given generic ApiDOM object in AsyncApi 2.0 shape should refr
{
"element": "string",
"content": "asyncapi-reference"
},
{
"element": "string",
"content": "reference-element"
}
]
},
Expand Down Expand Up @@ -6423,6 +6502,10 @@ exports[`refractor given generic ApiDOM object in AsyncApi 2.0 shape should refr
{
"element": "string",
"content": "asyncapi-reference"
},
{
"element": "string",
"content": "reference-element"
}
]
},
Expand Down Expand Up @@ -6586,6 +6669,10 @@ exports[`refractor given generic ApiDOM object in AsyncApi 2.0 shape should refr
{
"element": "string",
"content": "asyncapi-reference"
},
{
"element": "string",
"content": "reference-element"
}
]
},
Expand Down Expand Up @@ -6749,6 +6836,10 @@ exports[`refractor given generic ApiDOM object in AsyncApi 2.0 shape should refr
{
"element": "string",
"content": "asyncapi-reference"
},
{
"element": "string",
"content": "reference-element"
}
]
},
Expand Down

0 comments on commit 808073f

Please sign in to comment.