2525import test from 'ava' ;
2626
2727import { JsonSchema } from '../../src/models/jsonSchema' ;
28- import { deriveType } from '../../src/util/index' ;
28+ import { deriveTypes } from '../../src/util/index' ;
2929
3030test ( 'derive type with type' , t => {
3131 const schema : JsonSchema = {
3232 type : 'string'
3333 } ;
34- t . is ( deriveType ( schema ) , 'string' ) ;
34+ t . is ( deriveTypes ( schema ) . length , 1 ) ;
35+ t . is ( deriveTypes ( schema ) [ 0 ] , 'string' ) ;
3536} ) ;
3637
3738test ( 'derive type w/o type - properties object' , t => {
@@ -40,7 +41,8 @@ test('derive type w/o type - properties object', t => {
4041 foo : { type : 'string' }
4142 }
4243 } ;
43- t . is ( deriveType ( schema ) , 'object' ) ;
44+ t . is ( deriveTypes ( schema ) . length , 1 ) ;
45+ t . is ( deriveTypes ( schema ) [ 0 ] , 'object' ) ;
4446} ) ;
4547
4648test ( 'derive type w/o type - additionalProperties object' , t => {
@@ -49,7 +51,8 @@ test('derive type w/o type - additionalProperties object', t => {
4951 type : 'string'
5052 }
5153 } ;
52- t . is ( deriveType ( schema ) , 'object' ) ;
54+ t . is ( deriveTypes ( schema ) . length , 1 ) ;
55+ t . is ( deriveTypes ( schema ) [ 0 ] , 'object' ) ;
5356} ) ;
5457
5558test ( 'derive type w/o type - items array' , t => {
@@ -58,29 +61,33 @@ test('derive type w/o type - items array', t => {
5861 type : 'string'
5962 }
6063 } ;
61- t . is ( deriveType ( schema ) , 'array' ) ;
64+ t . is ( deriveTypes ( schema ) . length , 1 ) ;
65+ t . is ( deriveTypes ( schema ) [ 0 ] , 'array' ) ;
6266} ) ;
6367
6468test ( 'derive type with type - union' , t => {
6569 const schema : JsonSchema = {
6670 type : [ 'string' , 'number' ]
6771 } ;
72+ t . is ( deriveTypes ( schema ) . length , 2 ) ;
6873 // we just take the first, as derive type returns exactly one value
69- t . is ( deriveType ( schema ) , 'string' ) ;
74+ t . is ( deriveTypes ( schema ) , schema . type ) ;
7075} ) ;
7176
7277test ( 'derive type with type - allOf first has type' , t => {
7378 const schema : JsonSchema = {
7479 allOf : [ { type : 'string' } , { enum : [ 'foo' , 'bar' ] } ]
7580 } ;
76- t . is ( deriveType ( schema ) , 'string' ) ;
81+ t . is ( deriveTypes ( schema ) . length , 1 ) ;
82+ t . is ( deriveTypes ( schema ) [ 0 ] , 'string' ) ;
7783} ) ;
7884
7985test ( 'derive type with type - allOf other has type' , t => {
8086 const schema : JsonSchema = {
8187 allOf : [ { enum : [ 'foo' , 'bar' ] } , { type : 'string' } ]
8288 } ;
83- t . is ( deriveType ( schema ) , 'string' ) ;
89+ t . is ( deriveTypes ( schema ) . length , 1 ) ;
90+ t . is ( deriveTypes ( schema ) [ 0 ] , 'string' ) ;
8491} ) ;
8592
8693test ( 'derive type w/o type - allOf other has type' , t => {
@@ -90,5 +97,6 @@ test('derive type w/o type - allOf other has type', t => {
9097 { properties : { bar : { type : 'string' } } }
9198 ]
9299 } ;
93- t . is ( deriveType ( schema ) , 'object' ) ;
100+ t . is ( deriveTypes ( schema ) . length , 1 ) ;
101+ t . is ( deriveTypes ( schema ) [ 0 ] , 'object' ) ;
94102} ) ;
0 commit comments