summaryrefslogtreecommitdiff
path: root/vendor/github.com/go-openapi/errors/schema.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/go-openapi/errors/schema.go')
-rw-r--r--vendor/github.com/go-openapi/errors/schema.go110
1 files changed, 57 insertions, 53 deletions
diff --git a/vendor/github.com/go-openapi/errors/schema.go b/vendor/github.com/go-openapi/errors/schema.go
index cf7ac2ed4..8f3239dfd 100644
--- a/vendor/github.com/go-openapi/errors/schema.go
+++ b/vendor/github.com/go-openapi/errors/schema.go
@@ -17,6 +17,7 @@ package errors
import (
"encoding/json"
"fmt"
+ "net/http"
"strings"
)
@@ -32,12 +33,12 @@ const (
patternFail = "%s in %s should match '%s'"
enumFail = "%s in %s should be one of %v"
multipleOfFail = "%s in %s should be a multiple of %v"
- maxIncFail = "%s in %s should be less than or equal to %v"
- maxExcFail = "%s in %s should be less than %v"
+ maximumIncFail = "%s in %s should be less than or equal to %v"
+ maximumExcFail = "%s in %s should be less than %v"
minIncFail = "%s in %s should be greater than or equal to %v"
minExcFail = "%s in %s should be greater than %v"
uniqueFail = "%s in %s shouldn't contain duplicates"
- maxItemsFail = "%s in %s should have at most %d items"
+ maximumItemsFail = "%s in %s should have at most %d items"
minItemsFail = "%s in %s should have at least %d items"
typeFailNoIn = "%s must be of type %s"
typeFailWithDataNoIn = "%s must be of type %s: %q"
@@ -49,12 +50,12 @@ const (
patternFailNoIn = "%s should match '%s'"
enumFailNoIn = "%s should be one of %v"
multipleOfFailNoIn = "%s should be a multiple of %v"
- maxIncFailNoIn = "%s should be less than or equal to %v"
- maxExcFailNoIn = "%s should be less than %v"
+ maximumIncFailNoIn = "%s should be less than or equal to %v"
+ maximumExcFailNoIn = "%s should be less than %v"
minIncFailNoIn = "%s should be greater than or equal to %v"
minExcFailNoIn = "%s should be greater than %v"
uniqueFailNoIn = "%s shouldn't contain duplicates"
- maxItemsFailNoIn = "%s should have at most %d items"
+ maximumItemsFailNoIn = "%s should have at most %d items"
minItemsFailNoIn = "%s should have at least %d items"
noAdditionalItems = "%s in %s can't have additional items"
noAdditionalItemsNoIn = "%s can't have additional items"
@@ -69,14 +70,17 @@ const (
multipleOfMustBePositive = "factor MultipleOf declared for %s must be positive: %v"
)
+const maximumValidHTTPCode = 600
+
// All code responses can be used to differentiate errors for different handling
// by the consuming program
const (
// CompositeErrorCode remains 422 for backwards-compatibility
// and to separate it from validation errors with cause
- CompositeErrorCode = 422
+ CompositeErrorCode = http.StatusUnprocessableEntity
+
// InvalidTypeCode is used for any subclass of invalid types
- InvalidTypeCode = 600 + iota
+ InvalidTypeCode = maximumValidHTTPCode + iota
RequiredFailCode
TooLongFailCode
TooShortFailCode
@@ -298,10 +302,10 @@ func DuplicateItems(name, in string) *Validation {
}
// TooManyItems error for when an array contains too many items
-func TooManyItems(name, in string, max int64, value interface{}) *Validation {
- msg := fmt.Sprintf(maxItemsFail, name, in, max)
+func TooManyItems(name, in string, maximum int64, value interface{}) *Validation {
+ msg := fmt.Sprintf(maximumItemsFail, name, in, maximum)
if in == "" {
- msg = fmt.Sprintf(maxItemsFailNoIn, name, max)
+ msg = fmt.Sprintf(maximumItemsFailNoIn, name, maximum)
}
return &Validation{
@@ -314,10 +318,10 @@ func TooManyItems(name, in string, max int64, value interface{}) *Validation {
}
// TooFewItems error for when an array contains too few items
-func TooFewItems(name, in string, min int64, value interface{}) *Validation {
- msg := fmt.Sprintf(minItemsFail, name, in, min)
+func TooFewItems(name, in string, minimum int64, value interface{}) *Validation {
+ msg := fmt.Sprintf(minItemsFail, name, in, minimum)
if in == "" {
- msg = fmt.Sprintf(minItemsFailNoIn, name, min)
+ msg = fmt.Sprintf(minItemsFailNoIn, name, minimum)
}
return &Validation{
code: MinItemsFailCode,
@@ -328,21 +332,21 @@ func TooFewItems(name, in string, min int64, value interface{}) *Validation {
}
}
-// ExceedsMaximumInt error for when maximum validation fails
-func ExceedsMaximumInt(name, in string, max int64, exclusive bool, value interface{}) *Validation {
+// ExceedsMaximumInt error for when maximumimum validation fails
+func ExceedsMaximumInt(name, in string, maximum int64, exclusive bool, value interface{}) *Validation {
var message string
if in == "" {
- m := maxIncFailNoIn
+ m := maximumIncFailNoIn
if exclusive {
- m = maxExcFailNoIn
+ m = maximumExcFailNoIn
}
- message = fmt.Sprintf(m, name, max)
+ message = fmt.Sprintf(m, name, maximum)
} else {
- m := maxIncFail
+ m := maximumIncFail
if exclusive {
- m = maxExcFail
+ m = maximumExcFail
}
- message = fmt.Sprintf(m, name, in, max)
+ message = fmt.Sprintf(m, name, in, maximum)
}
return &Validation{
code: MaxFailCode,
@@ -353,21 +357,21 @@ func ExceedsMaximumInt(name, in string, max int64, exclusive bool, value interfa
}
}
-// ExceedsMaximumUint error for when maximum validation fails
-func ExceedsMaximumUint(name, in string, max uint64, exclusive bool, value interface{}) *Validation {
+// ExceedsMaximumUint error for when maximumimum validation fails
+func ExceedsMaximumUint(name, in string, maximum uint64, exclusive bool, value interface{}) *Validation {
var message string
if in == "" {
- m := maxIncFailNoIn
+ m := maximumIncFailNoIn
if exclusive {
- m = maxExcFailNoIn
+ m = maximumExcFailNoIn
}
- message = fmt.Sprintf(m, name, max)
+ message = fmt.Sprintf(m, name, maximum)
} else {
- m := maxIncFail
+ m := maximumIncFail
if exclusive {
- m = maxExcFail
+ m = maximumExcFail
}
- message = fmt.Sprintf(m, name, in, max)
+ message = fmt.Sprintf(m, name, in, maximum)
}
return &Validation{
code: MaxFailCode,
@@ -378,21 +382,21 @@ func ExceedsMaximumUint(name, in string, max uint64, exclusive bool, value inter
}
}
-// ExceedsMaximum error for when maximum validation fails
-func ExceedsMaximum(name, in string, max float64, exclusive bool, value interface{}) *Validation {
+// ExceedsMaximum error for when maximumimum validation fails
+func ExceedsMaximum(name, in string, maximum float64, exclusive bool, value interface{}) *Validation {
var message string
if in == "" {
- m := maxIncFailNoIn
+ m := maximumIncFailNoIn
if exclusive {
- m = maxExcFailNoIn
+ m = maximumExcFailNoIn
}
- message = fmt.Sprintf(m, name, max)
+ message = fmt.Sprintf(m, name, maximum)
} else {
- m := maxIncFail
+ m := maximumIncFail
if exclusive {
- m = maxExcFail
+ m = maximumExcFail
}
- message = fmt.Sprintf(m, name, in, max)
+ message = fmt.Sprintf(m, name, in, maximum)
}
return &Validation{
code: MaxFailCode,
@@ -404,20 +408,20 @@ func ExceedsMaximum(name, in string, max float64, exclusive bool, value interfac
}
// ExceedsMinimumInt error for when minimum validation fails
-func ExceedsMinimumInt(name, in string, min int64, exclusive bool, value interface{}) *Validation {
+func ExceedsMinimumInt(name, in string, minimum int64, exclusive bool, value interface{}) *Validation {
var message string
if in == "" {
m := minIncFailNoIn
if exclusive {
m = minExcFailNoIn
}
- message = fmt.Sprintf(m, name, min)
+ message = fmt.Sprintf(m, name, minimum)
} else {
m := minIncFail
if exclusive {
m = minExcFail
}
- message = fmt.Sprintf(m, name, in, min)
+ message = fmt.Sprintf(m, name, in, minimum)
}
return &Validation{
code: MinFailCode,
@@ -429,20 +433,20 @@ func ExceedsMinimumInt(name, in string, min int64, exclusive bool, value interfa
}
// ExceedsMinimumUint error for when minimum validation fails
-func ExceedsMinimumUint(name, in string, min uint64, exclusive bool, value interface{}) *Validation {
+func ExceedsMinimumUint(name, in string, minimum uint64, exclusive bool, value interface{}) *Validation {
var message string
if in == "" {
m := minIncFailNoIn
if exclusive {
m = minExcFailNoIn
}
- message = fmt.Sprintf(m, name, min)
+ message = fmt.Sprintf(m, name, minimum)
} else {
m := minIncFail
if exclusive {
m = minExcFail
}
- message = fmt.Sprintf(m, name, in, min)
+ message = fmt.Sprintf(m, name, in, minimum)
}
return &Validation{
code: MinFailCode,
@@ -454,20 +458,20 @@ func ExceedsMinimumUint(name, in string, min uint64, exclusive bool, value inter
}
// ExceedsMinimum error for when minimum validation fails
-func ExceedsMinimum(name, in string, min float64, exclusive bool, value interface{}) *Validation {
+func ExceedsMinimum(name, in string, minimum float64, exclusive bool, value interface{}) *Validation {
var message string
if in == "" {
m := minIncFailNoIn
if exclusive {
m = minExcFailNoIn
}
- message = fmt.Sprintf(m, name, min)
+ message = fmt.Sprintf(m, name, minimum)
} else {
m := minIncFail
if exclusive {
m = minExcFail
}
- message = fmt.Sprintf(m, name, in, min)
+ message = fmt.Sprintf(m, name, in, minimum)
}
return &Validation{
code: MinFailCode,
@@ -549,12 +553,12 @@ func ReadOnly(name, in string, value interface{}) *Validation {
}
// TooLong error for when a string is too long
-func TooLong(name, in string, max int64, value interface{}) *Validation {
+func TooLong(name, in string, maximum int64, value interface{}) *Validation {
var msg string
if in == "" {
- msg = fmt.Sprintf(tooLongMessageNoIn, name, max)
+ msg = fmt.Sprintf(tooLongMessageNoIn, name, maximum)
} else {
- msg = fmt.Sprintf(tooLongMessage, name, in, max)
+ msg = fmt.Sprintf(tooLongMessage, name, in, maximum)
}
return &Validation{
code: TooLongFailCode,
@@ -566,12 +570,12 @@ func TooLong(name, in string, max int64, value interface{}) *Validation {
}
// TooShort error for when a string is too short
-func TooShort(name, in string, min int64, value interface{}) *Validation {
+func TooShort(name, in string, minimum int64, value interface{}) *Validation {
var msg string
if in == "" {
- msg = fmt.Sprintf(tooShortMessageNoIn, name, min)
+ msg = fmt.Sprintf(tooShortMessageNoIn, name, minimum)
} else {
- msg = fmt.Sprintf(tooShortMessage, name, in, min)
+ msg = fmt.Sprintf(tooShortMessage, name, in, minimum)
}
return &Validation{