Skip to content

Commit 3644592

Browse files
committed
fix(walker): anyOf/oneOf handling
1 parent a9db9a5 commit 3644592

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/tree/tree.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import type { SchemaTreeRefDereferenceFn } from '../resolver/types';
66
import type { SchemaFragment } from '../types';
77
import { isObjectLiteral } from '../utils';
88
import { get } from '../utils/get';
9+
import { Walker } from '../walker';
910
import type { WalkerRefResolver } from '../walker/types';
10-
import { Walker } from '../walker/walk';
1111

1212
export type SchemaTreeOptions = {
1313
mergeAllOf: boolean;
@@ -26,6 +26,10 @@ export class SchemaTree {
2626
});
2727
}
2828

29+
public clear() {
30+
this.root.children.length = 0;
31+
}
32+
2933
public populate() {
3034
this.invokeWalker(this.walker);
3135
}

src/walker/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './walker';
2+
export * from './types';

src/walker/walk.ts renamed to src/walker/walker.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,14 @@ export class Walker extends EventEmitter<Dictionary<WalkerEventHandler, WalkerEv
240240

241241
if (SchemaCombinerName.OneOf in fragment || SchemaCombinerName.AnyOf in fragment) {
242242
try {
243-
for (const item of mergeOneOrAnyOf(fragment, path, walkingOptions)) {
244-
yield new RegularNode(item);
243+
const merged = mergeOneOrAnyOf(fragment, path, walkingOptions);
244+
if (merged.length === 1) {
245+
yield new RegularNode(merged[0]);
246+
} else {
247+
const combiner = SchemaCombinerName.OneOf in fragment ? SchemaCombinerName.OneOf : SchemaCombinerName.AnyOf;
248+
yield new RegularNode({
249+
[combiner]: merged,
250+
});
245251
}
246252

247253
return;

0 commit comments

Comments
 (0)