Skip to content

Commit

Permalink
fix(namespaces): fix duplicates in mixed fields visitor
Browse files Browse the repository at this point in the history
  • Loading branch information
char0n committed Mar 19, 2021
1 parent 13ec21c commit 725ecce
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions apidom/packages/@types/minim.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ declare module 'minim' {
export class ObjectElement extends ArrayElement {
constructor(content?: Record<string, unknown>, meta?: Meta, attributes?: Attributes);

remove(name: string): Element;

set(key: string | StringElement | number, value: any): ObjectElement;

hasKey(value: string): boolean;
Expand All @@ -128,6 +130,8 @@ declare module 'minim' {
callback: (value: Element, key: Element, member: MemberElement) => MemberElement,
thisArg?: unknown,
): Array<MemberElement>;

keys(): unknown[];
}

export class MemberElement extends Element {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import stampit from 'stampit';
import { difference } from 'ramda';
import { noop } from 'ramda-adjunct';
import { ObjectElement, BREAK } from 'apidom';

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import stampit from 'stampit';
import { difference } from 'ramda';
import { noop } from 'ramda-adjunct';
import { ObjectElement, BREAK } from 'apidom';

Expand All @@ -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) {
Expand Down

0 comments on commit 725ecce

Please sign in to comment.