@@ -16,77 +16,88 @@ object SwaggerValidator {
16
16
val errors = new ListBuffer [ValidationError ]
17
17
18
18
if (resource.apiVersion == " " )
19
- errors += ValidationError (" resourceListing" , " apiVersion" , ERROR )
19
+ errors += ValidationError (" resourceListing" , " apiVersion is required " , ERROR )
20
20
if (resource.swaggerVersion == " " )
21
- errors += ValidationError (" resourceListing" , " apiVersion" , ERROR )
21
+ errors += ValidationError (" resourceListing" , " apiVersion is required " , ERROR )
22
22
for (api <- resource.apis)
23
23
validate(api, errors, " resourceListing" )
24
24
errors.toList
25
25
}
26
26
27
27
def validate (ref : ApiListingReference , errors : ListBuffer [ValidationError ], parent : String ): Unit = {
28
28
if (ref.path == " " )
29
- errors += ValidationError (parent + " :api" , " path" , ERROR )
29
+ errors += ValidationError (parent + " :[ api] " , " path is required " , ERROR )
30
30
}
31
31
32
32
def validate (api : ApiListing , errors : ListBuffer [ValidationError ]): Unit = {
33
33
if (api.swaggerVersion == " " )
34
- errors += ValidationError (" apiDeclaration" , " swaggerVersion" , ERROR )
34
+ errors += ValidationError (" apiDeclaration" , " swaggerVersion is required " , ERROR )
35
35
if (api.apiVersion == " " )
36
- errors += ValidationError (" apiDeclaration" , " apiVersion" , ERROR )
36
+ errors += ValidationError (" apiDeclaration" , " apiVersion is required " , ERROR )
37
37
if (api.basePath == " " )
38
- errors += ValidationError (" apiDeclaration" , " basePath" , ERROR )
38
+ errors += ValidationError (" apiDeclaration" , " basePath is required " , ERROR )
39
39
if (api.resourcePath == " " )
40
- errors += ValidationError (" apiDeclaration" , " resourcePath" , ERROR )
40
+ errors += ValidationError (" apiDeclaration" , " resourcePath is required " , ERROR )
41
41
42
+ val name = {
43
+ if (api.resourcePath == " " ) " [unknown]"
44
+ else api.resourcePath
45
+ }
42
46
for (a <- api.apis) {
43
- validate(a, errors, api.resourcePath )
47
+ validate(a, errors, name )
44
48
}
45
49
46
50
api.models match {
47
51
case Some (m) => for ((name, model) <- m) {
48
- validate(model, errors, api.resourcePath )
52
+ validate(model, errors, name )
49
53
}
50
54
case None =>
51
55
}
52
56
}
53
57
54
58
def validate (model : Model , errors : ListBuffer [ValidationError ], parent : String ): Unit = {
55
59
if (model.id == " " )
56
- errors += ValidationError (parent + " :model" , " id" , ERROR )
60
+ errors += ValidationError (parent + " :[ model] " , " id is required " , ERROR )
57
61
}
58
62
59
63
def validate (desc : ApiDescription , errors : ListBuffer [ValidationError ], parent : String ): Unit = {
60
64
if (desc.path == " " )
61
- errors += ValidationError (parent + " :api" , " path" , ERROR )
65
+ errors += ValidationError (parent + " :[ api] " , " path is required " , ERROR )
62
66
for (op <- desc.operations)
63
67
validate(op, errors, parent + " :" + desc.path)
64
68
}
65
69
66
70
def validate (op : Operation , errors : ListBuffer [ValidationError ], parent : String ): Unit = {
67
71
if (op.method == " " )
68
- errors += ValidationError (parent + " :operation" , " method" , ERROR )
72
+ errors += ValidationError (parent + " :[ operation] " , " method is required " , ERROR )
69
73
if (op.nickname == " " )
70
- errors += ValidationError (parent + " :" + op.method, " nickname" , WARNING )
74
+ errors += ValidationError (parent + " :" + op.method, " nickname is recommended " , WARNING )
71
75
if (op.responseClass == " " )
72
- errors += ValidationError (parent + " :" + op.method, " responseClass" , ERROR )
76
+ errors += ValidationError (parent + " :" + op.method, " responseClass is required " , ERROR )
73
77
for (resp <- op.responseMessages)
74
78
validate(resp, errors, parent)
75
79
for (param <- op.parameters)
76
80
validate(param, errors, parent)
77
81
}
78
82
79
83
def validate (param : Parameter , errors : ListBuffer [ValidationError ], parent : String ): Unit = {
84
+ val name = if (param.name == " " )
85
+ " [unknown]"
86
+ else
87
+ param.name
88
+
80
89
if (param.name == " " )
81
- errors += ValidationError (" Parameter " , " name" , ERROR )
90
+ errors += ValidationError (parent + " :[parameter] " , " name is required " , ERROR )
82
91
if (param.paramType == " " )
83
- errors += ValidationError (" Parameter" , " paramType" , ERROR )
92
+ errors += ValidationError (parent + name, " paramType is required" , ERROR )
93
+ if (param.dataType == " " )
94
+ errors += ValidationError (parent + name, " type is required" , ERROR )
84
95
}
85
96
86
97
def validate (resp : ResponseMessage , errors : ListBuffer [ValidationError ], parent : String ): Unit = {
87
98
if (resp.code == 0 )
88
- errors += ValidationError (" ResponseMessage " , " code" , ERROR )
99
+ errors += ValidationError (parent + " :[responseMessage] " , " code is required " , ERROR )
89
100
if (resp.message == 0 )
90
- errors += ValidationError (" ResponseMessage " , " message" , ERROR )
101
+ errors += ValidationError (parent + " :[responseMessage] " , " message is required " , ERROR )
91
102
}
92
103
}
0 commit comments