diff --git a/apidom/package-lock.json b/apidom/package-lock.json index d29cb9642d..9bd2ee5a8a 100644 --- a/apidom/package-lock.json +++ b/apidom/package-lock.json @@ -3595,6 +3595,21 @@ "web-tree-sitter": "=0.17.0" } }, + "apidom-parser-adapter-asyncapi2-0-yaml": { + "version": "file:packages/apidom-parser-adapter-asyncapi2-0-yaml", + "requires": { + "@apidevtools/json-schema-ref-parser": "=9.0.3", + "apidom": "file:packages/apidom", + "apidom-ast": "file:packages/apidom-ast", + "apidom-ns-asyncapi2-0": "file:packages/apidom-ns-asyncapi2-0", + "ramda": "=0.27.0", + "ramda-adjunct": "=2.27.0", + "stampit": "=4.3.1", + "tree-sitter": "=0.17.0", + "tree-sitter-yaml": "=0.3.0", + "web-tree-sitter": "=0.17.0" + } + }, "apidom-parser-adapter-openapi3-1-json": { "version": "file:packages/apidom-parser-adapter-openapi3-1-json", "requires": { diff --git a/apidom/package.json b/apidom/package.json index 25bd2a784f..a9135878a6 100644 --- a/apidom/package.json +++ b/apidom/package.json @@ -88,6 +88,7 @@ "apidom-ns-openapi3-1": "file:packages/apidom-ns-openapi3-1", "apidom-parser": "file:packages/apidom-parser", "apidom-parser-adapter-asyncapi2-0-json": "file:packages/apidom-parser-adapter-asyncapi2-0-json", + "apidom-parser-adapter-asyncapi2-0-yaml": "file:packages/apidom-parser-adapter-asyncapi2-0-yaml", "apidom-parser-adapter-openapi3-1-json": "file:packages/apidom-parser-adapter-openapi3-1-json", "apidom-parser-adapter-openapi3-1-yaml": "file:packages/apidom-parser-adapter-openapi3-1-yaml" } diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-json/src/adapter.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-json/src/adapter.ts index 13bbae7a4f..88458573cc 100644 --- a/apidom/packages/apidom-parser-adapter-asyncapi2-0-json/src/adapter.ts +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-json/src/adapter.ts @@ -1,7 +1,6 @@ export const mediaTypes = [ 'application/vnd.aai.asyncapi;version=2.0.0', 'application/vnd.aai.asyncapi+json;version=2.0.0', - 'application/vnd.aai.asyncapi+yaml;version=2.0.0', ]; export const detect = (source: string): boolean => diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/.eslintignore b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/.eslintignore new file mode 100644 index 0000000000..a64ca2aac4 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/.eslintignore @@ -0,0 +1,8 @@ +/dist +/es +/lib +/types +/config +/.nyc_output +/node_modules +/**/*.js diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/.gitignore b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/.gitignore new file mode 100644 index 0000000000..a18747d249 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/.gitignore @@ -0,0 +1,4 @@ +/dist +/es +/lib +/types diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/.mocharc.js b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/.mocharc.js new file mode 100644 index 0000000000..a4a860cdec --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/.mocharc.js @@ -0,0 +1,7 @@ +'use strict'; + +module.exports = { + recursive: true, + spec: 'test/**/*.ts', + require: ['test/mocha-bootstrap.js'], +}; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/.npmrc b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/.npmrc new file mode 100644 index 0000000000..4b82d2e7bb --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/.npmrc @@ -0,0 +1,2 @@ +save-prefix="=" +save=false diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/config/webpack/browser.config.js b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/config/webpack/browser.config.js new file mode 100644 index 0000000000..158f585658 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/config/webpack/browser.config.js @@ -0,0 +1,88 @@ +'use strict'; + +const path = require('path'); +const { nonMinimizeTrait, minimizeTrait } = require('./traits.config'); + +const browser = { + mode: 'production', + entry: ['./src/polyfills.ts', './src/adapter-browser.ts'], + target: 'web', + node: { + fs: 'empty', + }, + performance: { + maxEntrypointSize: 712000, + maxAssetSize: 712000, + }, + output: { + path: path.resolve('./dist'), + filename: 'apidom-parser-adapter-asyncapi2-0-yaml.browser.js', + libraryTarget: 'umd', + library: 'apidomParserAdapterAsyncApi2_0Yaml', + }, + resolve: { + extensions: ['.ts', '.mjs', '.js', '.json'], + }, + module: { + rules: [ + { + test: /\.wasm$/, + loader: 'file-loader', + type: 'javascript/auto', + }, + { + test: /\.(ts|js)?$/, + exclude: /node_modules/, + use: { + loader: 'babel-loader', + options: { + babelrc: true, + rootMode: 'upward', + }, + }, + }, + ], + }, + ...nonMinimizeTrait, +}; + +const browserMin = { + mode: 'production', + entry: ['./src/polyfills.ts', './src/adapter-browser.ts'], + target: 'web', + node: { + fs: 'empty', + }, + output: { + path: path.resolve('./dist'), + filename: 'apidom-parser-adapter-asyncapi2-0-yaml.browser.min.js', + libraryTarget: 'umd', + library: 'apidomParserAdapterAsyncApi2_0Yaml', + }, + resolve: { + extensions: ['.ts', '.mjs', '.js', '.json'], + }, + module: { + rules: [ + { + test: /\.wasm$/, + loader: 'file-loader', + type: 'javascript/auto', + }, + { + test: /\.(ts|js)?$/, + exclude: /node_modules/, + use: { + loader: 'babel-loader', + options: { + babelrc: true, + rootMode: 'upward', + }, + }, + }, + ], + }, + ...minimizeTrait, +}; + +module.exports = [browser, browserMin]; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/config/webpack/traits.config.js b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/config/webpack/traits.config.js new file mode 100644 index 0000000000..a1d6167603 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/config/webpack/traits.config.js @@ -0,0 +1,39 @@ +'use strict'; + +const webpack = require('webpack'); +const TerserPlugin = require('terser-webpack-plugin'); + +const nonMinimizeTrait = { + optimization: { + minimize: false, + usedExports: false, + concatenateModules: false, + }, +}; + +const minimizeTrait = { + plugins: [ + new webpack.LoaderOptionsPlugin({ + minimize: true, + }), + ], + optimization: { + minimizer: [ + new TerserPlugin({ + terserOptions: { + compress: { + warnings: false, + }, + output: { + comments: false, + }, + }, + }), + ], + }, +}; + +module.exports = { + nonMinimizeTrait, + minimizeTrait, +}; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/package.json b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/package.json new file mode 100644 index 0000000000..bceccdd71e --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/package.json @@ -0,0 +1,41 @@ +{ + "name": "apidom-parser-adapter-asyncapi2-0-yaml", + "version": "0.1.0", + "description": "AsyncApi 2.0.0 YAML adapter for ApiDOM parser", + "main": "lib/adapter-node.js", + "module": "es/adapter-browser.js", + "jsnext:main": "es/adapter-browser.js", + "browser": "es/adapter-browser.js", + "unpkg": "dist/apidom-parser-apdater-asyncapi2-0-yaml.browser.min.js", + "scripts": { + "build": "npm run build:es && npm run build:commonjs && npm run build:umd:browser", + "build:es": "cross-env BABEL_ENV=es babel src --out-dir es --extensions '.ts' --root-mode 'upward'", + "build:commonjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib --extensions '.ts' --root-mode 'upward'", + "build:umd:browser": "npm run build:wasm && cross-env BABEL_ENV=browser webpack --config config/webpack/browser.config.js --progress", + "build:wasm": "node ../../scripts/file-exists.js ../../node_modules/tree-sitter-yaml/tree-sitter-yaml.wasm && exit 0 || cd ../../node_modules/tree-sitter-yaml && cross-env BABEL_ENV=commonjs NODE_OPTIONS='-r core-js/stable @babel/register' tree-sitter generate ./grammar.js && tree-sitter build-wasm", + "lint": "eslint ./", + "lint:fix": "eslint ./ --fix", + "clean": "rimraf ./es ./lib ./dist tree-sitter-yaml.wasm", + "test": "cross-env BABEL_ENV=commonjs mocha", + "security-audit": "run-s -sc security-audit:prod security-audit:dev", + "security-audit:prod": "npm-audit --production --only=prod --audit-level=low", + "security-audit:dev": "npm-audit --only=dev --audit-level=moderate" + }, + "author": "Vladimir Gorej", + "license": "Apache-2.0", + "dependencies": { + "@apidevtools/json-schema-ref-parser": "=9.0.3", + "apidom": "file:../apidom", + "apidom-ast": "file:../apidom-ast", + "apidom-ns-asyncapi2-0": "file:../apidom-ns-asyncapi2-0", + "ramda": "=0.27.0", + "ramda-adjunct": "=2.27.0", + "stampit": "=4.3.1", + "tree-sitter": "=0.17.0", + "tree-sitter-yaml": "=0.3.0", + "web-tree-sitter": "=0.17.0" + }, + "devDependencies": { + "tree-sitter-cli": "=0.17.0" + } +} diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/adapter-browser.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/adapter-browser.ts new file mode 100644 index 0000000000..3d418c68d2 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/adapter-browser.ts @@ -0,0 +1,2 @@ +export { default as parse, namespace } from './parser/index-browser'; +export { detect, mediaTypes } from './adapter'; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/adapter-node.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/adapter-node.ts new file mode 100644 index 0000000000..a88c94f9ed --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/adapter-node.ts @@ -0,0 +1,2 @@ +export { default as parse, namespace } from './parser/index-node'; +export { mediaTypes, detect } from './adapter'; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/adapter.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/adapter.ts new file mode 100644 index 0000000000..2812a929d1 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/adapter.ts @@ -0,0 +1,7 @@ +export const mediaTypes = [ + 'application/vnd.aai.asyncapi;version=2.0.0', + 'application/vnd.aai.asyncapi+yaml;version=2.0.0', +]; + +export const detect = (source: string): boolean => + !!source.match(/(["']?)asyncapi\1\s*:\s*(["']?)3\.\d+\.\d+\2/g); diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/index-browser-patch.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/index-browser-patch.ts new file mode 100644 index 0000000000..7eec50c4d0 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/index-browser-patch.ts @@ -0,0 +1,15 @@ +import { tail } from 'ramda'; +import { isString } from 'ramda-adjunct'; +// @ts-ignore +import treeSitterWasm from 'web-tree-sitter/tree-sitter.wasm'; + +// patch fetch() to let emscripten load the WASM file +const realFetch = window.fetch; +window.fetch = (...args) => { + // @ts-ignore + if (isString(args[0]) && args[0].endsWith('/tree-sitter.wasm')) { + // @ts-ignore + return realFetch.apply(window, [treeSitterWasm, tail(args)]); + } + return realFetch.apply(window, args); +}; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/index-browser.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/index-browser.ts new file mode 100644 index 0000000000..597db23038 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/index-browser.ts @@ -0,0 +1,29 @@ +import './index-browser-patch'; + +import Parser from 'web-tree-sitter'; +import * as apiDOM from 'apidom'; +// @ts-ignore +import treeSitterYaml from 'tree-sitter-yaml/tree-sitter-yaml.wasm'; + +import parse from '.'; + +export { namespace } from './index'; + +const parserP = (async () => { + await Parser.init(); + const YamlLanguage = await Parser.Language.load(treeSitterYaml); + const parser = new Parser(); + parser.setLanguage(YamlLanguage); + return parser; +})(); + +const parseBrowser = async ( + source: string, + options: Record = {}, +): Promise => { + const parser = await parserP; + // @ts-ignore + return parse(source, { ...options, parser }); +}; + +export default parseBrowser; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/index-node.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/index-node.ts new file mode 100644 index 0000000000..734afb6449 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/index-node.ts @@ -0,0 +1,21 @@ +import Parser from 'tree-sitter'; +// @ts-ignore +import YAMLLanguage from 'tree-sitter-yaml'; +import * as apiDOM from 'apidom'; + +import parse from '.'; + +export { namespace } from './index'; + +const parseNode = async ( + source: string, + options: Record = {}, +): Promise => { + const parser = new Parser(); + parser.setLanguage(YAMLLanguage); + + // @ts-ignore + return parse(source, { ...options, parser }); +}; + +export default parseNode; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/index.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/index.ts new file mode 100644 index 0000000000..eb6a226dc8 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/index.ts @@ -0,0 +1,62 @@ +import $RefParser from '@apidevtools/json-schema-ref-parser'; +import { createNamespace, ParseResultElement } from 'apidom'; +import { + Error, + YamlStream, + YamlDocument, + YamlMapping, + YamlSequence, + YamlKeyValuePair, + transformTreeSitterYamlCST, +} from 'apidom-ast'; +import asyncapi2_0 from 'apidom-ns-asyncapi2-0'; + +import specification from './specification'; +import { visit } from './visitors'; + +export const namespace = createNamespace(asyncapi2_0); + +const parse = async ( + source: string, + { sourceMap = false, specObj = specification, parser = null } = {}, +): Promise => { + const resolvedSpecObj = await $RefParser.dereference(specObj); + // @ts-ignore + const parseResultElement = new namespace.elements.ParseResult(); + // @ts-ignore + const streamVisitor = resolvedSpecObj.visitors.stream.$visitor(); + + // @ts-ignore + const cst = parser.parse(source); + const ast = transformTreeSitterYamlCST(cst); + + const keyMap = { + // @ts-ignore + [YamlStream.type]: ['children'], + // @ts-ignore + [YamlDocument.type]: ['children'], + // @ts-ignore + [YamlMapping.type]: ['children'], + // @ts-ignore + [YamlSequence.type]: ['children'], + // @ts-ignore + [YamlKeyValuePair.type]: ['children'], + // @ts-ignore + [Error.type]: ['children'], + }; + + visit(ast.rootNode, streamVisitor, { + keyMap, + // @ts-ignore + state: { + namespace, + specObj: resolvedSpecObj, + sourceMap, + element: parseResultElement, + }, + }); + + return parseResultElement; +}; + +export default parse; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/metadata.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/metadata.ts new file mode 100644 index 0000000000..5108d12784 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-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-asyncapi2-0-yaml/src/parser/predicates.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/predicates.ts new file mode 100644 index 0000000000..2ba5640e92 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/predicates.ts @@ -0,0 +1,8 @@ +import { pathSatisfies, startsWith, both, curry } from 'ramda'; +import { isYamlKeyValuePair } from 'apidom-ast'; + +// isAsyncApiExtension :: (Options, YamlKeyValuePair) -> Boolean +// eslint-disable-next-line import/prefer-default-export +export const isAsyncApiExtension = curry((options, node) => + both(isYamlKeyValuePair, pathSatisfies(startsWith('x-'), ['key', 'content']))(node), +); diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/source-map.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/source-map.ts new file mode 100644 index 0000000000..86cc2b19ec --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/source-map.ts @@ -0,0 +1,20 @@ +import { namespace } from 'apidom'; + +/* eslint-disable import/prefer-default-export */ + +// @ts-ignore +export const addSourceMap = (node, element) => { + if (node === null) { + return element; + } + + // @ts-ignore + const sourceMap = new namespace.elements.SourceMap(); + + sourceMap.position = node.position; + sourceMap.astNode = node; + + element.meta.set('sourceMap', sourceMap); + + return element; +}; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/specification.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/specification.ts new file mode 100644 index 0000000000..04402b2d2e --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/specification.ts @@ -0,0 +1,200 @@ +import StreamVisitor from './visitors/StreamVisitor'; +import DocumentVisitor from './visitors/DocumentVisitor'; +import AsyncApi2_0Visitor from './visitors/async-api-2-0'; +import SpecificationExtensionVisitor from './visitors/SpecificationExtensionVisitor'; +import AsyncapiVisitor from './visitors/async-api-2-0/AsyncapiVisitor'; +import IdentifierVisitor from './visitors/async-api-2-0/IdentifierVisitor'; +import InfoVisitor from './visitors/async-api-2-0/info'; +import InfoTitleVisitor from './visitors/async-api-2-0/info/TitleVisitor'; +import InfoDescriptionVisitor from './visitors/async-api-2-0/info/DescriptionVisitor'; +import InfoSummaryVisitor from './visitors/async-api-2-0/info/SummaryVisitor'; +import InfoTermsOfServiceVisitor from './visitors/async-api-2-0/info/TermsOfServiceVisitor'; +import InfoVersionVisitor from './visitors/async-api-2-0/info/VersionVisitor'; +import ContactVisitor from './visitors/async-api-2-0/contact'; +import ContactNameVisitor from './visitors/async-api-2-0/contact/NameVisitor'; +import ContactUrlVisitor from './visitors/async-api-2-0/contact/UrlVisitor'; +import ContactEmailVisitor from './visitors/async-api-2-0/contact/EmailVisitor'; +import LicenseVisitor from './visitors/async-api-2-0/license'; +import LicenseNameVisitor from './visitors/async-api-2-0/license/NameVisitor'; +import LicenseUrlVisitor from './visitors/async-api-2-0/license/UrlVisitor'; +import ErrorVisitor from './visitors/ErrorVisitor'; +import SchemaVisitor from './visitors/async-api-2-0/schema'; +import ComponentsVisitor from './visitors/async-api-2-0/components'; +import SchemasVisitor from './visitors/async-api-2-0/components/SchemasVisitor'; +import ChannelsVisitor from './visitors/async-api-2-0/channels'; +import ChannelItemVisitor from './visitors/async-api-2-0/channel-item'; +import ChannelItem$RefVisitor from './visitors/async-api-2-0/channel-item/$RefVisitor'; +import ChannelItemDescriptionVisitor from './visitors/async-api-2-0/channel-item/DescriptionVisitor'; +import ChannelBindingsVisitor from './visitors/async-api-2-0/channel-bindings'; +import OperationVisitor from './visitors/async-api-2-0/operation'; +import ParametersVisitor from './visitors/async-api-2-0/parameters'; +import ServersVisitor from './visitors/async-api-2-0/servers'; +import ServerVisitor from './visitors/async-api-2-0/server'; +import ServerUrlVisitor from './visitors/async-api-2-0/server/UrlVisitor'; +import ServerProtocolVisitor from './visitors/async-api-2-0/server/ProtocolVisitor'; +import ServerProtocolVersionVisitor from './visitors/async-api-2-0/server/ProtocolVersionVisitor'; +import ServerDescriptionVisitor from './visitors/async-api-2-0/server/DescriptionVisitor'; +import ServerVariablesVisitor from './visitors/async-api-2-0/server/VariablesVisitor'; +import ServerSecurityVisitor from './visitors/async-api-2-0/server/SecurityVisitor'; +import ServerVariableVisitor from './visitors/async-api-2-0/server-variable'; +import ServerVariableEnumVisitor from './visitors/async-api-2-0/server-variable/EnumVisitor'; +import ServerVariableDefaultVisitor from './visitors/async-api-2-0/server-variable/DefaultVisitor'; +import ServerVariableDescriptionVisitor from './visitors/async-api-2-0/server-variable/DescriptionVisitor'; +import ServerVariableExamplesVisitor from './visitors/async-api-2-0/server-variable/ExamplesVisitor'; +import ServerBindingsVisitor from './visitors/async-api-2-0/server-bindings'; +import SecurityRequirementVisitor from './visitors/async-api-2-0/security-requirement'; +import { KindVisitor, MappingVisitor, ScalarVisitor, SequenceVisitor } from './visitors/generics'; + +/** + * Specification object allows us to have complete control over visitors + * when traversing the AST. + * Specification also allows us to create new parser adapters from + * existing ones by manipulating it. + * + * Note: Specification object allows to use relative JSON pointers. + */ +const specification = { + visitors: { + scalar: ScalarVisitor, + mapping: MappingVisitor, + sequence: SequenceVisitor, + kind: KindVisitor, + error: ErrorVisitor, + stream: { + $visitor: StreamVisitor, + }, + document: { + $visitor: DocumentVisitor, + objects: { + AsyncApi: { + $visitor: AsyncApi2_0Visitor, + fixedFields: { + asyncapi: AsyncapiVisitor, + id: IdentifierVisitor, + info: { + $ref: '#/visitors/document/objects/Info', + }, + servers: { + $ref: '#/visitors/document/objects/Servers', + }, + channels: { + $ref: '#/visitors/document/objects/Channels', + }, + components: { + $ref: '#/visitors/document/objects/Components', + }, + }, + }, + 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, + url: LicenseUrlVisitor, + }, + }, + Servers: { + $visitor: ServersVisitor, + }, + Server: { + $visitor: ServerVisitor, + fixedFields: { + url: ServerUrlVisitor, + protocol: ServerProtocolVisitor, + protocolVersion: ServerProtocolVersionVisitor, + description: ServerDescriptionVisitor, + variables: ServerVariablesVisitor, + security: ServerSecurityVisitor, + bindings: { + $ref: '#/visitors/document/objects/Operation', + }, + }, + }, + ServerVariable: { + $visitor: ServerVariableVisitor, + fixedFields: { + enum: ServerVariableEnumVisitor, + default: ServerVariableDefaultVisitor, + description: ServerVariableDescriptionVisitor, + examples: ServerVariableExamplesVisitor, + }, + }, + ServerBindings: { + $visitor: ServerBindingsVisitor, + fixedFields: {}, + }, + SecurityRequirement: { + $visitor: SecurityRequirementVisitor, + }, + Schema: { + $visitor: SchemaVisitor, + }, + Channels: { + $visitor: ChannelsVisitor, + }, + ChannelItem: { + $visitor: ChannelItemVisitor, + fixedFields: { + $ref: ChannelItem$RefVisitor, + description: ChannelItemDescriptionVisitor, + subscribe: { + $ref: '#/visitors/document/objects/Operation', + }, + publish: { + $ref: '#/visitors/document/objects/Operation', + }, + parameters: { + $ref: '#/visitors/document/objects/Parameters', + }, + bindings: { + $ref: '#/visitors/document/objects/ChannelBindings', + }, + }, + }, + Operation: { + $visitor: OperationVisitor, + fixedFields: {}, + }, + ChannelBindings: { + $visitor: ChannelBindingsVisitor, + fixedFields: {}, + }, + Parameters: { + $visitor: ParametersVisitor, + }, + Components: { + $visitor: ComponentsVisitor, + fixedFields: { + schemas: SchemasVisitor, + }, + }, + }, + extension: SpecificationExtensionVisitor, + }, + }, +}; + +export default specification; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/DocumentVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/DocumentVisitor.ts new file mode 100644 index 0000000000..abcacdd0da --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/DocumentVisitor.ts @@ -0,0 +1,36 @@ +import stampit from 'stampit'; +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); + this.element.content.push(element); + }, + + mapping(mappingNode: YamlMapping) { + const asyncApiElement = this.nodeToElement(['document', 'objects', 'AsyncApi'], mappingNode); + this.element.content.push(asyncApiElement); + }, + + sequence(sequenceNode: YamlSequence) { + const arrayElement = this.nodeToElement(['sequence'], sequenceNode); + this.element.content.push(arrayElement); + }, + + comment(commentNode: YamlComment) { + const commentElement = new this.namespace.elements.Comment(commentNode.content); + this.element.content.push(commentElement); + }, + }, +}); + +export default DocumentVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/ErrorVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/ErrorVisitor.ts new file mode 100644 index 0000000000..8b81fecc46 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/ErrorVisitor.ts @@ -0,0 +1,35 @@ +import stampit from 'stampit'; +import { BREAK } from '.'; +import SpecificationVisitor from './SpecificationVisitor'; + +const ErrorVisitor = stampit(SpecificationVisitor, { + methods: { + literal(literalNode) { + if (literalNode.isMissing) { + const message = `(Missing ${literalNode.value})`; + this.element = new this.namespace.elements.Annotation(message); + + this.maybeAddSourceMap(literalNode, this.element); + + return BREAK; + } + + return undefined; + }, + + error(errorNode) { + const message = errorNode.isUnexpected + ? `(Unexpected ${errorNode.value})` + : `(Error ${errorNode.value})`; + + this.element = new this.namespace.elements.Annotation(message); + this.element.classes.push('error'); + + this.maybeAddSourceMap(errorNode, this.element); + + return BREAK; + }, + }, +}); + +export default ErrorVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/SpecificationExtensionVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/SpecificationExtensionVisitor.ts new file mode 100644 index 0000000000..d730957005 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/SpecificationExtensionVisitor.ts @@ -0,0 +1,41 @@ +import stampit from 'stampit'; +import { YamlAlias, YamlKeyValuePair, YamlMapping, YamlScalar, YamlSequence } from 'apidom-ast'; + +import SpecificationVisitor from './SpecificationVisitor'; +import { isAsyncApiExtension } from '../predicates'; +import { BREAK, visit } from '.'; + +const SpecificationExtensionVisitor = stampit(SpecificationVisitor, { + methods: { + keyValuePair(keyValuePairNode: YamlKeyValuePair) { + type YamlValue = YamlScalar | YamlMapping | YamlSequence | YamlAlias; + const { key: keyNode } = keyValuePairNode; + const { value: valueNode }: { value: YamlValue } = keyValuePairNode; + const keyElement = new this.namespace.elements.String(keyNode.content); + const { MemberElement } = this.namespace.elements.Element.prototype; + const state = { namespace: this.namespace, sourceMap: this.sourceMap, specObj: this.specObj }; + const valueVisitor = this.retrieveVisitorInstance(['kind']); + + // @ts-ignore + visit(valueNode, valueVisitor, { state }); + + const memberElement = this.maybeAddSourceMap( + keyValuePairNode, + new MemberElement( + this.maybeAddSourceMap(keyNode, keyElement), + this.maybeAddSourceMap(valueNode, valueVisitor.element), + ), + ); + + if (isAsyncApiExtension({}, keyValuePairNode)) { + memberElement.classes.push('specificationExtension'); + } + + this.element = memberElement; + + return BREAK; + }, + }, +}); + +export default SpecificationExtensionVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/SpecificationVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/SpecificationVisitor.ts new file mode 100644 index 0000000000..054cd1713f --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/SpecificationVisitor.ts @@ -0,0 +1,50 @@ +import stampit from 'stampit'; +import { pathSatisfies, path, pick, pipe, keys } from 'ramda'; +import { isFunction } from 'ramda-adjunct'; +import Visitor from './Visitor'; +import { visit } from '.'; + +/** + * This is a base Type for every visitor that does + * internal look-ups to retrieve other child visitors. + */ +const SpecificationVisitor = stampit(Visitor, { + props: { + specObj: null, + }, + // @ts-ignore + init({ specObj = this.specObj }) { + this.specObj = specObj; + }, + methods: { + retrievePassingOptions() { + return pick(['namespace', 'sourceMap', 'specObj'], this); + }, + + retrieveFixedFields(specPath) { + return pipe(path(['visitors', ...specPath, 'fixedFields']), keys)(this.specObj); + }, + + retrieveVisitor(specPath) { + if (pathSatisfies(isFunction, ['visitors', ...specPath], this.specObj)) { + return path(['visitors', ...specPath], this.specObj); + } + + return path(['visitors', ...specPath, '$visitor'], this.specObj); + }, + + retrieveVisitorInstance(specPath, options = {}) { + const passingOpts = this.retrievePassingOptions(); + + return this.retrieveVisitor(specPath)({ ...passingOpts, ...options }); + }, + + nodeToElement(specPath: string[], node, options = {}) { + const visitor = this.retrieveVisitorInstance(specPath); + visit(node, visitor, options); + return visitor.element; + }, + }, +}); + +export default SpecificationVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/StreamVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/StreamVisitor.ts new file mode 100644 index 0000000000..a21872ae71 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/StreamVisitor.ts @@ -0,0 +1,68 @@ +import stampit from 'stampit'; +import { Literal, Error, YamlDocument, YamlComment } from 'apidom-ast'; + +import { visit, BREAK } from '.'; +import SpecificationVisitor from './SpecificationVisitor'; + +const StreamVisitor = stampit(SpecificationVisitor, { + props: { + processedDocumentCount: 0, + }, + methods: { + literal(literalNode: Literal) { + if (literalNode.isMissing) { + const element = this.nodeToElement(['error'], literalNode); + this.element.content.push(element); + } + }, + + comment(commentNode: YamlComment) { + // we're only interested of stream comments before the first document + const shouldSkipVisitingMoreDocuments = this.processedDocumentCount >= 1; + + if (shouldSkipVisitingMoreDocuments) { + return false; + } + + const commentElement = new this.namespace.elements.Comment(commentNode.content); + this.element.content.push(commentElement); + return undefined; + }, + + document(documentNode: YamlDocument) { + // we're only interested in first document + const shouldWarnAboutMoreDocuments = this.processedDocumentCount === 1; + const shouldSkipVisitingMoreDocuments = this.processedDocumentCount >= 1; + + if (shouldWarnAboutMoreDocuments) { + const message = + 'Only first document within YAML stream will be used. Rest will be discarded.'; + const annotationElement = new this.namespace.elements.Annotation(message); + annotationElement.classes.push('warning'); + this.element.content.push(annotationElement); + } + + if (shouldSkipVisitingMoreDocuments) { + return BREAK; + } + + const documentVisitor = this.retrieveVisitorInstance(['document']); + visit(documentNode, documentVisitor, { + // @ts-ignore + state: { + element: this.element, + }, + }); + + this.processedDocumentCount += 1; + return undefined; + }, + + error(errorNode: Error) { + const element = this.nodeToElement(['error'], errorNode); + this.element.content.push(element); + }, + }, +}); + +export default StreamVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/Visitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/Visitor.ts new file mode 100644 index 0000000000..6198f8b97e --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/Visitor.ts @@ -0,0 +1,28 @@ +import stampit from 'stampit'; +import { addSourceMap } from '../source-map'; + +const Visitor = stampit({ + props: { + element: null, + namespace: null, + sourceMap: false, + keyMap: null, + }, + // @ts-ignore + init({ namespace = this.namespace, sourceMap = this.sourceMap, element = this.element } = {}) { + this.namespace = namespace; + this.sourceMap = sourceMap; + this.element = element; + }, + methods: { + maybeAddSourceMap(node, element) { + if (!this.sourceMap) { + return element; + } + + return addSourceMap(node, element); + }, + }, +}); + +export default Visitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/AsyncapiVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/AsyncapiVisitor.ts new file mode 100644 index 0000000000..40b2e888b2 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/AsyncapiVisitor.ts @@ -0,0 +1,18 @@ +import stampit from 'stampit'; +import { YamlScalar } from 'apidom-ast'; + +import { BREAK } from '..'; +import { KindVisitor } from '../generics'; +import SpecificationVisitor from '../SpecificationVisitor'; + +const AsyncapiVisitor = stampit(KindVisitor, SpecificationVisitor, { + methods: { + scalar(scalarNode: YamlScalar) { + const asyncapiElement = new this.namespace.elements.Asyncapi(scalarNode.content); + this.element = this.maybeAddSourceMap(scalarNode, asyncapiElement); + return BREAK; + }, + }, +}); + +export default AsyncapiVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/IdentifierVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/IdentifierVisitor.ts new file mode 100644 index 0000000000..f16200e477 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/IdentifierVisitor.ts @@ -0,0 +1,17 @@ +import stampit from 'stampit'; +import { BREAK, YamlScalar } from 'apidom-ast'; + +import { KindVisitor } from '../generics'; +import SpecificationVisitor from '../SpecificationVisitor'; + +const IdentifierVisitor = stampit(KindVisitor, SpecificationVisitor, { + methods: { + scalar(scalarNode: YamlScalar) { + const identifierElement = new this.namespace.elements.Identifier(scalarNode.content); + this.element = this.maybeAddSourceMap(scalarNode, identifierElement); + return BREAK; + }, + }, +}); + +export default IdentifierVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/channel-bindings/index.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/channel-bindings/index.ts new file mode 100644 index 0000000000..e53afa35e1 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/channel-bindings/index.ts @@ -0,0 +1,16 @@ +import stampit from 'stampit'; +import { always } from 'ramda'; + +import { KindVisitor } from '../../generics'; +import FixedFieldsYamlMappingVisitor from '../../generics/FixedFieldsYamlMappingVisitor'; + +const ChannelBindingsVisitor = stampit(KindVisitor, FixedFieldsYamlMappingVisitor, { + props: { + specPath: always(['document', 'objects', 'ChannelBindings']), + }, + init() { + this.element = new this.namespace.elements.ChannelBindings(); + }, +}); + +export default ChannelBindingsVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/channel-item/$RefVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/channel-item/$RefVisitor.ts new file mode 100644 index 0000000000..45720b9429 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/channel-item/$RefVisitor.ts @@ -0,0 +1,21 @@ +import stampit from 'stampit'; +import { YamlScalar } from 'apidom-ast'; + +import SpecificationVisitor from '../../SpecificationVisitor'; +import { BREAK } from '../..'; +import { KindVisitor } from '../../generics'; + +const $RefVisitor = stampit(KindVisitor, SpecificationVisitor, { + methods: { + scalar(scalarNode: YamlScalar) { + const { content } = scalarNode; + const refElement = new this.namespace.elements.Ref(content); + refElement.path = content; + this.element = this.maybeAddSourceMap(scalarNode, refElement); + + return BREAK; + }, + }, +}); + +export default $RefVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/channel-item/DescriptionVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/channel-item/DescriptionVisitor.ts new file mode 100644 index 0000000000..5a01b32367 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/channel-item/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-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/channel-item/index.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/channel-item/index.ts new file mode 100644 index 0000000000..aded04f226 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/channel-item/index.ts @@ -0,0 +1,16 @@ +import stampit from 'stampit'; +import { always } from 'ramda'; + +import { KindVisitor } from '../../generics'; +import FixedFieldsYamlMappingVisitor from '../../generics/FixedFieldsYamlMappingVisitor'; + +const ChannelItemVisitor = stampit(KindVisitor, FixedFieldsYamlMappingVisitor, { + props: { + specPath: always(['document', 'objects', 'ChannelItem']), + }, + init() { + this.element = new this.namespace.elements.ChannelItem(); + }, +}); + +export default ChannelItemVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/channels/index.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/channels/index.ts new file mode 100644 index 0000000000..4ff0257610 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/channels/index.ts @@ -0,0 +1,16 @@ +import stampit from 'stampit'; +import { always } from 'ramda'; + +import MapYamlMappingVisitor from '../../generics/MapYamlMappingVisitor'; +import { KindVisitor } from '../../generics'; + +const ChannelsVisitor = stampit(KindVisitor, MapYamlMappingVisitor, { + props: { + specPath: always(['document', 'objects', 'ChannelItem']), + }, + init() { + this.element = new this.namespace.elements.Channels(); + }, +}); + +export default ChannelsVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/components/SchemasVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/components/SchemasVisitor.ts new file mode 100644 index 0000000000..3766e33ad1 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/components/SchemasVisitor.ts @@ -0,0 +1,17 @@ +import stampit from 'stampit'; +import { always } from 'ramda'; + +import MapYamlMappingVisitor from '../../generics/MapYamlMappingVisitor'; +import { KindVisitor } from '../../generics'; + +const SchemasVisitor = stampit(KindVisitor, MapYamlMappingVisitor, { + props: { + specPath: always(['document', 'objects', 'Schema']), + }, + init() { + this.element = new this.namespace.elements.Object(); + this.element.classes.push('schemas'); + }, +}); + +export default SchemasVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/components/index.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/components/index.ts new file mode 100644 index 0000000000..acaec369cc --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/components/index.ts @@ -0,0 +1,16 @@ +import stampit from 'stampit'; +import { always } from 'ramda'; + +import FixedFieldsYamlMappingVisitor from '../../generics/FixedFieldsYamlMappingVisitor'; +import { KindVisitor } from '../../generics'; + +const ComponentsVisitor = stampit(KindVisitor, FixedFieldsYamlMappingVisitor, { + props: { + specPath: always(['document', 'objects', 'Components']), + }, + init() { + this.element = new this.namespace.elements.Components(); + }, +}); + +export default ComponentsVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/contact/EmailVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/contact/EmailVisitor.ts new file mode 100644 index 0000000000..500c9153e7 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/contact/EmailVisitor.ts @@ -0,0 +1,7 @@ +import stampit from 'stampit'; + +import { KindVisitor } from '../../generics'; + +const EmailVisitor = stampit(KindVisitor); + +export default EmailVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/contact/NameVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/contact/NameVisitor.ts new file mode 100644 index 0000000000..ffcae9a0ba --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/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-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/contact/UrlVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/contact/UrlVisitor.ts new file mode 100644 index 0000000000..6879e8a7af --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/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-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/contact/index.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/contact/index.ts new file mode 100644 index 0000000000..220ab07f40 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/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-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/index.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/index.ts new file mode 100644 index 0000000000..d690c4a036 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/index.ts @@ -0,0 +1,16 @@ +import stampit from 'stampit'; +import { always } from 'ramda'; + +import { KindVisitor } from '../generics'; +import FixedFieldsYamlMappingVisitor from '../generics/FixedFieldsYamlMappingVisitor'; + +const AsyncApi2_0Visitor = stampit(KindVisitor, FixedFieldsYamlMappingVisitor, { + props: { + specPath: always(['document', 'objects', 'AsyncApi']), + }, + init() { + this.element = new this.namespace.elements.AsyncApi2_0(); + }, +}); + +export default AsyncApi2_0Visitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/info/DescriptionVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/info/DescriptionVisitor.ts new file mode 100644 index 0000000000..5a01b32367 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/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-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/info/SummaryVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/info/SummaryVisitor.ts new file mode 100644 index 0000000000..486de6038c --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/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-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/info/TermsOfServiceVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/info/TermsOfServiceVisitor.ts new file mode 100644 index 0000000000..4b9028892e --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/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-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/info/TitleVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/info/TitleVisitor.ts new file mode 100644 index 0000000000..ee54310473 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/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-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/info/VersionVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/info/VersionVisitor.ts new file mode 100644 index 0000000000..7bdb3b4282 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/info/VersionVisitor.ts @@ -0,0 +1,20 @@ +import stampit from 'stampit'; +import { YamlScalar } from 'apidom-ast'; + +import { appendMetadata } from '../../../metadata'; +import { KindVisitor } from '../../generics'; + +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-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/info/index.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/info/index.ts new file mode 100644 index 0000000000..112882705e --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/info/index.ts @@ -0,0 +1,16 @@ +import stampit from 'stampit'; +import { always } from 'ramda'; + +import FixedFieldsYamlMappingVisitor from '../../generics/FixedFieldsYamlMappingVisitor'; +import { KindVisitor } from '../../generics'; + +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-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/license/NameVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/license/NameVisitor.ts new file mode 100644 index 0000000000..ffcae9a0ba --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/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-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/license/UrlVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/license/UrlVisitor.ts new file mode 100644 index 0000000000..6879e8a7af --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/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-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/license/index.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/license/index.ts new file mode 100644 index 0000000000..cad279b024 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/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; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/operation/index.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/operation/index.ts new file mode 100644 index 0000000000..36962f0685 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/operation/index.ts @@ -0,0 +1,16 @@ +import stampit from 'stampit'; +import { always } from 'ramda'; + +import FixedFieldsYamlMappingVisitor from '../../generics/FixedFieldsYamlMappingVisitor'; +import { KindVisitor } from '../../generics'; + +const OperationVisitor = stampit(KindVisitor, FixedFieldsYamlMappingVisitor, { + props: { + specPath: always(['document', 'objects', 'Operation']), + }, + init() { + this.element = new this.namespace.elements.Operation(); + }, +}); + +export default OperationVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/parameters/index.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/parameters/index.ts new file mode 100644 index 0000000000..76c4310526 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/parameters/index.ts @@ -0,0 +1,18 @@ +import stampit from 'stampit'; +import { test, always } from 'ramda'; + +import PatternedFieldsYamlMappingVisitor from '../../generics/PatternedFieldsYamlMappingVisitor'; +import { KindVisitor } from '../../generics'; + +const ParametersVisitor = stampit(KindVisitor, PatternedFieldsYamlMappingVisitor, { + props: { + // TODO(vladimir.gorej@gmail.com): replace generic value spec with concrete objects + specPath: always(['kind']), + fieldPatternPredicate: test(/^[A-Za-z0-9_\\-]+$/), + }, + init() { + this.element = new this.namespace.elements.Parameters(); + }, +}); + +export default ParametersVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/schema/index.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/schema/index.ts new file mode 100644 index 0000000000..0d591a6940 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/schema/index.ts @@ -0,0 +1,21 @@ +import stampit from 'stampit'; +import { YamlMapping } from 'apidom-ast'; + +import { BREAK } from '../..'; +import SpecificationVisitor from '../../SpecificationVisitor'; +import { KindVisitor } from '../../generics'; + +const SchemaVisitor = stampit(KindVisitor, SpecificationVisitor, { + methods: { + mapping(mappingNode: YamlMapping) { + const objectElement = this.nodeToElement(['mapping'], mappingNode); + const schemaElement = new this.namespace.elements.Schema(objectElement.content); + + this.element = this.maybeAddSourceMap(mappingNode, schemaElement); + + return BREAK; + }, + }, +}); + +export default SchemaVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/security-requirement/index.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/security-requirement/index.ts new file mode 100644 index 0000000000..273cf80e46 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/security-requirement/index.ts @@ -0,0 +1,16 @@ +import stampit from 'stampit'; +import { always } from 'ramda'; + +import MapYamlMappingVisitor from '../../generics/MapYamlMappingVisitor'; +import { KindVisitor } from '../../generics'; + +const SecurityRequirementVisitor = stampit(KindVisitor, MapYamlMappingVisitor, { + props: { + specPath: always(['sequence']), + }, + init() { + this.element = new this.namespace.elements.SecurityRequirement(); + }, +}); + +export default SecurityRequirementVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server-bindings/index.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server-bindings/index.ts new file mode 100644 index 0000000000..4c575af06e --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server-bindings/index.ts @@ -0,0 +1,16 @@ +import stampit from 'stampit'; +import { always } from 'ramda'; + +import FixedFieldsYamlMappingVisitor from '../../generics/FixedFieldsYamlMappingVisitor'; +import { KindVisitor } from '../../generics'; + +const ServerBindingsVisitor = stampit(KindVisitor, FixedFieldsYamlMappingVisitor, { + props: { + specPath: always(['document', 'objects', 'ServerBindings']), + }, + init() { + this.element = new this.namespace.elements.ServerBindings(); + }, +}); + +export default ServerBindingsVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server-variable/DefaultVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server-variable/DefaultVisitor.ts new file mode 100644 index 0000000000..8e54560780 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server-variable/DefaultVisitor.ts @@ -0,0 +1,7 @@ +import stampit from 'stampit'; + +import { KindVisitor } from '../../generics'; + +const DefaultVisitor = stampit(KindVisitor); + +export default DefaultVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server-variable/DescriptionVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server-variable/DescriptionVisitor.ts new file mode 100644 index 0000000000..5a01b32367 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server-variable/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-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server-variable/EnumVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server-variable/EnumVisitor.ts new file mode 100644 index 0000000000..6c11023697 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server-variable/EnumVisitor.ts @@ -0,0 +1,7 @@ +import stampit from 'stampit'; + +import { KindVisitor } from '../../generics'; + +const EnumVisitor = stampit(KindVisitor); + +export default EnumVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server-variable/ExamplesVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server-variable/ExamplesVisitor.ts new file mode 100644 index 0000000000..ef4a91e036 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server-variable/ExamplesVisitor.ts @@ -0,0 +1,7 @@ +import stampit from 'stampit'; + +import { KindVisitor } from '../../generics'; + +const ExamplesVisitor = stampit(KindVisitor); + +export default ExamplesVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server-variable/index.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server-variable/index.ts new file mode 100644 index 0000000000..1b022238b5 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server-variable/index.ts @@ -0,0 +1,16 @@ +import stampit from 'stampit'; +import { always } from 'ramda'; + +import FixedFieldsYamlMappingVisitor from '../../generics/FixedFieldsYamlMappingVisitor'; +import { KindVisitor } from '../../generics'; + +const ServerVariableVisitor = stampit(KindVisitor, FixedFieldsYamlMappingVisitor, { + props: { + specPath: always(['document', 'objects', 'ServerVariable']), + }, + init() { + this.element = new this.namespace.elements.ServerVariable(); + }, +}); + +export default ServerVariableVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server/DescriptionVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server/DescriptionVisitor.ts new file mode 100644 index 0000000000..5a01b32367 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server/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-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server/ProtocolVersionVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server/ProtocolVersionVisitor.ts new file mode 100644 index 0000000000..d3d92f56d4 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server/ProtocolVersionVisitor.ts @@ -0,0 +1,7 @@ +import stampit from 'stampit'; + +import { KindVisitor } from '../../generics'; + +const ProtocolVersionVisitor = stampit(KindVisitor); + +export default ProtocolVersionVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server/ProtocolVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server/ProtocolVisitor.ts new file mode 100644 index 0000000000..fcadad680d --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server/ProtocolVisitor.ts @@ -0,0 +1,7 @@ +import stampit from 'stampit'; + +import { KindVisitor } from '../../generics'; + +const ProtocolVisitor = stampit(KindVisitor); + +export default ProtocolVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server/SecurityVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server/SecurityVisitor.ts new file mode 100644 index 0000000000..21deb5eba8 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server/SecurityVisitor.ts @@ -0,0 +1,31 @@ +import stampit from 'stampit'; +import { isYamlMapping, YamlSequence } from 'apidom-ast'; + +import { BREAK } from '../..'; +import SpecificationVisitor from '../../SpecificationVisitor'; + +const SecurityVisitor = stampit(SpecificationVisitor, { + init() { + this.element = new this.namespace.elements.Array(); + this.element.classes.push('security'); + }, + methods: { + sequence(sequenceNode: YamlSequence) { + sequenceNode.content.forEach((item) => { + if (isYamlMapping(item)) { + const element = this.nodeToElement(['document', 'objects', 'SecurityRequirement'], item); + this.element.push(element); + } else { + const element = this.nodeToElement(['kind'], item); + this.element.push(element); + } + }); + + this.maybeAddSourceMap(sequenceNode, this.element); + + return BREAK; + }, + }, +}); + +export default SecurityVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server/UrlVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server/UrlVisitor.ts new file mode 100644 index 0000000000..6879e8a7af --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server/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-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server/VariablesVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server/VariablesVisitor.ts new file mode 100644 index 0000000000..a5c6ddce0d --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server/VariablesVisitor.ts @@ -0,0 +1,17 @@ +import stampit from 'stampit'; +import { always } from 'ramda'; + +import MapYamlMappingVisitor from '../../generics/MapYamlMappingVisitor'; +import { KindVisitor } from '../../generics'; + +const VariablesVisitor = stampit(KindVisitor, MapYamlMappingVisitor, { + props: { + specPath: always(['document', 'objects', 'ServerVariable']), + }, + init() { + this.element = new this.namespace.elements.Object(); + this.element.classes.push('variables'); + }, +}); + +export default VariablesVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server/index.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server/index.ts new file mode 100644 index 0000000000..64e2462240 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/server/index.ts @@ -0,0 +1,16 @@ +import stampit from 'stampit'; +import { always } from 'ramda'; + +import FixedFieldsYamlMappingVisitor from '../../generics/FixedFieldsYamlMappingVisitor'; +import { KindVisitor } from '../../generics'; + +const ServerVisitor = stampit(KindVisitor, FixedFieldsYamlMappingVisitor, { + props: { + specPath: always(['document', 'objects', 'Server']), + }, + init() { + this.element = new this.namespace.elements.Server(); + }, +}); + +export default ServerVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/servers/index.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/servers/index.ts new file mode 100644 index 0000000000..cf323789d6 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/async-api-2-0/servers/index.ts @@ -0,0 +1,17 @@ +import stampit from 'stampit'; +import { test, always } from 'ramda'; + +import PatternedFieldsYamlMappingVisitor from '../../generics/PatternedFieldsYamlMappingVisitor'; +import { KindVisitor } from '../../generics'; + +const ServersVisitor = stampit(KindVisitor, PatternedFieldsYamlMappingVisitor, { + props: { + specPath: always(['document', 'objects', 'Server']), + fieldPatternPredicate: test(/^[A-Za-z0-9_\\-]+$/), + }, + init() { + this.element = new this.namespace.elements.Servers(); + }, +}); + +export default ServersVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/generics/AlternatingVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/generics/AlternatingVisitor.ts new file mode 100644 index 0000000000..50be6ed91c --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/generics/AlternatingVisitor.ts @@ -0,0 +1,30 @@ +import stampit from 'stampit'; +import { ifElse, always, Pred } from 'ramda'; +import { dispatch, stubUndefined } from 'ramda-adjunct'; +import { YamlMapping } from 'apidom-ast'; + +import { BREAK } from '..'; +import SpecificationVisitor from '../SpecificationVisitor'; + +const AlternatingVisitor = stampit(SpecificationVisitor, { + props: { + alternator: [], + }, + methods: { + mapping(mappingNode: YamlMapping) { + const functions = this.alternator.map( + ({ predicate, specPath }: { predicate: Pred; specPath: string[] }) => + ifElse(predicate, always(specPath), stubUndefined), + ); + const specPath = dispatch(functions)(mappingNode); + + this.element = this.nodeToElement(specPath, mappingNode); + + this.maybeAddSourceMap(mappingNode, this.element); + + return BREAK; + }, + }, +}); + +export default AlternatingVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/generics/FixedFieldsYamlMappingVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/generics/FixedFieldsYamlMappingVisitor.ts new file mode 100644 index 0000000000..7cbefba705 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/generics/FixedFieldsYamlMappingVisitor.ts @@ -0,0 +1,78 @@ +import stampit from 'stampit'; +import { noop } from 'ramda-adjunct'; +import { YamlKeyValuePair, YamlMapping } from 'apidom-ast'; + +import SpecificationVisitor from '../SpecificationVisitor'; +import { isAsyncApiExtension } 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(valueNode, 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 && + isAsyncApiExtension({}, 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-asyncapi2-0-yaml/src/parser/visitors/generics/MapYamlMappingVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/generics/MapYamlMappingVisitor.ts new file mode 100644 index 0000000000..07fdc0176e --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/generics/MapYamlMappingVisitor.ts @@ -0,0 +1,12 @@ +import stampit from 'stampit'; +import { isNonEmptyString } from 'ramda-adjunct'; + +import PatternedFieldsYamlMappingVisitor from './PatternedFieldsYamlMappingVisitor'; + +const MapYamlMappingVisitor = stampit(PatternedFieldsYamlMappingVisitor, { + props: { + fieldPatternPredicate: isNonEmptyString, + }, +}); + +export default MapYamlMappingVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/generics/MixedFieldsYamlMappingVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/generics/MixedFieldsYamlMappingVisitor.ts new file mode 100644 index 0000000000..a6414ab65e --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/generics/MixedFieldsYamlMappingVisitor.ts @@ -0,0 +1,43 @@ +import stampit from 'stampit'; +import { noop } from 'ramda-adjunct'; +import { YamlMapping } from 'apidom-ast'; + +import { BREAK, visit } from '..'; +import FixedFieldsYamlMappingVisitor from './FixedFieldsYamlMappingVisitor'; +import PatternedFieldsYamlMappingVisitor from './PatternedFieldsYamlMappingVisitor'; +import SpecificationVisitor from '../SpecificationVisitor'; + +const MixedFieldsYamlMappingVisitor = stampit(SpecificationVisitor, { + props: { + specPathFixedFields: noop, + specPathPatternedFields: noop, + }, + methods: { + mapping(mappingNode: YamlMapping) { + const fixedFieldsVisitor = FixedFieldsYamlMappingVisitor({ + ...this.retrievePassingOptions(), + ignoredFields: this.ignoredFields, + canSupportSpecificationExtensions: this.canSupportSpecificationExtensions, + element: this.element, + specPath: this.specPathFixedFields, + }); + + visit(mappingNode, fixedFieldsVisitor); + + const patternedFieldsVisitor = PatternedFieldsYamlMappingVisitor({ + ...this.retrievePassingOptions(), + ignoredFields: this.ignoredFields, + canSupportSpecificationExtensions: this.canSupportSpecificationExtensions, + element: this.element, + fieldPatternPredicate: this.fieldPatternPredicate, + specPath: this.specPathPatternedFields, + }); + + visit(mappingNode, patternedFieldsVisitor); + + return BREAK; + }, + }, +}); + +export default MixedFieldsYamlMappingVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/generics/PatternedFieldsYamlMappingVisitor.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/generics/PatternedFieldsYamlMappingVisitor.ts new file mode 100644 index 0000000000..33cac05c9a --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/generics/PatternedFieldsYamlMappingVisitor.ts @@ -0,0 +1,79 @@ +import stampit from 'stampit'; +import { F as stubFalse } from 'ramda'; +import { noop } from 'ramda-adjunct'; +import { YamlKeyValuePair, YamlMapping } from 'apidom-ast'; + +import SpecificationVisitor from '../SpecificationVisitor'; +import { isAsyncApiExtension } from '../../predicates'; +import { visit } from '..'; + +const PatternedFieldsYamlMappingVisitor = stampit(SpecificationVisitor, { + props: { + fieldPatternPredicate: stubFalse, + specPath: noop, + ignoredFields: [], + keyMap: { + // @ts-ignore + [YamlMapping.type]: ['children'], + }, + canSupportSpecificationExtensions: false, + }, + init({ + // @ts-ignore + specPath = this.specPath, + // @ts-ignore + fieldPatternPredicate = this.fieldPatternPredicate, + // @ts-ignore + ignoredFields = this.ignoredFields, + // @ts-ignore + canSupportSpecificationExtensions = this.canSupportSpecificationExtensions, + } = {}) { + this.specPath = specPath; + this.fieldPatternPredicate = fieldPatternPredicate; + this.ignoredFields = ignoredFields; + this.canSupportSpecificationExtensions = canSupportSpecificationExtensions; + }, + methods: { + mapping(mappingNode: YamlMapping) { + this.maybeAddSourceMap(mappingNode, this.element); + }, + + keyValuePair(keyValuePairNode: YamlKeyValuePair) { + const { key: keyNode, value: valueNode } = keyValuePairNode; + const keyName = keyNode.content; + const { MemberElement } = this.namespace.elements.Element.prototype; + + if (this.canSupportSpecificationExtensions && isAsyncApiExtension({}, keyValuePairNode)) { + const visitor = this.retrieveVisitorInstance(['document', 'extension']); + visit(keyValuePairNode, visitor); + this.element.content.push(visitor.element); + } else if (!this.ignoredFields.includes(keyName) && this.fieldPatternPredicate(keyName)) { + const specPath = this.specPath(valueNode); + const visitor = this.retrieveVisitorInstance(specPath); + const keyElement = new this.namespace.elements.String(keyName); + + visit(valueNode, visitor); + + const memberElement = this.maybeAddSourceMap( + keyValuePairNode, + new MemberElement(this.maybeAddSourceMap(keyNode, keyElement), visitor.element), + ); + memberElement.classes.push('patternedField'); + + this.element.content.push(memberElement); + } 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 PatternedFieldsYamlMappingVisitor; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/generics/index.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/generics/index.ts new file mode 100644 index 0000000000..19ead536f8 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/generics/index.ts @@ -0,0 +1,150 @@ +import stampit from 'stampit'; +import { last } from 'ramda'; +import { isNotNull } from 'ramda-adjunct'; +import { + YamlKeyValuePair, + YamlMapping, + YamlScalar, + YamlSequence, + isYamlMapping, + isYamlSequence, +} from 'apidom-ast'; + +import { BREAK } from '..'; +import { isAsyncApiExtension } from '../../predicates'; +import SpecificationVisitor from '../SpecificationVisitor'; + +export const ScalarVisitor = stampit(SpecificationVisitor, { + methods: { + scalar(scalarNode: YamlScalar): typeof BREAK { + const stringElement = this.namespace.toElement(scalarNode.content); + this.element = this.maybeAddSourceMap(scalarNode, stringElement); + return BREAK; + }, + }, +}); + +export const SequenceVisitor = stampit(SpecificationVisitor).init(function SequenceVisitor() { + // @ts-ignore + const stack = []; + + // @ts-ignore + this.mapping = function mapping(mappingNode: YamlMapping) { + // @ts-ignore + const arrayElement = last(stack); + const element = this.nodeToElement(['mapping'], mappingNode); + + arrayElement.push(this.maybeAddSourceMap(mappingNode, element)); + + return false; + }; + + this.sequence = { + enter: (sequenceNode: YamlSequence) => { + const arrayElement = this.maybeAddSourceMap( + sequenceNode, + new this.namespace.elements.Array(), + ); + + stack.push(arrayElement); + + if (isNotNull(this.element)) { + this.element.push(arrayElement); + } else { + this.element = arrayElement; + } + }, + leave: () => { + // @ts-ignore + this.element = stack.pop(); + }, + }; + + this.scalar = function scalar(scalarNode: YamlScalar) { + // @ts-ignore + const arrayElement = last(stack); + const element = this.nodeToElement(['scalar'], scalarNode); + + arrayElement.push(element); + }; +}); + +export const MappingVisitor = stampit(SpecificationVisitor).init(function MappingVisitor() { + // @ts-ignore + const stack = []; + + this.keyValuePair = function keyValuePair(keyValuePairNode: YamlKeyValuePair) { + // @ts-ignore + const objElement = last(stack); + const { MemberElement } = this.namespace.elements.Element.prototype; + const { key: keyNode } = keyValuePairNode; + const { value: valueNode } = keyValuePairNode; + const keyElement = new this.namespace.elements.String(keyNode.content); + let valueElement; + + if (isYamlMapping(valueNode)) { + valueElement = this.nodeToElement(['mapping'], valueNode); + } else if (isYamlSequence(valueNode)) { + valueElement = this.nodeToElement(['sequence'], valueNode); + } else if (keyNode.content === '$ref') { + // $ref property key special handling + // @ts-ignore + valueElement = new this.namespace.elements.Ref(valueNode.content); + valueElement.path = valueNode.content; + } else if (!isAsyncApiExtension({}, keyValuePairNode)) { + // @ts-ignore + valueElement = this.namespace.toElement(valueNode.content); + } + + if (isAsyncApiExtension({}, keyValuePairNode)) { + objElement.content.push(this.nodeToElement(['document', 'extension'], keyValuePairNode)); + } else { + objElement.content.push( + this.maybeAddSourceMap( + keyValuePairNode, + new MemberElement( + this.maybeAddSourceMap(keyNode, keyElement), + this.maybeAddSourceMap(valueNode, valueElement), + ), + ), + ); + } + + return false; + }; + + this.mapping = { + enter: (mappingNode: YamlMapping) => { + const objectElement = this.maybeAddSourceMap( + mappingNode, + new this.namespace.elements.Object(), + ); + + // @ts-ignore + stack.push(objectElement); + }, + leave: () => { + // @ts-ignore + this.element = stack.pop(); + }, + }; +}); + +export const KindVisitor = stampit(SpecificationVisitor, { + methods: { + sequence(sequenceNode: YamlSequence): typeof BREAK { + this.element = this.nodeToElement(['sequence'], sequenceNode); + return BREAK; + }, + + mapping(mappingNode: YamlMapping): typeof BREAK { + this.element = this.nodeToElement(['mapping'], mappingNode); + return BREAK; + }, + + scalar(scalarNode: YamlScalar): typeof BREAK { + this.element = this.nodeToElement(['scalar'], scalarNode); + return BREAK; + }, + }, +}); diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/index.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/index.ts new file mode 100644 index 0000000000..2711038cab --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/parser/visitors/index.ts @@ -0,0 +1,38 @@ +import { propOr } from 'ramda'; +import { + YamlStream, + YamlDocument, + YamlMapping, + YamlSequence, + YamlKeyValuePair, + Error, + visit as astVisit, +} from 'apidom-ast'; + +export { BREAK } from 'apidom-ast'; + +/* eslint-disable import/prefer-default-export */ + +const keyMapDefault = { + // @ts-ignore + [YamlStream.type]: ['children'], + // @ts-ignore + [YamlDocument.type]: ['children'], + // @ts-ignore + [YamlMapping.type]: ['children'], + // @ts-ignore + [YamlSequence.type]: ['children'], + // @ts-ignore + [YamlKeyValuePair.type]: ['key', 'value'], + // @ts-ignore + [Error.type]: ['children'], +}; + +// @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: effectiveKeyMap }); +}; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/polyfills.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/polyfills.ts new file mode 100644 index 0000000000..920af8735b --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/src/polyfills.ts @@ -0,0 +1,3 @@ +/* eslint-disable import/no-extraneous-dependencies */ +import 'core-js/stable'; +import 'regenerator-runtime/runtime'; diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/test/.eslintrc b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/test/.eslintrc new file mode 100644 index 0000000000..36c7f68c71 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/test/.eslintrc @@ -0,0 +1,35 @@ +{ + "env": { + "mocha": true + }, + "globals": { + "document": true + }, + "plugins": [ + "mocha" + ], + "rules": { + "no-void": 0, + "func-names": 0, + "prefer-arrow-callback": 0, + "no-array-constructor": 0, + "prefer-rest-params": 0, + "no-new-wrappers": 0, + "mocha/no-skipped-tests": 2, + "mocha/handle-done-callback": 2, + "mocha/valid-suite-description": 2, + "mocha/no-mocha-arrows": 2, + "mocha/no-hooks-for-single-case": 2, + "mocha/no-sibling-hooks": 2, + "mocha/no-top-level-hooks": 2, + "mocha/no-identical-title": 2, + "mocha/no-nested-tests": 2, + "mocha/no-exclusive-tests": 2 + }, + "overrides": [{ + "files": ["mocha-bootstrap.js"], + "parserOptions": { + "sourceType": "script" + } + }] +} diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/test/fixtures/sample-api.yaml b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/test/fixtures/sample-api.yaml new file mode 100644 index 0000000000..672be85dc9 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/test/fixtures/sample-api.yaml @@ -0,0 +1,100 @@ +--- +asyncapi: 2.0.0 +id: urn:com:smartylighting:streetlights:server +info: + title: AsyncAPI Sample App + description: This is a sample server. + termsOfService: http://asyncapi.org/terms/ + contact: + name: API Support + url: http://www.asyncapi.org/support + email: support@asyncapi.org + license: + name: Apache 2.0 + url: http://www.apache.org/licenses/LICENSE-2.0.html + version: 1.0.1 +servers: + production: + url: "{username}.gigantic-server.com:{port}/{basePath}" + description: The production API server + protocol: secure-mqtt + protocolVersion: 1.0.0 + variables: + username: + default: demo + description: This value is assigned by the service provider, in this example + `gigantic-server.com` + examples: + - value1 + - value2 + port: + enum: + - '8883' + - '8884' + default: '8883' + basePath: + default: v2 + security: + - user_pass: [] + bindings: {} +channels: + user/signup: + description: This channel is used to exchange messages about users signing up + subscribe: + summary: A user signed up. + message: + description: A longer description of the message + payload: + type: object + properties: + user: + "$ref": "#/components/schemas/user" + signup: + "$ref": "#/components/schemas/signup" + bindings: + amqp: + is: queue + queue: + exclusive: true +components: + x-extension: value + schemas: + Category: + type: object + properties: + id: + type: integer + format: int64 + name: + type: string + Tag: + type: object + properties: + id: + type: integer + format: int64 + name: + type: string + messages: + userSignUp: + summary: Action to sign a user up. + description: | + Multiline description of what this action does. + Here you have another line. + tags: + - name: user + - name: signup + headers: + type: object + properties: + applicationInstanceId: + description: Unique identifier for a given instance of the publishing + application + type: string + payload: + type: object + properties: + user: + "$ref": "#/components/schemas/userCreate" + signup: + "$ref": "#/components/schemas/signup" diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/test/index.ts b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/test/index.ts new file mode 100644 index 0000000000..a4052cf7d3 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/test/index.ts @@ -0,0 +1,18 @@ +import fs from 'fs'; +import path from 'path'; +import * as apiDOM from 'apidom'; + +import * as adapter from '../src/adapter-node'; + +const spec = fs.readFileSync(path.join(__dirname, 'fixtures', 'sample-api.yaml')).toString(); + +describe('apidom-parser-adapter-asyncapi2-0-yaml', function () { + it('test', async function () { + console.log(adapter.detect(spec)); + console.log(adapter.mediaTypes); + + const parseResult = await adapter.parse(spec, { sourceMap: true }); + console.log(JSON.stringify(apiDOM.toValue(parseResult), null, 2)); + // console.log(JSON.stringify(apiDOM.toJSON(adapter.namespace, parseResult), null, null)); + }); +}); diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/test/mocha-bootstrap.js b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/test/mocha-bootstrap.js new file mode 100644 index 0000000000..2f32267f0f --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/test/mocha-bootstrap.js @@ -0,0 +1,2 @@ +require('regenerator-runtime'); +require('@babel/register')({ extensions: ['.js', '.ts'], rootMode: 'upward' }); diff --git a/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/tsconfig.json b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/tsconfig.json new file mode 100644 index 0000000000..f50bd0d49c --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-asyncapi2-0-yaml/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.json", + "include": [ + "../@types/**/*.d.ts", + "src/**/*", + "test/**/*" + ] +} 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 cc1f3951b5..68e23ca198 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 @@ -1,6 +1,5 @@ import StreamVisitor from './visitors/StreamVisitor'; import DocumentVisitor from './visitors/DocumentVisitor'; - import ErrorVisitor from './visitors/ErrorVisitor'; import { ScalarVisitor, MappingVisitor, SequenceVisitor, KindVisitor } from './visitors/generics'; import SpecificationExtensionVisitor from './visitors/SpecificationExtensionVisitor';