diff --git a/src/tree/__tests__/populateTree.spec.ts b/src/tree/__tests__/populateTree.spec.ts index 61ce88c6..9bd3664d 100644 --- a/src/tree/__tests__/populateTree.spec.ts +++ b/src/tree/__tests__/populateTree.spec.ts @@ -1,7 +1,9 @@ -import { Tree } from '@stoplight/tree-list'; +import { Tree, TreeListParentNode } from '@stoplight/tree-list'; import * as fs from 'fs'; +import { JSONSchema4 } from 'json-schema'; import * as path from 'path'; import { generateId } from '../../utils/generateId'; +import { getNodeMetadata } from '../metadata'; import { populateTree } from '../utils/populateTree'; const BASE_PATH = path.resolve(__dirname, '../../__fixtures__/'); @@ -47,9 +49,9 @@ describe('populateTree util', () => { }); it('given schema with complex types, throws', () => { - const schema = { + const schema: JSONSchema4 = { type: [ - 'null', + 'null' as any, { type: 'object', properties: { @@ -63,8 +65,25 @@ describe('populateTree util', () => { }; const root = Tree.createArtificialRoot(); - expect(() => populateTree(schema as any, root, 0, [], null)).toThrow( + expect(() => populateTree(schema, root, 0, [], null)).toThrow( 'The "type" property must be a string, or an array of strings. Objects and array of objects are not valid.', ); }); + + it('includes properties with unknown types', () => { + const schema: JSONSchema4 = { + type: 'object', + properties: { + foo: { + __ERROR__: 'dd', + }, + }, + }; + + const root = Tree.createArtificialRoot(); + populateTree(schema, root, 0, [], null); + expect(getNodeMetadata((root.children[0] as TreeListParentNode).children[0])).toHaveProperty('schema', { + __ERROR__: 'dd', + }); + }); }); diff --git a/src/tree/utils/walk.ts b/src/tree/utils/walk.ts index c8599dfd..0f369601 100644 --- a/src/tree/utils/walk.ts +++ b/src/tree/utils/walk.ts @@ -72,6 +72,12 @@ function processNode(node: JSONSchema4): SchemaNode | void { // if ('not' in node) { // // todo: shall we support it? // } + + return { + id: generateId(), + validations: {}, + annotations: {}, + }; } export type WalkerValue = { diff --git a/src/types.ts b/src/types.ts index 2424e6e6..37d26831 100644 --- a/src/types.ts +++ b/src/types.ts @@ -31,7 +31,7 @@ export interface ICombinerNode { export interface IBaseNode extends Pick { id: string; readonly type?: JSONSchema4TypeName | JSONSchema4TypeName[]; - annotations: Pick; + annotations: Partial>; validations: Dictionary; required?: string[]; }