Skip to content

Commit 6f12e94

Browse files
committed
feat: add merge-all-of back (main thread only)
1 parent cb363ec commit 6f12e94

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/components/JsonSchemaViewer.tsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as React from 'react';
77
import { JSONSchema4 } from 'json-schema';
88
import { SchemaTree } from '../tree/tree';
99
import { GoToRefHandler, RowRenderer } from '../types';
10+
import { mergeAllOf } from '../utils';
1011
import { isSchemaViewerEmpty } from '../utils/isSchemaViewerEmpty';
1112
import { SchemaTree as SchemaTreeComponent } from './SchemaTree';
1213

@@ -35,7 +36,11 @@ export class JsonSchemaViewerComponent extends React.PureComponent<IJsonSchemaVi
3536
super(props);
3637

3738
this.treeState = new TreeState();
38-
this.tree = new SchemaTree(this.schema, this.treeState, this.expandedDepth);
39+
this.tree = new SchemaTree(
40+
props.mergeAllOf ? mergeAllOf(props.schema) : props.schema,
41+
this.treeState,
42+
this.expandedDepth,
43+
);
3944
this.treeStore = new TreeStore(this.tree, this.treeState, {
4045
defaultExpandedDepth: this.expandedDepth,
4146
});
@@ -53,10 +58,6 @@ export class JsonSchemaViewerComponent extends React.PureComponent<IJsonSchemaVi
5358
return 1;
5459
}
5560

56-
protected get schema() {
57-
return this.props.schema;
58-
}
59-
6061
protected renderSchema() {
6162
if (this.tree.count > 1) {
6263
for (const child of this.tree) {
@@ -78,7 +79,7 @@ export class JsonSchemaViewerComponent extends React.PureComponent<IJsonSchemaVi
7879
this.tree.expandedDepth = this.expandedDepth;
7980
this.renderSchema();
8081
} else if (prevProps.schema !== this.props.schema || prevProps.mergeAllOf !== this.props.mergeAllOf) {
81-
this.tree.schema = this.props.schema;
82+
this.tree.schema = this.props.mergeAllOf ? mergeAllOf(this.props.schema) : this.props.schema;
8283
this.renderSchema();
8384
}
8485
}

src/utils/mergeAllOf.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { JSONSchema4 } from 'json-schema';
22
// @ts-ignore
33
import resolveAllOf from 'json-schema-merge-allof';
4+
import { cloneDeep } from 'lodash-es';
45

56
export const mergeAllOf = (schema: JSONSchema4) => {
6-
return resolveAllOf(schema, {
7+
return resolveAllOf(cloneDeep(schema), {
78
resolvers: {
89
defaultResolver(values: any) {
910
return Object.assign({}, ...values);

0 commit comments

Comments
 (0)