Skip to content

Commit

Permalink
feat(AsyncApi2.0): add support for MemberElement sourcemaps
Browse files Browse the repository at this point in the history
Refs #71
  • Loading branch information
char0n committed Aug 31, 2020
1 parent cd569e0 commit e419a57
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ const SpecificationExtensionVisitor = stampit(SpecificationVisitor, {
// @ts-ignore
visit(propertyNode.value, valueVisitor, { state });

const memberElement = new MemberElement(
this.maybeAddSourceMap(propertyNode.key, keyElement),
this.maybeAddSourceMap(propertyNode.value, valueVisitor.element),
const memberElement = this.maybeAddSourceMap(
propertyNode,
new MemberElement(
this.maybeAddSourceMap(propertyNode.key, keyElement),
this.maybeAddSourceMap(propertyNode.value, valueVisitor.element),
),
);

if (isAsyncApiExtension({}, propertyNode)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ const AsyncapiVisitor = stampit(SpecificationVisitor, {
const asyncapiElement = new this.namespace.elements.Asyncapi(propertyNode.value.value);
const { MemberElement } = this.namespace.elements.Element.prototype;

this.element = new MemberElement(
this.maybeAddSourceMap(propertyNode.key, keyElement),
this.maybeAddSourceMap(propertyNode.value, asyncapiElement),
this.element = this.maybeAddSourceMap(
propertyNode,
new MemberElement(
this.maybeAddSourceMap(propertyNode.key, keyElement),
this.maybeAddSourceMap(propertyNode.value, asyncapiElement),
),
);
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ const IdentifierVisitor = stampit(SpecificationVisitor, {
const identifierElement = new this.namespace.elements.Identifier(propertyNode.value.value);
const { MemberElement } = this.namespace.elements.Element.prototype;

this.element = new MemberElement(
this.maybeAddSourceMap(propertyNode.key, keyElement),
this.maybeAddSourceMap(propertyNode.value, identifierElement),
this.element = this.maybeAddSourceMap(
propertyNode,
new MemberElement(
this.maybeAddSourceMap(propertyNode.key, keyElement),
this.maybeAddSourceMap(propertyNode.value, identifierElement),
),
);
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,27 @@ import { visit, BREAK } from '..';
import SpecificationVisitor from '../SpecificationVisitor';

const SchemaVisitor = stampit(SpecificationVisitor, {
props: {
keyElement: null,
},
methods: {
key(keyNode) {
this.keyElement = this.maybeAddSourceMap(
this.element.key = this.maybeAddSourceMap(
keyNode,
new this.namespace.elements.String(keyNode.value),
);
},

object(objectNode) {
property(propertyNode) {
const { MemberElement } = this.namespace.elements.Element.prototype;
this.element = this.maybeAddSourceMap(propertyNode, new MemberElement());
},

object(objectNode) {
const objectVisitor = this.retrieveVisitorInstance(['object']);

visit(objectNode, objectVisitor);

const schemaElement = new this.namespace.elements.Schema(objectVisitor.element.content);

this.element = new MemberElement(
this.keyElement,
this.maybeAddSourceMap(objectNode, schemaElement),
);
this.element.value = this.maybeAddSourceMap(objectNode, schemaElement);

return BREAK;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,21 @@ import SpecificationVisitor from '../../SpecificationVisitor';
import { BREAK } from '../..';

const SchemasVisitor = stampit(SpecificationVisitor, {
props: {
keyElement: null,
},
methods: {
key(keyNode) {
this.keyElement = this.maybeAddSourceMap(
this.element.key = this.maybeAddSourceMap(
keyNode,
new this.namespace.elements.String('schemas'),
);
},

property(propertyNode) {
const { MemberElement } = this.namespace.elements.Element.prototype;
this.element = this.maybeAddSourceMap(propertyNode, new MemberElement());
},

object(objectNode) {
const schemasElement = new this.namespace.elements.Object();
const { MemberElement } = this.namespace.elements.Element.prototype;

// @ts-ignore
objectNode.properties.forEach((propertyNode) => {
Expand All @@ -27,10 +28,7 @@ const SchemasVisitor = stampit(SpecificationVisitor, {

schemasElement.classes.push('schemas');

this.element = new MemberElement(
this.keyElement,
this.maybeAddSourceMap(objectNode, schemasElement),
);
this.element.value = this.maybeAddSourceMap(objectNode, schemasElement);

return BREAK;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ import SpecificationVisitor from '../../SpecificationVisitor';
import { isAsyncApiExtension } from '../../../predicates';

const ComponentsVisitor = stampit(SpecificationVisitor, {
props: {
keyElement: null,
},
methods: {
key(keyNode) {
this.keyElement = this.maybeAddSourceMap(
this.element.key = this.maybeAddSourceMap(
keyNode,
new this.namespace.elements.String('components'),
);
},

property(propertyNode) {
const { MemberElement } = this.namespace.elements.Element.prototype;
this.element = this.maybeAddSourceMap(propertyNode, new MemberElement());
},

object(objectNode) {
const componentsElement = new this.namespace.elements.Components();
const { MemberElement } = this.namespace.elements.Element.prototype;
const supportedProps = ['schemas'];

// @ts-ignore
Expand All @@ -36,10 +37,7 @@ const ComponentsVisitor = stampit(SpecificationVisitor, {
}
});

this.element = new MemberElement(
this.keyElement,
this.maybeAddSourceMap(objectNode, componentsElement),
);
this.element.value = this.maybeAddSourceMap(objectNode, componentsElement);

return BREAK;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ import SpecificationVisitor from '../../SpecificationVisitor';
import { isAsyncApiExtension } from '../../../predicates';

const ContactVisitor = stampit(SpecificationVisitor, {
props: {
keyElement: null,
},
methods: {
key(keyNode) {
this.keyElement = this.maybeAddSourceMap(
this.element.key = this.maybeAddSourceMap(
keyNode,
new this.namespace.elements.String('contact'),
);
},

property(propertyNode) {
const { MemberElement } = this.namespace.elements.Element.prototype;
this.element = this.maybeAddSourceMap(propertyNode, new MemberElement());
},

object(objectNode) {
const contactElement = new this.namespace.elements.Contact();
const { MemberElement } = this.namespace.elements.Element.prototype;

// @ts-ignore
objectNode.properties.forEach((propertyNode) => {
Expand All @@ -35,10 +36,7 @@ const ContactVisitor = stampit(SpecificationVisitor, {
}
});

this.element = new MemberElement(
this.keyElement,
this.maybeAddSourceMap(objectNode, contactElement),
);
this.element.value = this.maybeAddSourceMap(objectNode, contactElement);

return BREAK;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ import SpecificationVisitor from '../../SpecificationVisitor';
import { isAsyncApiExtension } from '../../../predicates';

const InfoVisitor = stampit(SpecificationVisitor, {
props: {
keyElement: null,
},
methods: {
key(keyNode) {
this.keyElement = this.maybeAddSourceMap(keyNode, new this.namespace.elements.String('info'));
this.element.key = this.maybeAddSourceMap(
keyNode,
new this.namespace.elements.String('info'),
);
},

property(propertyNode) {
const { MemberElement } = this.namespace.elements.Element.prototype;
this.element = this.maybeAddSourceMap(propertyNode, new MemberElement());
},

object(objectNode) {
const infoElement = new this.namespace.elements.Info();
const { MemberElement } = this.namespace.elements.Element.prototype;
const supportedProps = [
'title',
'description',
Expand All @@ -41,10 +45,7 @@ const InfoVisitor = stampit(SpecificationVisitor, {
}
});

this.element = new MemberElement(
this.keyElement,
this.maybeAddSourceMap(objectNode, infoElement),
);
this.element.value = this.maybeAddSourceMap(objectNode, infoElement);

return BREAK;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ import SpecificationVisitor from '../../SpecificationVisitor';
import { isAsyncApiExtension } from '../../../predicates';

const LicenseVisitor = stampit(SpecificationVisitor, {
props: {
keyElement: null,
},
methods: {
key(keyNode) {
this.keyElement = this.maybeAddSourceMap(
this.element.key = this.maybeAddSourceMap(
keyNode,
new this.namespace.elements.String('license'),
);
},

property(propertyNode) {
const { MemberElement } = this.namespace.elements.Element.prototype;
this.element = this.maybeAddSourceMap(propertyNode, new MemberElement());
},

object(objectNode) {
const licenseElement = new this.namespace.elements.License();
const { MemberElement } = this.namespace.elements.Element.prototype;

// @ts-ignore
objectNode.properties.forEach((propertyNode) => {
Expand All @@ -35,10 +36,7 @@ const LicenseVisitor = stampit(SpecificationVisitor, {
}
});

this.element = new MemberElement(
this.keyElement,
this.maybeAddSourceMap(objectNode, licenseElement),
);
this.element.value = this.maybeAddSourceMap(objectNode, licenseElement);

return BREAK;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,12 @@ export const ObjectVisitor = stampit(SpecificationVisitor).init(function ObjectV
);
} else {
objElement.content.push(
new MemberElement(
this.maybeAddSourceMap(propertyNode.key, keyElement),
this.maybeAddSourceMap(propertyNode.value, valueElement),
this.maybeAddSourceMap(
propertyNode,
new MemberElement(
this.maybeAddSourceMap(propertyNode.key, keyElement),
this.maybeAddSourceMap(propertyNode.value, valueElement),
),
),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ const PropertyVisitor = stampit(SpecificationVisitor, {
: new this.namespace.elements[this.type](propertyNode.value.value);
const { MemberElement } = this.namespace.elements.Element.prototype;

this.element = new MemberElement(
this.maybeAddSourceMap(propertyNode.key, keyElement),
this.maybeAddSourceMap(propertyNode.value, valueElement),
this.element = this.maybeAddSourceMap(
propertyNode,
new MemberElement(
this.maybeAddSourceMap(propertyNode.key, keyElement),
this.maybeAddSourceMap(propertyNode.value, valueElement),
),
);

return BREAK;
Expand Down

0 comments on commit e419a57

Please sign in to comment.