diff --git a/apidom/packages/@types/minim.d.ts b/apidom/packages/@types/minim.d.ts index 7fc020ae91..d962c21161 100644 --- a/apidom/packages/@types/minim.d.ts +++ b/apidom/packages/@types/minim.d.ts @@ -112,6 +112,8 @@ declare module 'minim' { export class ObjectElement extends ArrayElement { constructor(content?: Record, meta?: Meta, attributes?: Attributes); + remove(name: string): Element; + set(key: string | StringElement | number, value: any): ObjectElement; hasKey(value: string): boolean; @@ -128,6 +130,8 @@ declare module 'minim' { callback: (value: Element, key: Element, member: MemberElement) => MemberElement, thisArg?: unknown, ): Array; + + keys(): unknown[]; } export class MemberElement extends Element { diff --git a/apidom/packages/apidom-ns-asyncapi-2-0/src/refractor/visitors/generics/MixedFieldsVisitor.ts b/apidom/packages/apidom-ns-asyncapi-2-0/src/refractor/visitors/generics/MixedFieldsVisitor.ts index 6c36d855d4..02a22f48f8 100644 --- a/apidom/packages/apidom-ns-asyncapi-2-0/src/refractor/visitors/generics/MixedFieldsVisitor.ts +++ b/apidom/packages/apidom-ns-asyncapi-2-0/src/refractor/visitors/generics/MixedFieldsVisitor.ts @@ -1,4 +1,5 @@ import stampit from 'stampit'; +import { difference } from 'ramda'; import { noop } from 'ramda-adjunct'; import { ObjectElement, BREAK } from 'apidom'; @@ -12,14 +13,18 @@ const MixedFieldsVisitor = stampit(FixedFieldsVisitor, PatternedFieldsVisitor, { }, methods: { ObjectElement(objectElement: ObjectElement) { - const { specPath } = this; + const { specPath, ignoredFields } = this; try { this.specPath = this.specPathFixedFields; + const fixedFields = this.retrieveFixedFields(this.specPath(objectElement)); + // let FixedFieldsVisitor only process fixed fields and leave rest to PatternedFieldsVisitor + this.ignoredFields = [...ignoredFields, ...difference(objectElement.keys(), fixedFields)]; // @ts-ignore FixedFieldsVisitor.compose.methods.ObjectElement.call(this, objectElement); this.specPath = this.specPathPatternedFields; + this.ignoredFields = ignoredFields; // @ts-ignore PatternedFieldsVisitor.compose.methods.ObjectElement.call(this, objectElement); } catch (e) { diff --git a/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/generics/MixedFieldsVisitor.ts b/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/generics/MixedFieldsVisitor.ts index 6c36d855d4..02a22f48f8 100644 --- a/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/generics/MixedFieldsVisitor.ts +++ b/apidom/packages/apidom-ns-openapi-3-1/src/refractor/visitors/generics/MixedFieldsVisitor.ts @@ -1,4 +1,5 @@ import stampit from 'stampit'; +import { difference } from 'ramda'; import { noop } from 'ramda-adjunct'; import { ObjectElement, BREAK } from 'apidom'; @@ -12,14 +13,18 @@ const MixedFieldsVisitor = stampit(FixedFieldsVisitor, PatternedFieldsVisitor, { }, methods: { ObjectElement(objectElement: ObjectElement) { - const { specPath } = this; + const { specPath, ignoredFields } = this; try { this.specPath = this.specPathFixedFields; + const fixedFields = this.retrieveFixedFields(this.specPath(objectElement)); + // let FixedFieldsVisitor only process fixed fields and leave rest to PatternedFieldsVisitor + this.ignoredFields = [...ignoredFields, ...difference(objectElement.keys(), fixedFields)]; // @ts-ignore FixedFieldsVisitor.compose.methods.ObjectElement.call(this, objectElement); this.specPath = this.specPathPatternedFields; + this.ignoredFields = ignoredFields; // @ts-ignore PatternedFieldsVisitor.compose.methods.ObjectElement.call(this, objectElement); } catch (e) {