Skip to content

Commit f923926

Browse files
committed
fix: render unknown properties
1 parent 13ffc48 commit f923926

File tree

3 files changed

+30
-5
lines changed

3 files changed

+30
-5
lines changed

src/tree/__tests__/populateTree.spec.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import { Tree } from '@stoplight/tree-list';
1+
import { Tree, TreeListParentNode } from '@stoplight/tree-list';
22
import * as fs from 'fs';
3+
import { JSONSchema4 } from 'json-schema';
34
import * as path from 'path';
45
import { generateId } from '../../utils/generateId';
6+
import { getNodeMetadata } from '../metadata';
57
import { populateTree } from '../utils/populateTree';
68

79
const BASE_PATH = path.resolve(__dirname, '../../__fixtures__/');
@@ -47,9 +49,9 @@ describe('populateTree util', () => {
4749
});
4850

4951
it('given schema with complex types, throws', () => {
50-
const schema = {
52+
const schema: JSONSchema4 = {
5153
type: [
52-
'null',
54+
'null' as any,
5355
{
5456
type: 'object',
5557
properties: {
@@ -63,8 +65,25 @@ describe('populateTree util', () => {
6365
};
6466

6567
const root = Tree.createArtificialRoot();
66-
expect(() => populateTree(schema as any, root, 0, [], null)).toThrow(
68+
expect(() => populateTree(schema, root, 0, [], null)).toThrow(
6769
'The "type" property must be a string, or an array of strings. Objects and array of objects are not valid.',
6870
);
6971
});
72+
73+
it('includes properties with unknown types', () => {
74+
const schema: JSONSchema4 = {
75+
type: 'object',
76+
properties: {
77+
foo: {
78+
__ERROR__: 'dd',
79+
},
80+
},
81+
};
82+
83+
const root = Tree.createArtificialRoot();
84+
populateTree(schema, root, 0, [], null);
85+
expect(getNodeMetadata((root.children[0] as TreeListParentNode).children[0])).toHaveProperty('schema', {
86+
__ERROR__: 'dd',
87+
});
88+
});
7089
});

src/tree/utils/walk.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ function processNode(node: JSONSchema4): SchemaNode | void {
7272
// if ('not' in node) {
7373
// // todo: shall we support it?
7474
// }
75+
76+
return {
77+
id: generateId(),
78+
validations: {},
79+
annotations: {},
80+
};
7581
}
7682

7783
export type WalkerValue = {

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export interface ICombinerNode {
3131
export interface IBaseNode extends Pick<JSONSchema4, 'enum'> {
3232
id: string;
3333
readonly type?: JSONSchema4TypeName | JSONSchema4TypeName[];
34-
annotations: Pick<JSONSchema4, JSONSchema4Annotations>;
34+
annotations: Partial<Pick<JSONSchema4, JSONSchema4Annotations>>;
3535
validations: Dictionary<unknown>;
3636
required?: string[];
3737
}

0 commit comments

Comments
 (0)