1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package validate
16
17 import (
18 "net/http"
19
20 "github.com/go-openapi/errors"
21 )
22
23
24 const (
25
26 ArrayRequiresItemsError = "%s for %q is a collection without an element type (array requires items definition)"
27
28
29 ArrayInParamRequiresItemsError = "param %q for %q is a collection without an element type (array requires item definition)"
30
31
32 ArrayInHeaderRequiresItemsError = "header %q for %q is a collection without an element type (array requires items definition)"
33
34
35 BothFormDataAndBodyError = "operation %q has both formData and body parameters. Only one such In: type may be used for a given operation"
36
37
38 CannotResolveReferenceError = "could not resolve reference in %s to $ref %s: %v"
39
40
41 CircularAncestryDefinitionError = "definition %q has circular ancestry: %v"
42
43
44 DefaultValueDoesNotValidateError = "default value for %s in %s does not validate its schema"
45
46
47 DefaultValueItemsDoesNotValidateError = "default value for %s.items in %s does not validate its schema"
48
49
50 DefaultValueHeaderDoesNotValidateError = "in operation %q, default value in header %s for %s does not validate its schema"
51
52
53 DefaultValueHeaderItemsDoesNotValidateError = "in operation %q, default value in header.items %s for %s does not validate its schema"
54
55
56 DefaultValueInDoesNotValidateError = "in operation %q, default value in %s does not validate its schema"
57
58
59 DuplicateParamNameError = "duplicate parameter name %q for %q in operation %q"
60
61
62 DuplicatePropertiesError = "definition %q contains duplicate properties: %v"
63
64
65 ExampleValueDoesNotValidateError = "example value for %s in %s does not validate its schema"
66
67
68 ExampleValueItemsDoesNotValidateError = "example value for %s.items in %s does not validate its schema"
69
70
71 ExampleValueHeaderDoesNotValidateError = "in operation %q, example value in header %s for %s does not validate its schema"
72
73
74 ExampleValueHeaderItemsDoesNotValidateError = "in operation %q, example value in header.items %s for %s does not validate its schema"
75
76
77 ExampleValueInDoesNotValidateError = "in operation %q, example value in %s does not validate its schema"
78
79
80 EmptyPathParameterError = "%q contains an empty path parameter"
81
82
83 InvalidDocumentError = "spec validator can only validate spec.Document objects"
84
85
86 InvalidItemsPatternError = "%s for %q has invalid items pattern: %q"
87
88
89 InvalidParameterDefinitionError = "invalid definition for parameter %s in %s in operation %q"
90
91
92
93 InvalidParameterDefinitionAsSchemaError = "invalid definition as Schema for parameter %s in %s in operation %q"
94
95
96 InvalidPatternError = "pattern %q is invalid in %s"
97
98
99 InvalidPatternInError = "%s in %s has invalid pattern: %q"
100
101
102 InvalidPatternInHeaderError = "in operation %q, header %s for %s has invalid pattern %q: %v"
103
104
105 InvalidPatternInParamError = "operation %q has invalid pattern in param %q: %q"
106
107
108 InvalidReferenceError = "invalid ref %q"
109
110
111
112 InvalidResponseDefinitionAsSchemaError = "invalid definition as Schema for response %s in %s"
113
114
115 MultipleBodyParamError = "operation %q has more than 1 body param: %v"
116
117
118 NonUniqueOperationIDError = "%q is defined %d times"
119
120
121 NoParameterInPathError = "path param %q has no parameter definition"
122
123
124 NoValidPathErrorOrWarning = "spec has no valid path defined"
125
126
127 NoValidResponseError = "operation %q has no valid response"
128
129
130 PathOverlapError = "path %s overlaps with %s"
131
132
133 PathParamNotInPathError = "path param %q is not present in path %q"
134
135
136 PathParamNotUniqueError = "params in path %q must be unique: %q conflicts with %q"
137
138
139 PathParamRequiredError = "in operation %q,path param %q must be declared as required"
140
141
142 RefNotAllowedInHeaderError = "IMPORTANT!in %q: $ref are not allowed in headers. In context for header %q%s"
143
144
145 RequiredButNotDefinedError = "%q is present in required but not defined as property in definition %q"
146
147
148 SomeParametersBrokenError = "some parameters definitions are broken in %q.%s. Cannot carry on full checks on parameters for operation %s"
149
150
151 UnresolvedReferencesError = "some references could not be resolved in spec. First found: %v"
152 )
153
154
155 const (
156
157 ExamplesWithoutSchemaWarning = "Examples provided without schema in operation %q, %s"
158
159
160
161 ExamplesMimeNotSupportedWarning = "No validation attempt for examples for media types other than application/json, in operation %q, %s"
162
163
164 PathParamGarbledWarning = "in path %q, param %q contains {,} or white space. Albeit not stricly illegal, this is probably no what you want"
165
166
167 ParamValidationTypeMismatch = "validation keywords of parameter %q in path %q don't match its type %s"
168
169
170 PathStrippedParamGarbledWarning = "path stripped from path parameters %s contains {,} or white space. This is probably no what you want."
171
172
173 ReadOnlyAndRequiredWarning = "Required property %s in %q should not be marked as both required and readOnly"
174
175
176
177 RefShouldNotHaveSiblingsWarning = "$ref property should have no sibling in %q.%s"
178
179
180 RequiredHasDefaultWarning = "%s in %s has a default value and is required as parameter"
181
182
183 UnusedDefinitionWarning = "definition %q is not used anywhere"
184
185
186 UnusedParamWarning = "parameter %q is not used anywhere"
187
188
189 UnusedResponseWarning = "response %q is not used anywhere"
190
191 InvalidObject = "expected an object in %q.%s"
192 )
193
194
195 const (
196
197 InternalErrorCode = http.StatusInternalServerError
198
199 NotFoundErrorCode = http.StatusNotFound
200 )
201
202 func invalidDocumentMsg() errors.Error {
203 return errors.New(InternalErrorCode, InvalidDocumentError)
204 }
205 func invalidRefMsg(path string) errors.Error {
206 return errors.New(NotFoundErrorCode, InvalidReferenceError, path)
207 }
208 func unresolvedReferencesMsg(err error) errors.Error {
209 return errors.New(errors.CompositeErrorCode, UnresolvedReferencesError, err)
210 }
211 func noValidPathMsg() errors.Error {
212 return errors.New(errors.CompositeErrorCode, NoValidPathErrorOrWarning)
213 }
214 func emptyPathParameterMsg(path string) errors.Error {
215 return errors.New(errors.CompositeErrorCode, EmptyPathParameterError, path)
216 }
217 func nonUniqueOperationIDMsg(path string, i int) errors.Error {
218 return errors.New(errors.CompositeErrorCode, NonUniqueOperationIDError, path, i)
219 }
220 func circularAncestryDefinitionMsg(path string, args interface{}) errors.Error {
221 return errors.New(errors.CompositeErrorCode, CircularAncestryDefinitionError, path, args)
222 }
223 func duplicatePropertiesMsg(path string, args interface{}) errors.Error {
224 return errors.New(errors.CompositeErrorCode, DuplicatePropertiesError, path, args)
225 }
226 func pathParamNotInPathMsg(path, param string) errors.Error {
227 return errors.New(errors.CompositeErrorCode, PathParamNotInPathError, param, path)
228 }
229 func arrayRequiresItemsMsg(path, operation string) errors.Error {
230 return errors.New(errors.CompositeErrorCode, ArrayRequiresItemsError, path, operation)
231 }
232 func arrayInParamRequiresItemsMsg(path, operation string) errors.Error {
233 return errors.New(errors.CompositeErrorCode, ArrayInParamRequiresItemsError, path, operation)
234 }
235 func arrayInHeaderRequiresItemsMsg(path, operation string) errors.Error {
236 return errors.New(errors.CompositeErrorCode, ArrayInHeaderRequiresItemsError, path, operation)
237 }
238 func invalidItemsPatternMsg(path, operation, pattern string) errors.Error {
239 return errors.New(errors.CompositeErrorCode, InvalidItemsPatternError, path, operation, pattern)
240 }
241 func invalidPatternMsg(pattern, path string) errors.Error {
242 return errors.New(errors.CompositeErrorCode, InvalidPatternError, pattern, path)
243 }
244 func requiredButNotDefinedMsg(path, definition string) errors.Error {
245 return errors.New(errors.CompositeErrorCode, RequiredButNotDefinedError, path, definition)
246 }
247 func pathParamGarbledMsg(path, param string) errors.Error {
248 return errors.New(errors.CompositeErrorCode, PathParamGarbledWarning, path, param)
249 }
250 func pathStrippedParamGarbledMsg(path string) errors.Error {
251 return errors.New(errors.CompositeErrorCode, PathStrippedParamGarbledWarning, path)
252 }
253 func pathOverlapMsg(path, arg string) errors.Error {
254 return errors.New(errors.CompositeErrorCode, PathOverlapError, path, arg)
255 }
256 func invalidPatternInParamMsg(operation, param, pattern string) errors.Error {
257 return errors.New(errors.CompositeErrorCode, InvalidPatternInParamError, operation, param, pattern)
258 }
259 func pathParamRequiredMsg(operation, param string) errors.Error {
260 return errors.New(errors.CompositeErrorCode, PathParamRequiredError, operation, param)
261 }
262 func bothFormDataAndBodyMsg(operation string) errors.Error {
263 return errors.New(errors.CompositeErrorCode, BothFormDataAndBodyError, operation)
264 }
265 func multipleBodyParamMsg(operation string, args interface{}) errors.Error {
266 return errors.New(errors.CompositeErrorCode, MultipleBodyParamError, operation, args)
267 }
268 func pathParamNotUniqueMsg(path, param, arg string) errors.Error {
269 return errors.New(errors.CompositeErrorCode, PathParamNotUniqueError, path, param, arg)
270 }
271 func duplicateParamNameMsg(path, param, operation string) errors.Error {
272 return errors.New(errors.CompositeErrorCode, DuplicateParamNameError, param, path, operation)
273 }
274 func unusedParamMsg(arg string) errors.Error {
275 return errors.New(errors.CompositeErrorCode, UnusedParamWarning, arg)
276 }
277 func unusedDefinitionMsg(arg string) errors.Error {
278 return errors.New(errors.CompositeErrorCode, UnusedDefinitionWarning, arg)
279 }
280 func unusedResponseMsg(arg string) errors.Error {
281 return errors.New(errors.CompositeErrorCode, UnusedResponseWarning, arg)
282 }
283 func readOnlyAndRequiredMsg(path, param string) errors.Error {
284 return errors.New(errors.CompositeErrorCode, ReadOnlyAndRequiredWarning, param, path)
285 }
286 func noParameterInPathMsg(param string) errors.Error {
287 return errors.New(errors.CompositeErrorCode, NoParameterInPathError, param)
288 }
289 func requiredHasDefaultMsg(param, path string) errors.Error {
290 return errors.New(errors.CompositeErrorCode, RequiredHasDefaultWarning, param, path)
291 }
292 func defaultValueDoesNotValidateMsg(param, path string) errors.Error {
293 return errors.New(errors.CompositeErrorCode, DefaultValueDoesNotValidateError, param, path)
294 }
295 func defaultValueItemsDoesNotValidateMsg(param, path string) errors.Error {
296 return errors.New(errors.CompositeErrorCode, DefaultValueItemsDoesNotValidateError, param, path)
297 }
298 func noValidResponseMsg(operation string) errors.Error {
299 return errors.New(errors.CompositeErrorCode, NoValidResponseError, operation)
300 }
301 func defaultValueHeaderDoesNotValidateMsg(operation, header, path string) errors.Error {
302 return errors.New(errors.CompositeErrorCode, DefaultValueHeaderDoesNotValidateError, operation, header, path)
303 }
304 func defaultValueHeaderItemsDoesNotValidateMsg(operation, header, path string) errors.Error {
305 return errors.New(errors.CompositeErrorCode, DefaultValueHeaderItemsDoesNotValidateError, operation, header, path)
306 }
307 func invalidPatternInHeaderMsg(operation, header, path, pattern string, args interface{}) errors.Error {
308 return errors.New(errors.CompositeErrorCode, InvalidPatternInHeaderError, operation, header, path, pattern, args)
309 }
310 func invalidPatternInMsg(path, in, pattern string) errors.Error {
311 return errors.New(errors.CompositeErrorCode, InvalidPatternInError, path, in, pattern)
312 }
313 func defaultValueInDoesNotValidateMsg(operation, path string) errors.Error {
314 return errors.New(errors.CompositeErrorCode, DefaultValueInDoesNotValidateError, operation, path)
315 }
316 func exampleValueDoesNotValidateMsg(param, path string) errors.Error {
317 return errors.New(errors.CompositeErrorCode, ExampleValueDoesNotValidateError, param, path)
318 }
319 func exampleValueItemsDoesNotValidateMsg(param, path string) errors.Error {
320 return errors.New(errors.CompositeErrorCode, ExampleValueItemsDoesNotValidateError, param, path)
321 }
322 func exampleValueHeaderDoesNotValidateMsg(operation, header, path string) errors.Error {
323 return errors.New(errors.CompositeErrorCode, ExampleValueHeaderDoesNotValidateError, operation, header, path)
324 }
325 func exampleValueHeaderItemsDoesNotValidateMsg(operation, header, path string) errors.Error {
326 return errors.New(errors.CompositeErrorCode, ExampleValueHeaderItemsDoesNotValidateError, operation, header, path)
327 }
328 func exampleValueInDoesNotValidateMsg(operation, path string) errors.Error {
329 return errors.New(errors.CompositeErrorCode, ExampleValueInDoesNotValidateError, operation, path)
330 }
331 func examplesWithoutSchemaMsg(operation, response string) errors.Error {
332 return errors.New(errors.CompositeErrorCode, ExamplesWithoutSchemaWarning, operation, response)
333 }
334 func examplesMimeNotSupportedMsg(operation, response string) errors.Error {
335 return errors.New(errors.CompositeErrorCode, ExamplesMimeNotSupportedWarning, operation, response)
336 }
337 func refNotAllowedInHeaderMsg(path, header, ref string) errors.Error {
338 return errors.New(errors.CompositeErrorCode, RefNotAllowedInHeaderError, path, header, ref)
339 }
340 func cannotResolveRefMsg(path, ref string, err error) errors.Error {
341 return errors.New(errors.CompositeErrorCode, CannotResolveReferenceError, path, ref, err)
342 }
343 func invalidParameterDefinitionMsg(path, method, operationID string) errors.Error {
344 return errors.New(errors.CompositeErrorCode, InvalidParameterDefinitionError, path, method, operationID)
345 }
346 func invalidParameterDefinitionAsSchemaMsg(path, method, operationID string) errors.Error {
347 return errors.New(errors.CompositeErrorCode, InvalidParameterDefinitionAsSchemaError, path, method, operationID)
348 }
349 func parameterValidationTypeMismatchMsg(param, path, typ string) errors.Error {
350 return errors.New(errors.CompositeErrorCode, ParamValidationTypeMismatch, param, path, typ)
351 }
352 func invalidObjectMsg(path, in string) errors.Error {
353 return errors.New(errors.CompositeErrorCode, InvalidObject, path, in)
354 }
355
356
357
358
359
360
361 func someParametersBrokenMsg(path, method, operationID string) errors.Error {
362 return errors.New(errors.CompositeErrorCode, SomeParametersBrokenError, path, method, operationID)
363 }
364 func refShouldNotHaveSiblingsMsg(path, operationID string) errors.Error {
365 return errors.New(errors.CompositeErrorCode, RefShouldNotHaveSiblingsWarning, operationID, path)
366 }
367
View as plain text