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