diff --git a/apidom/packages/apidom-ast/src/nodes/yaml/YamlScalar.ts b/apidom/packages/apidom-ast/src/nodes/yaml/YamlScalar.ts index 1fff84355a..8d479cc7ea 100644 --- a/apidom/packages/apidom-ast/src/nodes/yaml/YamlScalar.ts +++ b/apidom/packages/apidom-ast/src/nodes/yaml/YamlScalar.ts @@ -1,6 +1,7 @@ import stampit from 'stampit'; import YamlNode from './YamlNode'; +import { YamlStyle } from './YamlStyle'; interface YamlScalar extends YamlNode { type: 'scalar'; @@ -23,6 +24,10 @@ const YamlScalar: stampit.Stamp = stampit(YamlNode, { methods: { // @ts-ignore get content() { + if (this.style === YamlStyle.SingleQuoted) { + // @ts-ignore + return this.text.replace(/^'/, '').replace(/'$/, ''); + } // @ts-ignore return this.text; }, 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 3b82816a23..ca5d5b0f3b 100644 --- a/apidom/packages/apidom-ast/src/transformers/tree-sitter-yaml.ts +++ b/apidom/packages/apidom-ast/src/transformers/tree-sitter-yaml.ts @@ -428,7 +428,7 @@ const Visitor = stampit({ const anchor = kindNodeToYamlAnchor(node); return YamlScalar({ - content: node.text, + text: node.text, anchor, tag, position, @@ -445,7 +445,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/ServersVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/ServersVisitor.ts index f6f099ac5c..523f3c28ad 100644 --- a/apidom/packages/apidom-parser-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/ServersVisitor.ts +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/ServersVisitor.ts @@ -15,7 +15,6 @@ const ServersVisitor = stampit(ValueVisitor, SpecificationVisitor, { array(arrayNode) { arrayNode.items.forEach((item: JsonNode) => { if (isServerObject({}, item)) { - console.dir('server object'); const element = this.nodeToElement(['document', 'objects', 'Server'], item); this.element.push(element); } else { diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/operation/CallbacksVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/operation/CallbacksVisitor.ts index 0fcccdbc7c..7bb6f7de15 100644 --- a/apidom/packages/apidom-parser-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/operation/CallbacksVisitor.ts +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/operation/CallbacksVisitor.ts @@ -9,7 +9,7 @@ const CallbacksVisitor = stampit(ValueVisitor, MapJsonObjectVisitor, { props: { specPath: (node: JsonNode) => { // eslint-disable-next-line no-nested-ternary - return isReferenceObject(node) + return isReferenceObject({}, node) ? ['document', 'objects', 'Reference'] : isJsonObject(node) ? ['document', 'objects', 'Callback'] diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/paths/index.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/paths/index.ts index 21a5268b8c..9e70726728 100644 --- a/apidom/packages/apidom-parser-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/paths/index.ts +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-json/src/parser/visitors/open-api-3-1/paths/index.ts @@ -1,11 +1,12 @@ import stampit from 'stampit'; -import { always } from 'ramda'; +import { test, always } from 'ramda'; -import MapJsonObjectVisitor from '../../generics/MapJsonObjectVisitor'; +import PatternedFieldsJsonObjectVisitor from '../../generics/PatternedFieldsJsonObjectVisitor'; import { ValueVisitor } from '../../generics'; -const PathsVisitor = stampit(ValueVisitor, MapJsonObjectVisitor, { +const PathsVisitor = stampit(ValueVisitor, PatternedFieldsJsonObjectVisitor, { props: { + fieldPatternPredicate: test(/^\/(?.*)$/), specPath: always(['document', 'objects', 'PathItem']), canSupportSpecificationExtensions: true, }, diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/predicates.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/predicates.ts index 013c76d962..812717c17e 100644 --- a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/predicates.ts +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/predicates.ts @@ -30,3 +30,27 @@ export const isServerObject = curry((options, node) => { } return hasKeys(['url'], node.content); }); + +// isParameterObject :: Options -> JsonObject -> Boolean +export const isParameterObject = curry((options, node) => { + if (!isYamlMapping(node)) { + return false; + } + return hasKeys(['name', 'in'], node.content); +}); + +// isReferenceObject :: Options -> JsonObject -> Boolean +export const isReferenceObject = curry((options, node) => { + if (!isYamlMapping(node)) { + return false; + } + return hasKeys(['$ref'], node.content); +}); + +// isRequestBodyObject :: Options -> JsonObject -> Boolean +export const isRequestBodyObject = curry((options, node) => { + if (!isYamlMapping(node)) { + return false; + } + return hasKeys(['content'], node.content); +}); 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 b88b421437..dd88fd84da 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 @@ -34,6 +34,26 @@ import SecurityRequirementVisitor from './visitors/open-api-3-1/security-require import ComponentsVisitor from './visitors/open-api-3-1/components'; import SchemasVisitor from './visitors/open-api-3-1/components/SchemasVisitor'; import SchemaVisitor from './visitors/open-api-3-1/schema'; +import PathsVisitor from './visitors/open-api-3-1/paths'; +import PathItemVisitor from './visitors/open-api-3-1/path-item'; +import PathItem$RefVisitor from './visitors/open-api-3-1/path-item/$RefVisitor'; +import PathItemSummaryVisitor from './visitors/open-api-3-1/path-item/SummaryVisitor'; +import PathItemDescriptionVisitor from './visitors/open-api-3-1/path-item/DescriptionVisitor'; +import ParametersVisitor from './visitors/open-api-3-1/ParametersVisitor'; +import OperationVisitor from './visitors/open-api-3-1/operation'; +import OperationTagsVisitor from './visitors/open-api-3-1/operation/TagsVisitor'; +import OperationSummaryVisitor from './visitors/open-api-3-1/operation/SummaryVisitor'; +import OperationDescriptionVisitor from './visitors/open-api-3-1/operation/DescriptionVisitor'; +import OperationOperationIdVisitor from './visitors/open-api-3-1/operation/OperationIdVisitor'; +import OperationDeprecatedVisitor from './visitors/open-api-3-1/operation/DeprecatedVisitor'; +import OperationRequestBodyVisitor from './visitors/open-api-3-1/operation/RequestBodyVisitor'; +import OperationCallbacksVisitor from './visitors/open-api-3-1/operation/CallbacksVisitor'; +import ExternalDocumentationVisitor from './visitors/open-api-3-1/external-documentation'; +import ExternalDocumentationDescriptionVisitor from './visitors/open-api-3-1/external-documentation/DescriptionVisitor'; +import ExternalDocumentationUrlVisitor from './visitors/open-api-3-1/external-documentation/UrlVisitor'; +import RequestBodyVisitor from './visitors/open-api-3-1/request-body'; +import ReferenceVisitor from './visitors/open-api-3-1/reference'; +import CallbackVisitor from './visitors/open-api-3-1/callback'; /** * Specification object allows us to have complete control over visitors @@ -68,6 +88,9 @@ const specification = { $ref: '#/visitors/document/objects/Components', }, security: SecurityVisitor, + paths: { + $ref: '#/visitors/document/objects/Paths', + }, }, }, Info: { @@ -127,6 +150,83 @@ const specification = { schemas: SchemasVisitor, }, }, + Paths: { + $visitor: PathsVisitor, + }, + PathItem: { + $visitor: PathItemVisitor, + fixedFields: { + $ref: PathItem$RefVisitor, + summary: PathItemSummaryVisitor, + description: PathItemDescriptionVisitor, + get: { + $ref: '#/visitors/document/objects/Operation', + }, + put: { + $ref: '#/visitors/document/objects/Operation', + }, + post: { + $ref: '#/visitors/document/objects/Operation', + }, + delete: { + $ref: '#/visitors/document/objects/Operation', + }, + options: { + $ref: '#/visitors/document/objects/Operation', + }, + head: { + $ref: '#/visitors/document/objects/Operation', + }, + patch: { + $ref: '#/visitors/document/objects/Operation', + }, + trace: { + $ref: '#/visitors/document/objects/Operation', + }, + servers: ServersVisitor, + parameters: ParametersVisitor, + }, + }, + Operation: { + $visitor: OperationVisitor, + fixedFields: { + tags: OperationTagsVisitor, + summary: OperationSummaryVisitor, + description: OperationDescriptionVisitor, + externalDocs: { + $ref: '#/visitors/document/objects/ExternalDocumentation', + }, + operationId: OperationOperationIdVisitor, + parameters: ParametersVisitor, + requestBody: OperationRequestBodyVisitor, + // responses: { + // $ref: '#/visitors/document/objects/Responses', + // }, + callbacks: OperationCallbacksVisitor, + deprecated: OperationDeprecatedVisitor, + security: SecurityVisitor, + servers: ServersVisitor, + }, + }, + ExternalDocumentation: { + $visitor: ExternalDocumentationVisitor, + fixedFields: { + description: ExternalDocumentationDescriptionVisitor, + url: ExternalDocumentationUrlVisitor, + }, + }, + RequestBody: { + $visitor: RequestBodyVisitor, + fixedFields: {}, + }, + Callback: { + $visitor: CallbackVisitor, + fixedFields: {}, + }, + Reference: { + $visitor: ReferenceVisitor, + fixedFields: {}, + }, SecurityRequirement: { $visitor: SecurityRequirementVisitor, }, diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/generics/AlternatingVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/generics/AlternatingVisitor.ts new file mode 100644 index 0000000000..50be6ed91c --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-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-openapi3-1-yaml/src/parser/visitors/generics/FixedFieldsYamlMappingVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/generics/FixedFieldsYamlMappingVisitor.ts index a08d38932f..1d12823c90 100644 --- 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 @@ -45,7 +45,7 @@ const FixedFieldsYamlMappingVisitor = stampit(SpecificationVisitor, { const visitor = this.retrieveVisitorInstance([...specPath, 'fixedFields', keyName]); const keyElement = new this.namespace.elements.String(keyName); - visit(keyValuePairNode.value, visitor); + visit(valueNode, visitor); const memberElement = this.maybeAddSourceMap( keyValuePairNode, diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/generics/index.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/generics/index.ts index 9a55225e49..448bbdba91 100644 --- a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/generics/index.ts +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/generics/index.ts @@ -17,7 +17,7 @@ import SpecificationVisitor from '../SpecificationVisitor'; export const ScalarVisitor = stampit(SpecificationVisitor, { methods: { scalar(scalarNode: YamlScalar): typeof BREAK { - const stringElement = new this.namespace.elements.String(scalarNode.content); + const stringElement = this.namespace.toElement(scalarNode.content); this.element = this.maybeAddSourceMap(scalarNode, stringElement); return BREAK; }, diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/ParametersVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/ParametersVisitor.ts new file mode 100644 index 0000000000..a070bbe526 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/ParametersVisitor.ts @@ -0,0 +1,34 @@ +import stampit from 'stampit'; +import { YamlSequence } from 'apidom-ast'; + +import { BREAK } from '..'; +import SpecificationVisitor from '../SpecificationVisitor'; +import { isParameterObject, isReferenceObject } from '../../predicates'; +import { KindVisitor } from '../generics'; + +const ParametersVisitor = stampit(KindVisitor, SpecificationVisitor, { + init() { + this.element = new this.namespace.elements.Array(); + this.element.classes.push('parameters'); + }, + methods: { + sequence(sequenceNode: YamlSequence) { + sequenceNode.content.forEach((item): void => { + if (isParameterObject({}, item)) { + this.element.push(new this.namespace.elements.Parameter()); + } else if (isReferenceObject({}, item)) { + this.element.push(new this.namespace.elements.Reference()); + } else { + const element = this.nodeToElement(['kind'], item); + this.element.push(element); + } + }); + + this.maybeAddSourceMap(sequenceNode, this.element); + + return BREAK; + }, + }, +}); + +export default ParametersVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/callback/index.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/callback/index.ts new file mode 100644 index 0000000000..422dc4b6d0 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/callback/index.ts @@ -0,0 +1,16 @@ +import stampit from 'stampit'; +import { always } from 'ramda'; + +import { KindVisitor } from '../../generics'; +import FixedFieldsYamlMappingVisitor from '../../generics/FixedFieldsYamlMappingVisitor'; + +const CallbackVisitor = stampit(KindVisitor, FixedFieldsYamlMappingVisitor, { + props: { + specPath: always(['document', 'objects', 'Callback']), + }, + init() { + this.element = new this.namespace.elements.Callback(); + }, +}); + +export default CallbackVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/external-documentation/DescriptionVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/external-documentation/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/external-documentation/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/external-documentation/UrlVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/external-documentation/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/external-documentation/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/external-documentation/index.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/external-documentation/index.ts new file mode 100644 index 0000000000..0ea27459d2 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/external-documentation/index.ts @@ -0,0 +1,16 @@ +import stampit from 'stampit'; +import { always } from 'ramda'; + +import { KindVisitor } from '../../generics'; +import FixedFieldsYamlMappingVisitor from '../../generics/FixedFieldsYamlMappingVisitor'; + +const ExternalDocumentationVisitor = stampit(KindVisitor, FixedFieldsYamlMappingVisitor, { + props: { + specPath: always(['document', 'objects', 'ExternalDocumentation']), + }, + init() { + this.element = new this.namespace.elements.ExternalDocumentation(); + }, +}); + +export default ExternalDocumentationVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/operation/CallbacksVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/operation/CallbacksVisitor.ts new file mode 100644 index 0000000000..81da0285b3 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/operation/CallbacksVisitor.ts @@ -0,0 +1,25 @@ +import stampit from 'stampit'; +import { isYamlMapping } from 'apidom-ast'; + +import MapYamlMappingVisitor from '../../generics/MapYamlMappingVisitor'; +import { isReferenceObject } from '../../../predicates'; +import { KindVisitor } from '../../generics'; + +const CallbacksVisitor = stampit(KindVisitor, MapYamlMappingVisitor, { + props: { + specPath: (node: unknown) => { + // eslint-disable-next-line no-nested-ternary + return isReferenceObject({}, node) + ? ['document', 'objects', 'Reference'] + : isYamlMapping(node) + ? ['document', 'objects', 'Callback'] + : ['kind']; + }, + }, + init() { + this.element = new this.namespace.elements.Object(); + this.element.classes.push('callbacks'); + }, +}); + +export default CallbacksVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/operation/DeprecatedVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/operation/DeprecatedVisitor.ts new file mode 100644 index 0000000000..493d00d539 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/operation/DeprecatedVisitor.ts @@ -0,0 +1,7 @@ +import stampit from 'stampit'; + +import { KindVisitor } from '../../generics'; + +const DeprecatedVisitor = stampit(KindVisitor); + +export default DeprecatedVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/operation/DescriptionVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/operation/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/operation/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/operation/OperationIdVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/operation/OperationIdVisitor.ts new file mode 100644 index 0000000000..711ec61648 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/operation/OperationIdVisitor.ts @@ -0,0 +1,7 @@ +import stampit from 'stampit'; + +import { KindVisitor } from '../../generics'; + +const OperationIdVisitor = stampit(KindVisitor); + +export default OperationIdVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/operation/RequestBodyVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/operation/RequestBodyVisitor.ts new file mode 100644 index 0000000000..6cb4678591 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/operation/RequestBodyVisitor.ts @@ -0,0 +1,17 @@ +import stampit from 'stampit'; +import { T as stubTrue } from 'ramda'; + +import { isRequestBodyObject, isReferenceObject } from '../../../predicates'; +import AlternatingVisitor from '../../generics/AlternatingVisitor'; + +const RequestBodyVisitor = stampit(AlternatingVisitor, { + props: { + alternator: [ + { predicate: isRequestBodyObject({}), specPath: ['document', 'objects', 'RequestBody'] }, + { predicate: isReferenceObject({}), specPath: ['document', 'objects', 'Reference'] }, + { predicate: stubTrue, specPath: ['kind'] }, + ], + }, +}); + +export default RequestBodyVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/operation/SummaryVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/operation/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/operation/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/operation/TagsVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/operation/TagsVisitor.ts new file mode 100644 index 0000000000..37ca59760e --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/operation/TagsVisitor.ts @@ -0,0 +1,20 @@ +import stampit from 'stampit'; +import { YamlSequence } from 'apidom-ast'; + +import SpecificationVisitor from '../../SpecificationVisitor'; +import { KindVisitor } from '../../generics'; + +const TagsVisitor = stampit(KindVisitor, SpecificationVisitor, { + methods: { + sequence(sequenceNode: YamlSequence) { + // @ts-ignore + const result = KindVisitor.compose.methods.sequence.call(this, sequenceNode); + + this.element.classes.push('tags'); + + return result; + }, + }, +}); + +export default TagsVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/operation/index.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/operation/index.ts new file mode 100644 index 0000000000..36962f0685 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/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-openapi3-1-yaml/src/parser/visitors/open-api-3-1/path-item/$RefVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/path-item/$RefVisitor.ts new file mode 100644 index 0000000000..45720b9429 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/path-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-openapi3-1-yaml/src/parser/visitors/open-api-3-1/path-item/DescriptionVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/path-item/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/path-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-openapi3-1-yaml/src/parser/visitors/open-api-3-1/path-item/SummaryVisitor.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/path-item/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/path-item/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/path-item/index.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/path-item/index.ts new file mode 100644 index 0000000000..158f5bbd66 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/path-item/index.ts @@ -0,0 +1,28 @@ +import stampit from 'stampit'; +import { StringElement } from 'minim'; +import { always } from 'ramda'; +import { isOperationElement, OperationElement } from 'apidom-ns-openapi3-1'; + +import FixedFieldsYamlMappingVisitor from '../../generics/FixedFieldsYamlMappingVisitor'; +import { KindVisitor } from '../../generics'; + +const PathItemVisitor = stampit(KindVisitor, FixedFieldsYamlMappingVisitor).init( + function PathItemVisitor() { + this.element = new this.namespace.elements.PathItem(); + this.specPath = always(['document', 'objects', 'PathItem']); + + this.mapping = { + leave() { + this.element + .filter(isOperationElement) + .forEach((operationElement: OperationElement, httpMethodElementCI: StringElement) => { + const httpMethod = httpMethodElementCI.toValue().toUpperCase(); + const httpMethodElementCS = new this.namespace.elements.String(httpMethod); + operationElement.setMetaProperty('httpMethod', httpMethodElementCS); + }); + }, + }; + }, +); + +export default PathItemVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/paths/index.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/paths/index.ts new file mode 100644 index 0000000000..26c85adf23 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/paths/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 PathsVisitor = stampit(KindVisitor, PatternedFieldsYamlMappingVisitor, { + props: { + fieldPatternPredicate: test(/^\/(?.*)$/), + specPath: always(['document', 'objects', 'PathItem']), + canSupportSpecificationExtensions: true, + }, + init() { + this.element = new this.namespace.elements.Paths(); + }, +}); + +export default PathsVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/reference/index.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/reference/index.ts new file mode 100644 index 0000000000..2569216cd1 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/reference/index.ts @@ -0,0 +1,16 @@ +import stampit from 'stampit'; +import { always } from 'ramda'; + +import FixedFieldsYamlMappingVisitor from '../../generics/FixedFieldsYamlMappingVisitor'; +import { KindVisitor } from '../../generics'; + +const ReferenceVisitor = stampit(KindVisitor, FixedFieldsYamlMappingVisitor, { + props: { + specPath: always(['document', 'objects', 'Reference']), + }, + init() { + this.element = new this.namespace.elements.Reference(); + }, +}); + +export default ReferenceVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/request-body/index.ts b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/request-body/index.ts new file mode 100644 index 0000000000..dedce051b8 --- /dev/null +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/src/parser/visitors/open-api-3-1/request-body/index.ts @@ -0,0 +1,16 @@ +import stampit from 'stampit'; +import { always } from 'ramda'; + +import FixedFieldsYamlMappingVisitor from '../../generics/FixedFieldsYamlMappingVisitor'; +import { KindVisitor } from '../../generics'; + +const RequestBodyVisitor = stampit(KindVisitor, FixedFieldsYamlMappingVisitor, { + props: { + specPath: always(['document', 'objects', 'RequestBody']), + }, + init() { + this.element = new this.namespace.elements.RequestBody(); + }, +}); + +export default RequestBodyVisitor; diff --git a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/test/fixtures/sample-api.yaml b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/test/fixtures/sample-api.yaml index 642a577806..2b562f79ab 100644 --- a/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/test/fixtures/sample-api.yaml +++ b/apidom/packages/apidom-parser-adapter-openapi3-1-yaml/test/fixtures/sample-api.yaml @@ -61,5 +61,73 @@ security: - petstore_auth: - write:pets - read:pets +paths: + /users: + summary: path item summary + description: path item description + get: + tags: + - tag1 + - tag2 + summary: Returns a list of users. + description: Optional extended description in CommonMark or HTML. + externalDocs: + description: Find more info here + url: https://example.com + operationId: getUserList + parameters: + name: userId + in: query + description: ID of the user + required: true + requestBody: + content: {} + responses: + 200: + description: A JSON array of user names + content: + application/json: + schema: + type: array + items: + type: string + 201: + description: A response + content: + application/json: + schema: + $ref: #/components/schemas/User + xxx: + key: val + callbacks: + myCallback: + '{$request.query.queryUrl}': + post: + requestBody: + description: Callback payload + content: + application/json: + schema: + $ref: #/components/schemas/User + responses: + 200: + description: callback successfully processed + deprecated: true + security: + - {} + - petstore_auth: + - write:pets + - read:pets + servers: + - url: http://api.example.com/v3 + description: Redundant server description, e.g. redundant server + servers: + - url: http://api.example.com/v2 + description: Redundant server description, e.g. redundant server + parameters: + name: userId + in: query + description: ID of the user + required: true ... prop: value