@@ -24,28 +24,28 @@ use(sinonChai);
24
24
describe . only ( 'Schema builder' , ( ) => {
25
25
it ( 'builds integer schema' , ( ) => {
26
26
const schema = Schema . integer ( ) ;
27
- expect ( schema . toJSON ( ) ) . to . eql ( {
27
+ expect ( schema . toRequest ( ) ) . to . eql ( {
28
28
type : 'integer' ,
29
29
nullable : false
30
30
} ) ;
31
31
} ) ;
32
32
it ( 'builds number schema' , ( ) => {
33
33
const schema = Schema . number ( ) ;
34
- expect ( schema . toJSON ( ) ) . to . eql ( {
34
+ expect ( schema . toRequest ( ) ) . to . eql ( {
35
35
type : 'number' ,
36
36
nullable : false
37
37
} ) ;
38
38
} ) ;
39
39
it ( 'builds boolean schema' , ( ) => {
40
40
const schema = Schema . boolean ( ) ;
41
- expect ( schema . toJSON ( ) ) . to . eql ( {
41
+ expect ( schema . toRequest ( ) ) . to . eql ( {
42
42
type : 'boolean' ,
43
43
nullable : false
44
44
} ) ;
45
45
} ) ;
46
46
it ( 'builds string schema' , ( ) => {
47
47
const schema = Schema . string ( { description : 'hey' } ) ;
48
- expect ( schema . toJSON ( ) ) . to . eql ( {
48
+ expect ( schema . toRequest ( ) ) . to . eql ( {
49
49
type : 'string' ,
50
50
description : 'hey' ,
51
51
nullable : false
@@ -56,7 +56,7 @@ describe.only('Schema builder', () => {
56
56
example : 'east' ,
57
57
enum : [ 'east' , 'west' ]
58
58
} ) ;
59
- expect ( schema . toJSON ( ) ) . to . eql ( {
59
+ expect ( schema . toRequest ( ) ) . to . eql ( {
60
60
type : 'string' ,
61
61
example : 'east' ,
62
62
enum : [ 'east' , 'west' ] ,
@@ -69,7 +69,7 @@ describe.only('Schema builder', () => {
69
69
'someInput' : Schema . string ( )
70
70
}
71
71
} ) ;
72
- expect ( schema . toJSON ( ) ) . to . eql ( {
72
+ expect ( schema . toRequest ( ) ) . to . eql ( {
73
73
type : 'object' ,
74
74
nullable : false ,
75
75
properties : {
@@ -81,13 +81,12 @@ describe.only('Schema builder', () => {
81
81
required : [ 'someInput' ]
82
82
} ) ;
83
83
} ) ;
84
- it ( 'builds layered schema' , ( ) => {
84
+ it ( 'builds layered schema - partially filled out ' , ( ) => {
85
85
const schema = Schema . array ( {
86
86
items : Schema . object ( {
87
87
properties : {
88
88
country : Schema . string ( {
89
- description : 'some country' ,
90
- required : true
89
+ description : 'A country name'
91
90
} ) ,
92
91
population : Schema . integer ( ) ,
93
92
coordinates : Schema . object ( {
@@ -106,18 +105,74 @@ describe.only('Schema builder', () => {
106
105
}
107
106
} )
108
107
} ) ;
108
+ expect ( schema . toRequest ( ) ) . to . eql ( layeredSchemaOutputPartial ) ;
109
+ } ) ;
110
+ it ( 'builds layered schema - fully filled out' , ( ) => {
111
+ const schema = Schema . array ( {
112
+ items : Schema . object ( {
113
+ description : 'A country profile' ,
114
+ nullable : false ,
115
+ properties : {
116
+ country : Schema . string ( {
117
+ nullable : false ,
118
+ description : 'Country name' ,
119
+ format : undefined
120
+ } ) ,
121
+ population : Schema . integer ( {
122
+ nullable : false ,
123
+ description : 'Number of people in country' ,
124
+ format : 'int64'
125
+ } ) ,
126
+ coordinates : Schema . object ( {
127
+ nullable : false ,
128
+ description : 'Latitude and longitude' ,
129
+ properties : {
130
+ latitude : Schema . number ( {
131
+ nullable : false ,
132
+ description : 'Latitude of capital' ,
133
+ format : 'float'
134
+ } ) ,
135
+ longitude : Schema . number ( {
136
+ nullable : false ,
137
+ description : 'Longitude of capital' ,
138
+ format : 'double'
139
+ } )
140
+ }
141
+ } ) ,
142
+ hemisphere : Schema . object ( {
143
+ nullable : false ,
144
+ description : 'Hemisphere(s) country is in' ,
145
+ properties : {
146
+ latitudinal : Schema . enumString ( { enum : [ 'N' , 'S' ] } ) ,
147
+ longitudinal : Schema . enumString ( { enum : [ 'E' , 'W' ] } )
148
+ }
149
+ } ) ,
150
+ isCapital : Schema . boolean ( {
151
+ nullable : false ,
152
+ description : "This doesn't make a lot of sense but it's a demo"
153
+ } ) ,
154
+ elevation : Schema . integer ( {
155
+ nullable : false ,
156
+ description : 'Average elevation' ,
157
+ format : 'float'
158
+ } )
159
+ } ,
160
+ optionalProperties : [ ]
161
+ } )
162
+ } ) ;
109
163
110
- expect ( schema . toJSON ( ) ) . to . eql ( layeredSchemaOutput ) ;
164
+ expect ( schema . toRequest ( ) ) . to . eql ( layeredSchemaOutput ) ;
111
165
} ) ;
112
- it ( 'can override the "required " and "nullable" properties' , ( ) => {
166
+ it ( 'can override "nullable " and set optional properties' , ( ) => {
113
167
const schema = Schema . object ( {
114
168
properties : {
115
169
country : Schema . string ( ) ,
116
- elevation : Schema . number ( { required : false } ) ,
170
+ elevation : Schema . number ( ) ,
117
171
population : Schema . integer ( { nullable : true } )
118
- }
172
+ } ,
173
+ optionalProperties : [ 'elevation' ]
119
174
} ) ;
120
- expect ( schema . toJSON ( ) ) . to . eql ( {
175
+ expect ( schema . toRequest ( ) ) . to . eql ( {
121
176
'type' : 'object' ,
122
177
'nullable' : false ,
123
178
'properties' : {
@@ -139,7 +194,7 @@ describe.only('Schema builder', () => {
139
194
} ) ;
140
195
} ) ;
141
196
142
- const layeredSchemaOutput = {
197
+ const layeredSchemaOutputPartial = {
143
198
'type' : 'array' ,
144
199
'nullable' : false ,
145
200
'items' : {
@@ -148,7 +203,7 @@ const layeredSchemaOutput = {
148
203
'properties' : {
149
204
'country' : {
150
205
'type' : 'string' ,
151
- 'description' : 'some country' ,
206
+ 'description' : 'A country name ' ,
152
207
'nullable' : false
153
208
} ,
154
209
'population' : {
@@ -203,3 +258,83 @@ const layeredSchemaOutput = {
203
258
]
204
259
}
205
260
} ;
261
+
262
+ const layeredSchemaOutput = {
263
+ 'type' : 'array' ,
264
+ 'nullable' : false ,
265
+ 'items' : {
266
+ 'type' : 'object' ,
267
+ 'description' : 'A country profile' ,
268
+ 'nullable' : false ,
269
+ 'required' : [
270
+ 'country' ,
271
+ 'population' ,
272
+ 'coordinates' ,
273
+ 'hemisphere' ,
274
+ 'isCapital' ,
275
+ 'elevation'
276
+ ] ,
277
+ 'properties' : {
278
+ 'country' : {
279
+ 'type' : 'string' ,
280
+ 'description' : 'Country name' ,
281
+ 'nullable' : false
282
+ } ,
283
+ 'population' : {
284
+ 'type' : 'integer' ,
285
+ 'format' : 'int64' ,
286
+ 'description' : 'Number of people in country' ,
287
+ 'nullable' : false
288
+ } ,
289
+ 'coordinates' : {
290
+ 'type' : 'object' ,
291
+ 'description' : 'Latitude and longitude' ,
292
+ 'nullable' : false ,
293
+ 'required' : [ 'latitude' , 'longitude' ] ,
294
+ 'properties' : {
295
+ 'latitude' : {
296
+ 'type' : 'number' ,
297
+ 'format' : 'float' ,
298
+ 'description' : 'Latitude of capital' ,
299
+ 'nullable' : false
300
+ } ,
301
+ 'longitude' : {
302
+ 'type' : 'number' ,
303
+ 'format' : 'double' ,
304
+ 'description' : 'Longitude of capital' ,
305
+ 'nullable' : false
306
+ }
307
+ }
308
+ } ,
309
+ 'hemisphere' : {
310
+ 'type' : 'object' ,
311
+ 'description' : 'Hemisphere(s) country is in' ,
312
+ 'nullable' : false ,
313
+ 'required' : [ 'latitudinal' , 'longitudinal' ] ,
314
+ 'properties' : {
315
+ 'latitudinal' : {
316
+ 'type' : 'string' ,
317
+ 'nullable' : false ,
318
+ 'enum' : [ 'N' , 'S' ]
319
+ } ,
320
+ 'longitudinal' : {
321
+ 'type' : 'string' ,
322
+ 'nullable' : false ,
323
+ 'enum' : [ 'E' , 'W' ]
324
+ }
325
+ }
326
+ } ,
327
+ 'isCapital' : {
328
+ 'type' : 'boolean' ,
329
+ 'description' : "This doesn't make a lot of sense but it's a demo" ,
330
+ 'nullable' : false
331
+ } ,
332
+ 'elevation' : {
333
+ 'type' : 'integer' ,
334
+ 'format' : 'float' ,
335
+ 'description' : 'Average elevation' ,
336
+ 'nullable' : false
337
+ }
338
+ }
339
+ }
340
+ } ;
0 commit comments