diff --git a/packages/apidom-ns-asyncapi-2/src/predicates.ts b/packages/apidom-ns-asyncapi-2/src/predicates.ts index ca5e6aed49..d326bc820d 100644 --- a/packages/apidom-ns-asyncapi-2/src/predicates.ts +++ b/packages/apidom-ns-asyncapi-2/src/predicates.ts @@ -1,4 +1,9 @@ -import { createPredicate, isBooleanElement, isStringElement } from '@swagger-api/apidom-core'; +import { + createPredicate, + isBooleanElement, + isStringElement, + toValue, +} from '@swagger-api/apidom-core'; import AsyncApi2Element from './elements/AsyncApi2'; import AsyncApiVersionElement from './elements/AsyncApiVersion'; @@ -70,7 +75,7 @@ export const isChannelItemElementExternal = (element: any): element is ChannelIt return false; } - const value = element.$ref.toValue(); + const value = toValue(element.$ref); return typeof value === 'string' && value.length > 0 && !value.startsWith('#'); }; @@ -180,7 +185,7 @@ export const isReferenceElementExternal = (element: any): element is ReferenceEl return false; } - const value = element.$ref.toValue(); + const value = toValue(element.$ref); return typeof value === 'string' && value.length > 0 && !value.startsWith('#'); }; diff --git a/packages/apidom-ns-asyncapi-2/src/refractor/plugins/replace-empty-element.ts b/packages/apidom-ns-asyncapi-2/src/refractor/plugins/replace-empty-element.ts index 7d9e53e528..ca672875db 100644 --- a/packages/apidom-ns-asyncapi-2/src/refractor/plugins/replace-empty-element.ts +++ b/packages/apidom-ns-asyncapi-2/src/refractor/plugins/replace-empty-element.ts @@ -8,6 +8,7 @@ import { includesClasses, isArrayElement, cloneDeep, + toValue, } from '@swagger-api/apidom-core'; import mediaTypes from '../../media-types'; @@ -389,7 +390,7 @@ const schema = { payload(...args: any[]) { // @ts-ignore const { context: messageElement } = this; - const schemaFormat = defaultTo(mediaTypes.latest(), messageElement.schemaFormat?.toValue()); + const schemaFormat = defaultTo(mediaTypes.latest(), toValue(messageElement.schemaFormat)); if (mediaTypes.includes(schemaFormat)) { return new SchemaElement(...args); @@ -1026,7 +1027,7 @@ const schema = { const findElementFactory = (ancestor: any, keyName: string) => { const elementType = getNodeType(ancestor); // @ts-ignore - const keyMapping = schema[elementType] || schema[ancestor.classes.first?.toValue?.()]; + const keyMapping = schema[elementType] || schema[toValue(ancestor.classes.first)]; return typeof keyMapping === 'undefined' ? undefined @@ -1044,7 +1045,7 @@ const plugin = () => () => { const [, , , ancestors] = rest; const ancestor = ancestors[ancestors.length - 1]; // @ts-ignore - const elementFactory = findElementFactory(ancestor, element.key.toValue()); + const elementFactory = findElementFactory(ancestor, toValue(element.key)); // no element factory found if (typeof elementFactory === 'undefined') return undefined; diff --git a/packages/apidom-ns-asyncapi-2/src/refractor/predicates.ts b/packages/apidom-ns-asyncapi-2/src/refractor/predicates.ts index 4a6e87a96a..86afa5f6c3 100644 --- a/packages/apidom-ns-asyncapi-2/src/refractor/predicates.ts +++ b/packages/apidom-ns-asyncapi-2/src/refractor/predicates.ts @@ -1,5 +1,11 @@ -import { MemberElement, isStringElement, isObjectElement, Element } from '@swagger-api/apidom-core'; import { startsWith } from 'ramda'; +import { + MemberElement, + isStringElement, + isObjectElement, + Element, + toValue, +} from '@swagger-api/apidom-core'; export const isAsyncApi2LikeElement = (element: T): boolean => { return ( @@ -39,5 +45,5 @@ export const isServerLikeElement = (element: T): boolean => { export const isAsyncApiExtension = (element: MemberElement): boolean => { // @ts-ignore - return isStringElement(element.key) && startsWith('x-', element.key.toValue()); + return isStringElement(element.key) && startsWith('x-', toValue(element.key)); }; diff --git a/packages/apidom-ns-asyncapi-2/src/refractor/visitors/async-api-2/AsyncApiVersionVisitor.ts b/packages/apidom-ns-asyncapi-2/src/refractor/visitors/async-api-2/AsyncApiVersionVisitor.ts index c18b05a092..c27f5364b5 100644 --- a/packages/apidom-ns-asyncapi-2/src/refractor/visitors/async-api-2/AsyncApiVersionVisitor.ts +++ b/packages/apidom-ns-asyncapi-2/src/refractor/visitors/async-api-2/AsyncApiVersionVisitor.ts @@ -1,5 +1,5 @@ import stampit from 'stampit'; -import { StringElement, BREAK } from '@swagger-api/apidom-core'; +import { StringElement, BREAK, toValue } from '@swagger-api/apidom-core'; import FallbackVisitor from '../FallbackVisitor'; import SpecificationVisitor from '../SpecificationVisitor'; @@ -8,7 +8,7 @@ import AsyncApiVersionElement from '../../../elements/AsyncApiVersion'; const AsyncApiVersionVisitor = stampit(SpecificationVisitor, FallbackVisitor, { methods: { StringElement(stringElement: StringElement) { - const asyncApiVersionElement = new AsyncApiVersionElement(stringElement.toValue()); + const asyncApiVersionElement = new AsyncApiVersionElement(toValue(stringElement)); this.copyMetaAndAttributes(stringElement, asyncApiVersionElement); diff --git a/packages/apidom-ns-asyncapi-2/src/refractor/visitors/async-api-2/DefaultContentTypeVisitor.ts b/packages/apidom-ns-asyncapi-2/src/refractor/visitors/async-api-2/DefaultContentTypeVisitor.ts index 73296bc517..d85fdd4c5b 100644 --- a/packages/apidom-ns-asyncapi-2/src/refractor/visitors/async-api-2/DefaultContentTypeVisitor.ts +++ b/packages/apidom-ns-asyncapi-2/src/refractor/visitors/async-api-2/DefaultContentTypeVisitor.ts @@ -1,5 +1,5 @@ import stampit from 'stampit'; -import { StringElement, BREAK } from '@swagger-api/apidom-core'; +import { StringElement, BREAK, toValue } from '@swagger-api/apidom-core'; import FallbackVisitor from '../FallbackVisitor'; import SpecificationVisitor from '../SpecificationVisitor'; @@ -8,7 +8,7 @@ import DefaultContentTypeElement from '../../../elements/DefaultContentType'; const DefaultContentTypeVisitor = stampit(SpecificationVisitor, FallbackVisitor, { methods: { StringElement(stringElement: StringElement) { - const defaultContentTypeElement = new DefaultContentTypeElement(stringElement.toValue()); + const defaultContentTypeElement = new DefaultContentTypeElement(toValue(stringElement)); this.copyMetaAndAttributes(stringElement, defaultContentTypeElement); diff --git a/packages/apidom-ns-asyncapi-2/src/refractor/visitors/async-api-2/IdentifierVisitor.ts b/packages/apidom-ns-asyncapi-2/src/refractor/visitors/async-api-2/IdentifierVisitor.ts index f8083ee623..539f727f15 100644 --- a/packages/apidom-ns-asyncapi-2/src/refractor/visitors/async-api-2/IdentifierVisitor.ts +++ b/packages/apidom-ns-asyncapi-2/src/refractor/visitors/async-api-2/IdentifierVisitor.ts @@ -1,5 +1,5 @@ import stampit from 'stampit'; -import { StringElement, BREAK } from '@swagger-api/apidom-core'; +import { StringElement, BREAK, toValue } from '@swagger-api/apidom-core'; import FallbackVisitor from '../FallbackVisitor'; import SpecificationVisitor from '../SpecificationVisitor'; @@ -8,7 +8,7 @@ import IdentifierElement from '../../../elements/Identifier'; const IdentifierVisitor = stampit(SpecificationVisitor, FallbackVisitor, { methods: { StringElement(stringElement: StringElement) { - const identifierElement = new IdentifierElement(stringElement.toValue()); + const identifierElement = new IdentifierElement(toValue(stringElement)); this.copyMetaAndAttributes(stringElement, identifierElement); diff --git a/packages/apidom-ns-asyncapi-2/src/refractor/visitors/async-api-2/info/VersionVisitor.ts b/packages/apidom-ns-asyncapi-2/src/refractor/visitors/async-api-2/info/VersionVisitor.ts index 04a257abae..bcdf3dc6c9 100644 --- a/packages/apidom-ns-asyncapi-2/src/refractor/visitors/async-api-2/info/VersionVisitor.ts +++ b/packages/apidom-ns-asyncapi-2/src/refractor/visitors/async-api-2/info/VersionVisitor.ts @@ -1,12 +1,12 @@ import stampit from 'stampit'; -import { StringElement, BREAK } from '@swagger-api/apidom-core'; +import { StringElement, BREAK, toValue } from '@swagger-api/apidom-core'; import FallbackVisitor from '../../FallbackVisitor'; const VersionVisitor = stampit(FallbackVisitor, { methods: { StringElement(stringElement: StringElement) { - this.element = new StringElement(stringElement.toValue()); + this.element = new StringElement(toValue(stringElement)); this.copyMetaAndAttributes(stringElement, this.element); this.element.classes.push('api-version'); diff --git a/packages/apidom-ns-asyncapi-2/src/refractor/visitors/async-api-2/message/index.ts b/packages/apidom-ns-asyncapi-2/src/refractor/visitors/async-api-2/message/index.ts index 0f4193476f..6fd9fc24c8 100644 --- a/packages/apidom-ns-asyncapi-2/src/refractor/visitors/async-api-2/message/index.ts +++ b/packages/apidom-ns-asyncapi-2/src/refractor/visitors/async-api-2/message/index.ts @@ -1,6 +1,6 @@ import stampit from 'stampit'; import { always, defaultTo } from 'ramda'; -import { ObjectElement, isObjectElement } from '@swagger-api/apidom-core'; +import { ObjectElement, isObjectElement, toValue } from '@swagger-api/apidom-core'; import mediaTypes from '../../../../media-types'; import MessageElement from '../../../../elements/Message'; @@ -28,7 +28,7 @@ const MessageVisitor = stampit(FixedFieldsVisitor, FallbackVisitor, { const payload = this.element.get('payload'); const schemaFormat = defaultTo( mediaTypes.latest(), - objectElement.get('schemaFormat')?.toValue(), + toValue(objectElement.get('schemaFormat')), ); if (mediaTypes.includes(schemaFormat) && isReferenceLikeElement(payload)) { diff --git a/packages/apidom-ns-asyncapi-2/src/refractor/visitors/generics/PatternedFieldsVisitor.ts b/packages/apidom-ns-asyncapi-2/src/refractor/visitors/generics/PatternedFieldsVisitor.ts index 8e3877a6ee..2aa499cade 100644 --- a/packages/apidom-ns-asyncapi-2/src/refractor/visitors/generics/PatternedFieldsVisitor.ts +++ b/packages/apidom-ns-asyncapi-2/src/refractor/visitors/generics/PatternedFieldsVisitor.ts @@ -50,8 +50,8 @@ const PatternedFieldsJsonObjectVisitor = stampit(SpecificationVisitor, { ); this.element.content.push(extensionElement); } else if ( - !this.ignoredFields.includes(key.toValue()) && - this.fieldPatternPredicate(key.toValue()) + !this.ignoredFields.includes(toValue(key)) && + this.fieldPatternPredicate(toValue(key)) ) { const specPath = this.specPath(value); const patternedFieldElement = this.toRefractedElement(specPath, value); diff --git a/packages/apidom-ns-asyncapi-2/test/refractor/index.ts b/packages/apidom-ns-asyncapi-2/test/refractor/index.ts index 7978dc1afc..1d9f7d133c 100644 --- a/packages/apidom-ns-asyncapi-2/test/refractor/index.ts +++ b/packages/apidom-ns-asyncapi-2/test/refractor/index.ts @@ -346,7 +346,7 @@ describe('refractor', function () { }); // @ts-ignore - assert.strictEqual(asyncApiElement.asyncapi.meta.get('metaKey').toValue(), 'metaValue'); + assert.strictEqual(toValue(asyncApiElement.asyncapi.meta.get('metaKey')), 'metaValue'); }); }); });