1- import { Tree } from '@stoplight/tree-list' ;
1+ import { Tree , TreeListParentNode } from '@stoplight/tree-list' ;
22import * as fs from 'fs' ;
3+ import { JSONSchema4 } from 'json-schema' ;
34import * as path from 'path' ;
45import { generateId } from '../../utils/generateId' ;
6+ import { getNodeMetadata } from '../metadata' ;
57import { populateTree } from '../utils/populateTree' ;
68
79const 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} ) ;
0 commit comments