11import convert from "../src" ;
22
3- it ( "handles conversion in keywords specified in additionalKeywords" , function ( { expect } ) {
3+ describe ( "handles conversion in keywords specified in additionalKeywords" , function ( ) {
44 const schema = {
55 definitions : {
66 sharedDefinition : {
@@ -15,23 +15,83 @@ it("handles conversion in keywords specified in additionalKeywords", function ({
1515 } ,
1616 } ;
1717
18- const result = convert ( schema , {
19- definitionKeywords : [ "definitions" ] ,
18+ it ( "handles conversion in keywords specified in additionalKeywords" , function ( { expect } ) {
19+ const result = convert ( schema , {
20+ definitionKeywords : [ "definitions" ] ,
21+ } ) ;
22+
23+ const expected = {
24+ $schema : "http://json-schema.org/draft-04/schema#" ,
25+ definitions : {
26+ sharedDefinition : {
27+ type : "object" ,
28+ properties : {
29+ foo : {
30+ type : [ "string" , "null" ] ,
31+ } ,
32+ } ,
33+ } ,
34+ } ,
35+ } ;
36+
37+ expect ( result ) . toEqual ( expected ) ;
2038 } ) ;
2139
22- const expected = {
23- $schema : "http://json-schema.org/draft-04/schema#" ,
24- definitions : {
25- sharedDefinition : {
26- type : "object" ,
27- properties : {
28- foo : {
29- type : [ "string" , "null" ] ,
40+ it ( "does not convert when no definition keywords are included" , function ( { expect } ) {
41+ const result = convert ( schema ) ;
42+
43+ const expected = {
44+ $schema : "http://json-schema.org/draft-04/schema#" ,
45+ definitions : {
46+ sharedDefinition : {
47+ properties : {
48+ foo : {
49+ nullable : true ,
50+ type : "string" ,
51+ } ,
3052 } ,
53+ type : "object" ,
3154 } ,
3255 } ,
33- } ,
34- } ;
56+ } ;
57+
58+ expect ( result ) . toEqual ( expected ) ;
59+ } ) ;
60+
61+ it ( "handles nested definition keywords" , function ( { expect } ) {
62+ const nestedSchema = {
63+ schema : {
64+ definitions : {
65+ sharedDefinition : {
66+ type : "object" ,
67+ properties : {
68+ foo : {
69+ type : "string" ,
70+ nullable : true ,
71+ } ,
72+ } ,
73+ } ,
74+ } ,
75+ } ,
76+ } ;
77+ const result = convert ( nestedSchema , { definitionKeywords : [ "schema.definitions" ] } ) ;
78+
79+ const expected = {
80+ $schema : "http://json-schema.org/draft-04/schema#" ,
81+ schema : {
82+ definitions : {
83+ sharedDefinition : {
84+ type : "object" ,
85+ properties : {
86+ foo : {
87+ type : [ "string" , "null" ] ,
88+ } ,
89+ } ,
90+ } ,
91+ } ,
92+ } ,
93+ } ;
3594
36- expect ( result ) . toEqual ( expected ) ;
95+ expect ( result ) . toEqual ( expected ) ;
96+ } ) ;
3797} ) ;
0 commit comments