@@ -12,6 +12,76 @@ import (
12
12
"github.com/stretchr/testify/assert"
13
13
)
14
14
15
+ // studentSchema serves as a complex nested schema example.
16
+ var studentSchema = schema.Schema {
17
+ Description : "Object with array of students" ,
18
+ Fields : schema.Fields {
19
+ "students" : {
20
+ Description : "Array of students" ,
21
+ Validator : & schema.Array {
22
+ ValuesValidator : & schema.Object {
23
+ Schema : & schema.Schema {
24
+ Description : "Student and class" ,
25
+ Fields : schema.Fields {
26
+ "student" : {
27
+ Description : "The student name" ,
28
+ Required : true ,
29
+ Default : "Unknown" ,
30
+ Validator : & schema.String {
31
+ MinLen : 1 ,
32
+ MaxLen : 10 ,
33
+ },
34
+ },
35
+ "class" : {
36
+ Description : "The class name" ,
37
+ Default : "Unassigned" ,
38
+ Validator : & schema.String {
39
+ MinLen : 0 , // Default value.
40
+ MaxLen : 10 ,
41
+ },
42
+ },
43
+ },
44
+ },
45
+ },
46
+ },
47
+ },
48
+ },
49
+ }
50
+
51
+ // studentSchemaJSON contains the expected JSON serialization of studentSchema.
52
+ const studentSchemaJSON = `{
53
+ "type": "object",
54
+ "description": "Object with array of students",
55
+ "additionalProperties": false,
56
+ "properties": {
57
+ "students": {
58
+ "type": "array",
59
+ "description": "Array of students",
60
+ "items": {
61
+ "type": "object",
62
+ "description": "Student and class",
63
+ "additionalProperties": false,
64
+ "properties": {
65
+ "student": {
66
+ "type": "string",
67
+ "description": "The student name",
68
+ "default": "Unknown",
69
+ "minLength": 1,
70
+ "maxLength": 10
71
+ },
72
+ "class": {
73
+ "type": "string",
74
+ "description": "The class name",
75
+ "default": "Unassigned",
76
+ "maxLength": 10
77
+ }
78
+ },
79
+ "required": ["student"]
80
+ }
81
+ }
82
+ }
83
+ }`
84
+
15
85
type dummyValidator struct {}
16
86
17
87
func (v dummyValidator ) Validate (value interface {}) (interface {}, error ) {
@@ -340,73 +410,9 @@ func TestEncoder(t *testing.T) {
340
410
}` ,
341
411
},
342
412
{
343
- name : "Validator=Array,ValuesValidator=Object{Schema:Student}" ,
344
- schema : schema.Schema {
345
- Description : "Object with array of students" ,
346
- Fields : schema.Fields {
347
- "students" : {
348
- Description : "Array of students" ,
349
- Validator : & schema.Array {
350
- ValuesValidator : & schema.Object {
351
- Schema : & schema.Schema {
352
- Description : "Student and class" ,
353
- Fields : schema.Fields {
354
- "student" : {
355
- Description : "The student name" ,
356
- Required : true ,
357
- Default : "Unknown" ,
358
- Validator : & schema.String {
359
- MinLen : 1 ,
360
- MaxLen : 10 ,
361
- },
362
- },
363
- "class" : {
364
- Description : "The class name" ,
365
- Default : "Unassigned" ,
366
- Validator : & schema.String {
367
- MinLen : 0 , // Default value.
368
- MaxLen : 10 ,
369
- },
370
- },
371
- },
372
- },
373
- },
374
- },
375
- },
376
- },
377
- },
378
- expect : `{
379
- "type": "object",
380
- "description": "Object with array of students",
381
- "additionalProperties": false,
382
- "properties": {
383
- "students": {
384
- "type": "array",
385
- "description": "Array of students",
386
- "items": {
387
- "type": "object",
388
- "description": "Student and class",
389
- "additionalProperties": false,
390
- "properties": {
391
- "student": {
392
- "type": "string",
393
- "description": "The student name",
394
- "default": "Unknown",
395
- "minLength": 1,
396
- "maxLength": 10
397
- },
398
- "class": {
399
- "type": "string",
400
- "description": "The class name",
401
- "default": "Unassigned",
402
- "maxLength": 10
403
- }
404
- },
405
- "required": ["student"]
406
- }
407
- }
408
- }
409
- }` ,
413
+ name : "Validator=Array,ValuesValidator=Object{Schema:Student}" ,
414
+ schema : studentSchema ,
415
+ expect : studentSchemaJSON ,
410
416
},
411
417
{
412
418
name : `Validator=Object,Fields["location"].Validator=Object` ,
0 commit comments