@@ -288,15 +288,15 @@ describe('CommonModel', function() {
288288 const doc : Schema = { } ;
289289 let doc1 = CommonModel . toCommonModel ( doc ) ;
290290 let doc2 = CommonModel . toCommonModel ( doc ) ;
291- doc2 . items = [ { type : "string" } ] ;
291+ doc2 . items = [ CommonModel . toCommonModel ( { type : "string" } ) ] ;
292292 doc1 = CommonModel . mergeCommonModels ( doc1 , doc2 , doc ) ;
293293 expect ( doc1 . items ) . toEqual ( doc2 . items [ 0 ] ) ;
294294 } ) ;
295295 test ( 'should be merged when only left side is defined' , function ( ) {
296296 const doc : Schema = { } ;
297297 let doc1 = CommonModel . toCommonModel ( doc ) ;
298298 let doc2 = CommonModel . toCommonModel ( doc ) ;
299- doc1 . items = [ { type : "string" } , { type : "number" } ] ;
299+ doc1 . items = [ CommonModel . toCommonModel ( { type : "string" } ) , CommonModel . toCommonModel ( { type : "number" } ) ] ;
300300 doc1 = CommonModel . mergeCommonModels ( doc1 , doc2 , doc ) ;
301301 expect ( doc1 . items ) . toEqual ( { type : [ "string" , "number" ] , originalSchema : { } } ) ;
302302 } ) ;
@@ -312,17 +312,17 @@ describe('CommonModel', function() {
312312 const doc : Schema = { } ;
313313 let doc1 = CommonModel . toCommonModel ( doc ) ;
314314 let doc2 = CommonModel . toCommonModel ( doc ) ;
315- doc2 . items = { type : "string" } ;
316- doc1 . items = { type : "number" } ;
315+ doc2 . items = CommonModel . toCommonModel ( { type : "string" } ) ;
316+ doc1 . items = CommonModel . toCommonModel ( { type : "number" } ) ;
317317 doc1 = CommonModel . mergeCommonModels ( doc1 , doc2 , doc ) ;
318318 expect ( doc1 . items ) . toEqual ( { type : [ "number" , "string" ] , originalSchema : { } } ) ;
319319 } ) ;
320320 test ( 'should be merged when both sides are defined as array of schemas with different lengths' , function ( ) {
321321 const doc : Schema = { } ;
322322 let doc1 = CommonModel . toCommonModel ( doc ) ;
323323 let doc2 = CommonModel . toCommonModel ( doc ) ;
324- doc2 . items = [ { type : "string" } , { type : [ "boolean" ] } ] ;
325- doc1 . items = [ { type : [ "number" ] } ] ;
324+ doc2 . items = [ CommonModel . toCommonModel ( { type : "string" } ) , CommonModel . toCommonModel ( { type : "boolean" } ) ] ;
325+ doc1 . items = [ CommonModel . toCommonModel ( { type : "number" } ) ] ;
326326 doc1 = CommonModel . mergeCommonModels ( doc1 , doc2 , doc ) ;
327327 expect ( doc1 . items ) . toEqual ( { "originalSchema" : { } , "type" : [ "number" , "string" , "boolean" ] } ) ;
328328 } ) ;
@@ -340,25 +340,25 @@ describe('CommonModel', function() {
340340 const doc : Schema = { } ;
341341 let doc1 = CommonModel . toCommonModel ( doc ) ;
342342 let doc2 = CommonModel . toCommonModel ( doc ) ;
343- doc2 . properties = { "testProp" : { type : "string" } } ;
343+ doc2 . properties = { "testProp" : CommonModel . toCommonModel ( { type : "string" } ) } ;
344344 doc1 = CommonModel . mergeCommonModels ( doc1 , doc2 , doc ) ;
345345 expect ( doc1 . properties ) . toEqual ( doc2 . properties ) ;
346346 } ) ;
347347 test ( 'should be merged when both sides are defined' , function ( ) {
348348 const doc : Schema = { } ;
349349 let doc1 = CommonModel . toCommonModel ( doc ) ;
350350 let doc2 = CommonModel . toCommonModel ( doc ) ;
351- doc2 . properties = { "testProp" : { type : "string" } } ;
352- doc1 . properties = { "testProp2" : { type : "number" } } ;
351+ doc2 . properties = { "testProp" : CommonModel . toCommonModel ( { type : "string" } ) } ;
352+ doc1 . properties = { "testProp2" : CommonModel . toCommonModel ( { type : "number" } ) } ;
353353 doc1 = CommonModel . mergeCommonModels ( doc1 , doc2 , doc ) ;
354354 expect ( doc1 . properties ) . toEqual ( { "testProp" : { type : "string" } , "testProp2" : { type : "number" } } ) ;
355355 } ) ;
356356 test ( 'should be merged together when both sides are defined' , function ( ) {
357357 const doc : Schema = { } ;
358358 let doc1 = CommonModel . toCommonModel ( doc ) ;
359359 let doc2 = CommonModel . toCommonModel ( doc ) ;
360- doc2 . properties = { "testProp" : { type : "string" } } ;
361- doc1 . properties = { "testProp" : { type : "number" } } ;
360+ doc2 . properties = { "testProp" : CommonModel . toCommonModel ( { type : "string" } ) } ;
361+ doc1 . properties = { "testProp" : CommonModel . toCommonModel ( { type : "number" } ) } ;
362362 doc1 = CommonModel . mergeCommonModels ( doc1 , doc2 , doc ) ;
363363 expect ( doc1 . properties ) . toEqual ( { "testProp" : { type : [ "number" , "string" ] , originalSchema : { } } } ) ;
364364 } ) ;
@@ -371,4 +371,26 @@ describe('CommonModel', function() {
371371 } ) ;
372372 } ) ;
373373 } ) ;
374+
375+ describe ( 'helpers' , function ( ) {
376+ describe ( 'getFromSchema' , function ( ) {
377+ test ( 'should work' , function ( ) {
378+ const doc = { type : "string" , description : "Some description" } ;
379+ const d = CommonModel . toCommonModel ( doc ) ;
380+ d . originalSchema = doc ;
381+ const desc = d . getFromSchema ( 'description' ) ;
382+ expect ( desc ) . toEqual ( doc . description ) ;
383+ } ) ;
384+ } ) ;
385+
386+ describe ( 'isRequired' , function ( ) {
387+ test ( 'check that property is required' , function ( ) {
388+ const doc = { type : "object" , properties : { prop : { type : "string" } } } ;
389+ const d = CommonModel . toCommonModel ( doc ) ;
390+ d . required = [ "prop" ] ;
391+ expect ( d . isRequired ( "prop" ) ) . toEqual ( true ) ;
392+ expect ( d . isRequired ( "propX" ) ) . toEqual ( false ) ;
393+ } ) ;
394+ } ) ;
395+ } ) ;
374396} ) ;
0 commit comments