From b4161b68910351460f9358df3051bfb6360b377d Mon Sep 17 00:00:00 2001 From: Vladimir Gorej Date: Thu, 8 Oct 2020 13:27:11 +0200 Subject: [PATCH] feat(OpenApi3.1-Yaml): add support for Info, License and Contact Refs #1 --- .../apidom-ast/src/nodes/yaml/YamlNode.ts | 5 +- .../apidom-ast/src/nodes/yaml/YamlScalar.ts | 16 +++- .../src/transformers/tree-sitter-yaml.ts | 4 +- .../visitors/open-api-3-1/contact/index.ts | 2 +- .../src/parser/metadata.ts | 11 +++ .../src/parser/specification.ts | 59 ++++++++++++++ .../src/parser/visitors/DocumentVisitor.ts | 10 ++- .../src/parser/visitors/StreamVisitor.ts | 5 -- .../src/parser/visitors/Visitor.ts | 1 + .../generics/FixedFieldsYamlMappingVisitor.ts | 77 +++++++++++++++++++ .../src/parser/visitors/index.ts | 6 +- .../visitors/open-api-3-1/OpenapiVisitor.ts | 18 +++++ .../open-api-3-1/contact/EmailVisitor.ts | 6 ++ .../open-api-3-1/contact/NameVisitor.ts | 7 ++ .../open-api-3-1/contact/UrlVisitor.ts | 7 ++ .../visitors/open-api-3-1/contact/index.ts | 16 ++++ .../src/parser/visitors/open-api-3-1/index.ts | 16 ++++ .../open-api-3-1/info/DescriptionVisitor.ts | 7 ++ .../open-api-3-1/info/SummaryVisitor.ts | 7 ++ .../info/TermsOfServiceVisitor.ts | 7 ++ .../open-api-3-1/info/TitleVisitor.ts | 7 ++ .../open-api-3-1/info/VersionVisitor.ts | 20 +++++ .../visitors/open-api-3-1/info/index.ts | 16 ++++ .../open-api-3-1/license/IdentifierVisitor.ts | 7 ++ .../open-api-3-1/license/NameVisitor.ts | 7 ++ .../open-api-3-1/license/UrlVisitor.ts | 7 ++ .../visitors/open-api-3-1/license/index.ts | 16 ++++ 27 files changed, 350 insertions(+), 17 deletions(-) create mode 100644 apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/metadata.ts create mode 100644 apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/generics/FixedFieldsYamlMappingVisitor.ts create mode 100644 apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/OpenapiVisitor.ts create mode 100644 apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/contact/EmailVisitor.ts create mode 100644 apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/contact/NameVisitor.ts create mode 100644 apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/contact/UrlVisitor.ts create mode 100644 apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/contact/index.ts create mode 100644 apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/index.ts create mode 100644 apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/info/DescriptionVisitor.ts create mode 100644 apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/info/SummaryVisitor.ts create mode 100644 apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/info/TermsOfServiceVisitor.ts create mode 100644 apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/info/TitleVisitor.ts create mode 100644 apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/info/VersionVisitor.ts create mode 100644 apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/info/index.ts create mode 100644 apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/license/IdentifierVisitor.ts create mode 100644 apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/license/NameVisitor.ts create mode 100644 apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/license/UrlVisitor.ts create mode 100644 apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/license/index.ts diff --git a/apidom/packages/apidom-ast/src/nodes/yaml/YamlNode.ts b/apidom/packages/apidom-ast/src/nodes/yaml/YamlNode.ts index b01dda9fe4..c8f5bb0f6a 100644 --- a/apidom/packages/apidom-ast/src/nodes/yaml/YamlNode.ts +++ b/apidom/packages/apidom-ast/src/nodes/yaml/YamlNode.ts @@ -6,7 +6,6 @@ import YamlAnchor from './YamlAnchor'; import { YamlStyle, YamlStyleGroup } from './YamlStyle'; interface YamlNode extends Node { - content: unknown | null; anchor: YamlAnchor | null; tag: YamlTag | null; style: YamlStyle; @@ -15,14 +14,12 @@ interface YamlNode extends Node { const YamlNode: stampit.Stamp = stampit(Node, { props: { - content: null, anchor: null, tag: null, style: null, styleGroup: null, }, - init({ content = null, anchor = null, tag = null, style = null, styleGroup = null } = {}) { - this.content = content; + init({ anchor = null, tag = null, style = null, styleGroup = null } = {}) { this.anchor = anchor; this.tag = tag; this.style = style; diff --git a/apidom/packages/apidom-ast/src/nodes/yaml/YamlScalar.ts b/apidom/packages/apidom-ast/src/nodes/yaml/YamlScalar.ts index b85614913a..1fff84355a 100644 --- a/apidom/packages/apidom-ast/src/nodes/yaml/YamlScalar.ts +++ b/apidom/packages/apidom-ast/src/nodes/yaml/YamlScalar.ts @@ -5,16 +5,28 @@ import YamlNode from './YamlNode'; interface YamlScalar extends YamlNode { type: 'scalar'; format: string | null; - content: string | null; + text: string | null; + readonly content: string | null; } const YamlScalar: stampit.Stamp = stampit(YamlNode, { statics: { type: 'scalar', }, - init({ format = null } = {}) { + props: { + text: null, + }, + init({ text = null, format = null } = {}) { + this.text = text; this.format = format; }, + methods: { + // @ts-ignore + get content() { + // @ts-ignore + return this.text; + }, + }, }); export default YamlScalar; diff --git a/apidom/packages/apidom-ast/src/transformers/tree-sitter-yaml.ts b/apidom/packages/apidom-ast/src/transformers/tree-sitter-yaml.ts index 4832d5d221..936b1f87e8 100644 --- a/apidom/packages/apidom-ast/src/transformers/tree-sitter-yaml.ts +++ b/apidom/packages/apidom-ast/src/transformers/tree-sitter-yaml.ts @@ -146,7 +146,7 @@ const Visitor = stampit({ } return YamlScalar({ - content: '', + text: '', position: Position({ start: surrogatePoint, end: surrogatePoint }), tag, anchor, @@ -410,7 +410,7 @@ const Visitor = stampit({ const anchor = kindNodeToYamlAnchor(node); return YamlScalar({ - content: node.text, + text: node.text, anchor, tag, position, diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/contact/index.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/contact/index.ts index 46ce44c7c8..15e22f3d92 100644 --- a/apidom/packages/apidom-parser-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/contact/index.ts +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/contact/index.ts @@ -9,7 +9,7 @@ const ContactVisitor = stampit(ValueVisitor, FixedFieldsJsonObjectVisitor, { specPath: always(['document', 'objects', 'Contact']), }, init() { - this.element = new this.namespace.elements.License(); + this.element = new this.namespace.elements.Contact(); }, }); diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/metadata.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/metadata.ts new file mode 100644 index 0000000000..5108d12784 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/metadata.ts @@ -0,0 +1,11 @@ +import { Element } from 'minim'; + +// eslint-disable-next-line import/prefer-default-export +export const appendMetadata = (metadata: string[], element: T): T => { + metadata.forEach((md: string) => { + element.classes.push(md); + element.getMetaProperty('symbols', []).push(md); + }); + + return element; +}; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/specification.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/specification.ts index a7d2a9c969..fa66fb5c63 100644 --- a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/specification.ts +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/specification.ts @@ -4,6 +4,22 @@ import DocumentVisitor from './visitors/DocumentVisitor'; import ErrorVisitor from './visitors/ErrorVisitor'; import { ScalarVisitor, MappingVisitor, SequenceVisitor, KindVisitor } from './visitors/generics'; import SpecificationExtensionVisitor from './visitors/SpecificationExtensionVisitor'; +import OpenApi3_1Visitor from './visitors/open-api-3-1'; +import OpenapiVisitor from './visitors/open-api-3-1/OpenapiVisitor'; +import InfoVisitor from './visitors/open-api-3-1/info'; +import InfoTitleVisitor from './visitors/open-api-3-1/info/TitleVisitor'; +import InfoDescriptionVisitor from './visitors/open-api-3-1/info/DescriptionVisitor'; +import InfoSummaryVisitor from './visitors/open-api-3-1/info/SummaryVisitor'; +import InfoTermsOfServiceVisitor from './visitors/open-api-3-1/info/TermsOfServiceVisitor'; +import InfoVersionVisitor from './visitors/open-api-3-1/info/VersionVisitor'; +import ContactVisitor from './visitors/open-api-3-1/contact'; +import ContactNameVisitor from './visitors/open-api-3-1/contact/NameVisitor'; +import ContactUrlVisitor from './visitors/open-api-3-1/contact/UrlVisitor'; +import ContactEmailVisitor from './visitors/open-api-3-1/contact/EmailVisitor'; +import LicenseVisitor from './visitors/open-api-3-1/license'; +import LicenseNameVisitor from './visitors/open-api-3-1/license/NameVisitor'; +import LicenseIdentifierVisitor from './visitors/open-api-3-1/license/IdentifierVisitor'; +import LicenseUrlVisitor from './visitors/open-api-3-1/license/UrlVisitor'; /** * Specification object allows us to have complete control over visitors @@ -25,6 +41,49 @@ const specification = { }, document: { $visitor: DocumentVisitor, + objects: { + OpenApi: { + $visitor: OpenApi3_1Visitor, + fixedFields: { + openapi: OpenapiVisitor, + info: { + $ref: '#/visitors/document/objects/Info', + }, + }, + }, + Info: { + $visitor: InfoVisitor, + fixedFields: { + title: InfoTitleVisitor, + description: InfoDescriptionVisitor, + summary: InfoSummaryVisitor, + termsOfService: InfoTermsOfServiceVisitor, + version: InfoVersionVisitor, + contact: { + $ref: '#/visitors/document/objects/Contact', + }, + license: { + $ref: '#/visitors/document/objects/License', + }, + }, + }, + Contact: { + $visitor: ContactVisitor, + fixedFields: { + name: ContactNameVisitor, + url: ContactUrlVisitor, + email: ContactEmailVisitor, + }, + }, + License: { + $visitor: LicenseVisitor, + fixedFields: { + name: LicenseNameVisitor, + identifier: LicenseIdentifierVisitor, + url: LicenseUrlVisitor, + }, + }, + }, extension: SpecificationExtensionVisitor, }, }, diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/DocumentVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/DocumentVisitor.ts index b80933a96c..0307c9c590 100644 --- a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/DocumentVisitor.ts +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/DocumentVisitor.ts @@ -1,9 +1,15 @@ import stampit from 'stampit'; -import { YamlComment, YamlMapping, YamlScalar, YamlSequence } from 'apidom-ast'; +import { YamlComment, YamlDocument, YamlMapping, YamlScalar, YamlSequence } from 'apidom-ast'; import SpecificationVisitor from './SpecificationVisitor'; const DocumentVisitor = stampit(SpecificationVisitor, { + props: { + keyMap: { + // @ts-ignore + [YamlDocument.type]: ['children'], + }, + }, methods: { scalar(scalarNode: YamlScalar) { const element = this.nodeToElement(['scalar'], scalarNode); @@ -11,7 +17,7 @@ const DocumentVisitor = stampit(SpecificationVisitor, { }, mapping(mappingNode: YamlMapping) { - const openApiElement = this.nodeToElement(['mapping'], mappingNode); + const openApiElement = this.nodeToElement(['document', 'objects', 'OpenApi'], mappingNode); this.element.content.push(openApiElement); }, diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/StreamVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/StreamVisitor.ts index e986501f11..a21872ae71 100644 --- a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/StreamVisitor.ts +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/StreamVisitor.ts @@ -47,12 +47,7 @@ const StreamVisitor = stampit(SpecificationVisitor, { } const documentVisitor = this.retrieveVisitorInstance(['document']); - const keyMap = { - // @ts-ignore - [YamlDocument.type]: ['children'], - }; visit(documentNode, documentVisitor, { - keyMap, // @ts-ignore state: { element: this.element, diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/Visitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/Visitor.ts index d66900a13b..842c4c6783 100644 --- a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/Visitor.ts +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/Visitor.ts @@ -6,6 +6,7 @@ const Visitor = stampit({ element: null, namespace: null, sourceMap: false, + keyMap: null, }, // @ts-ignore init({ namespace = this.namespace, sourceMap = this.sourceMap } = {}) { diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/generics/FixedFieldsYamlMappingVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/generics/FixedFieldsYamlMappingVisitor.ts new file mode 100644 index 0000000000..05006e8f20 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/generics/FixedFieldsYamlMappingVisitor.ts @@ -0,0 +1,77 @@ +import stampit from 'stampit'; +import { noop } from 'ramda-adjunct'; +import { YamlKeyValuePair, YamlMapping } from 'apidom-ast'; +import SpecificationVisitor from '../SpecificationVisitor'; +import { isOpenApiExtension } from '../../predicates'; +import { visit } from '..'; + +const FixedFieldsYamlMappingVisitor = stampit(SpecificationVisitor, { + props: { + specPath: noop, + ignoredFields: [], + keyMap: { + // @ts-ignore + [YamlMapping.type]: ['children'], + }, + canSupportSpecificationExtensions: true, + }, + init({ + // @ts-ignore + specPath = this.specPath, + // @ts-ignore + ignoredFields = this.ignoredFields, + // @ts-ignore + canSupportSpecificationExtensions = this.canSupportSpecificationExtensions, + } = {}) { + this.specPath = specPath; + this.ignoredFields = ignoredFields; + this.canSupportSpecificationExtensions = canSupportSpecificationExtensions; + }, + methods: { + mapping(mappingNode: YamlMapping) { + this.maybeAddSourceMap(mappingNode, this.element); + }, + + keyValuePair(keyValuePairNode: YamlKeyValuePair) { + const specPath = this.specPath(keyValuePairNode); + const fields = this.retrieveFixedFields(specPath); + const { MemberElement } = this.namespace.elements.Element.prototype; + + const { key: keyNode, value: valueNode } = keyValuePairNode; + const keyName = keyNode.content; + + if (fields.includes(keyName) && !this.ignoredFields.includes(keyName)) { + const visitor = this.retrieveVisitorInstance([...specPath, 'fixedFields', keyName]); + const keyElement = new this.namespace.elements.String(keyName); + + visit(keyValuePairNode.value, visitor); + + const memberElement = this.maybeAddSourceMap( + keyValuePairNode, + new MemberElement(this.maybeAddSourceMap(keyNode, keyElement), visitor.element), + ); + memberElement.classes.push('fixedField'); + this.element.content.push(memberElement); + } else if ( + this.canSupportSpecificationExtensions && + isOpenApiExtension({}, keyValuePairNode) + ) { + const visitor = this.retrieveVisitorInstance(['document', 'extension']); + visit(keyValuePairNode, visitor); + this.element.content.push(visitor.element); + } else if (!this.ignoredFields.includes(keyName)) { + const keyElement = new this.namespace.elements.String(keyName); + const memberElement = this.maybeAddSourceMap( + keyValuePairNode, + new MemberElement( + this.maybeAddSourceMap(keyNode, keyElement), + this.nodeToElement(['kind'], valueNode), + ), + ); + this.element.content.push(memberElement); + } + }, + }, +}); + +export default FixedFieldsYamlMappingVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/index.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/index.ts index 186cbfd3f7..2711038cab 100644 --- a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/index.ts +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/index.ts @@ -1,3 +1,4 @@ +import { propOr } from 'ramda'; import { YamlStream, YamlDocument, @@ -29,6 +30,9 @@ const keyMapDefault = { // @ts-ignore export const visit = (root, visitor, { keyMap = keyMapDefault, ...rest } = {}) => { + // if visitor is associated with the keymap, we prefer this visitor keymap + const effectiveKeyMap = propOr(keyMap, 'keyMap', visitor); + // @ts-ignore - return astVisit(root, visitor, { ...rest, keyMap }); + return astVisit(root, visitor, { ...rest, keyMap: effectiveKeyMap }); }; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/OpenapiVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/OpenapiVisitor.ts new file mode 100644 index 0000000000..5f883ead94 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/OpenapiVisitor.ts @@ -0,0 +1,18 @@ +import stampit from 'stampit'; +import { YamlScalar } from 'apidom-ast'; + +import { BREAK } from '..'; +import SpecificationVisitor from '../SpecificationVisitor'; +import { KindVisitor } from '../generics'; + +const OpenapiVisitor = stampit(KindVisitor, SpecificationVisitor, { + methods: { + scalar(scalarNode: YamlScalar) { + const openapiElement = new this.namespace.elements.Openapi(scalarNode.content); + this.element = this.maybeAddSourceMap(scalarNode, openapiElement); + return BREAK; + }, + }, +}); + +export default OpenapiVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/contact/EmailVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/contact/EmailVisitor.ts new file mode 100644 index 0000000000..e399234fa9 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/contact/EmailVisitor.ts @@ -0,0 +1,6 @@ +import stampit from 'stampit'; +import { KindVisitor } from '../../generics'; + +const EmailVisitor = stampit(KindVisitor); + +export default EmailVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/contact/NameVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/contact/NameVisitor.ts new file mode 100644 index 0000000000..ffcae9a0ba --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/contact/NameVisitor.ts @@ -0,0 +1,7 @@ +import stampit from 'stampit'; + +import { KindVisitor } from '../../generics'; + +const NameVisitor = stampit(KindVisitor); + +export default NameVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/contact/UrlVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/contact/UrlVisitor.ts new file mode 100644 index 0000000000..6879e8a7af --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/contact/UrlVisitor.ts @@ -0,0 +1,7 @@ +import stampit from 'stampit'; + +import { KindVisitor } from '../../generics'; + +const UrlVisitor = stampit(KindVisitor); + +export default UrlVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/contact/index.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/contact/index.ts new file mode 100644 index 0000000000..220ab07f40 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/contact/index.ts @@ -0,0 +1,16 @@ +import stampit from 'stampit'; +import { always } from 'ramda'; + +import FixedFieldsYamlMappingVisitor from '../../generics/FixedFieldsYamlMappingVisitor'; +import { KindVisitor } from '../../generics'; + +const ContactVisitor = stampit(KindVisitor, FixedFieldsYamlMappingVisitor, { + props: { + specPath: always(['document', 'objects', 'Contact']), + }, + init() { + this.element = new this.namespace.elements.Contact(); + }, +}); + +export default ContactVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/index.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/index.ts new file mode 100644 index 0000000000..6e302c5e94 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/index.ts @@ -0,0 +1,16 @@ +import stampit from 'stampit'; +import { always } from 'ramda'; + +import { KindVisitor } from '../generics'; +import FixedFieldsYamlMappingVisitor from '../generics/FixedFieldsYamlMappingVisitor'; + +const OpenApi3_1Visitor = stampit(KindVisitor, FixedFieldsYamlMappingVisitor, { + props: { + specPath: always(['document', 'objects', 'OpenApi']), + }, + init() { + this.element = new this.namespace.elements.OpenApi3_1(); + }, +}); + +export default OpenApi3_1Visitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/info/DescriptionVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/info/DescriptionVisitor.ts new file mode 100644 index 0000000000..5a01b32367 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/info/DescriptionVisitor.ts @@ -0,0 +1,7 @@ +import stampit from 'stampit'; + +import { KindVisitor } from '../../generics'; + +const DescriptionVisitor = stampit(KindVisitor); + +export default DescriptionVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/info/SummaryVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/info/SummaryVisitor.ts new file mode 100644 index 0000000000..486de6038c --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/info/SummaryVisitor.ts @@ -0,0 +1,7 @@ +import stampit from 'stampit'; + +import { KindVisitor } from '../../generics'; + +const SummaryVisitor = stampit(KindVisitor); + +export default SummaryVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/info/TermsOfServiceVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/info/TermsOfServiceVisitor.ts new file mode 100644 index 0000000000..4b9028892e --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/info/TermsOfServiceVisitor.ts @@ -0,0 +1,7 @@ +import stampit from 'stampit'; + +import { KindVisitor } from '../../generics'; + +const TermsOfServiceVisitor = stampit(KindVisitor); + +export default TermsOfServiceVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/info/TitleVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/info/TitleVisitor.ts new file mode 100644 index 0000000000..ee54310473 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/info/TitleVisitor.ts @@ -0,0 +1,7 @@ +import stampit from 'stampit'; + +import { KindVisitor } from '../../generics'; + +const TitleVisitor = stampit(KindVisitor); + +export default TitleVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/info/VersionVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/info/VersionVisitor.ts new file mode 100644 index 0000000000..80ef6ac3bc --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/info/VersionVisitor.ts @@ -0,0 +1,20 @@ +import stampit from 'stampit'; +import { YamlScalar } from 'apidom-ast'; + +import { KindVisitor } from '../../generics'; +import { appendMetadata } from '../../../metadata'; + +const VersionVisitor = stampit(KindVisitor, { + methods: { + scalar(scalarNode: YamlScalar) { + // @ts-ignore + const result = KindVisitor.compose.methods.scalar.call(this, scalarNode); + + appendMetadata(['version'], this.element); + + return result; + }, + }, +}); + +export default VersionVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/info/index.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/info/index.ts new file mode 100644 index 0000000000..9c50ff0502 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/info/index.ts @@ -0,0 +1,16 @@ +import stampit from 'stampit'; +import { always } from 'ramda'; + +import { KindVisitor } from '../../generics'; +import FixedFieldsYamlMappingVisitor from '../../generics/FixedFieldsYamlMappingVisitor'; + +const InfoVisitor = stampit(KindVisitor, FixedFieldsYamlMappingVisitor, { + props: { + specPath: always(['document', 'objects', 'Info']), + }, + init() { + this.element = new this.namespace.elements.Info(); + }, +}); + +export default InfoVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/license/IdentifierVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/license/IdentifierVisitor.ts new file mode 100644 index 0000000000..3413e2d1df --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/license/IdentifierVisitor.ts @@ -0,0 +1,7 @@ +import stampit from 'stampit'; + +import { KindVisitor } from '../../generics'; + +const IdentifierVisitor = stampit(KindVisitor); + +export default IdentifierVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/license/NameVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/license/NameVisitor.ts new file mode 100644 index 0000000000..ffcae9a0ba --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/license/NameVisitor.ts @@ -0,0 +1,7 @@ +import stampit from 'stampit'; + +import { KindVisitor } from '../../generics'; + +const NameVisitor = stampit(KindVisitor); + +export default NameVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/license/UrlVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/license/UrlVisitor.ts new file mode 100644 index 0000000000..6879e8a7af --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/license/UrlVisitor.ts @@ -0,0 +1,7 @@ +import stampit from 'stampit'; + +import { KindVisitor } from '../../generics'; + +const UrlVisitor = stampit(KindVisitor); + +export default UrlVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/license/index.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/license/index.ts new file mode 100644 index 0000000000..cad279b024 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/license/index.ts @@ -0,0 +1,16 @@ +import stampit from 'stampit'; +import { always } from 'ramda'; + +import FixedFieldsYamlMappingVisitor from '../../generics/FixedFieldsYamlMappingVisitor'; +import { KindVisitor } from '../../generics'; + +const LicenseVisitor = stampit(KindVisitor, FixedFieldsYamlMappingVisitor, { + props: { + specPath: always(['document', 'objects', 'License']), + }, + init() { + this.element = new this.namespace.elements.License(); + }, +}); + +export default LicenseVisitor;