2017-04-17 18:08:24 -04:00
|
|
|
// Copyright 2015 xeipuuv ( https://github.com/xeipuuv )
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
// author xeipuuv
|
|
|
|
// author-github https://github.com/xeipuuv
|
|
|
|
// author-mail xeipuuv@gmail.com
|
|
|
|
//
|
|
|
|
// repository-name gojsonschema
|
|
|
|
// repository-desc An implementation of JSON Schema, based on IETF's draft v4 - Go language.
|
|
|
|
//
|
|
|
|
// description Contains const string and messages.
|
|
|
|
//
|
|
|
|
// created 01-01-2015
|
|
|
|
|
|
|
|
package gojsonschema
|
|
|
|
|
|
|
|
type (
|
2019-04-12 20:56:09 -04:00
|
|
|
// locale is an interface for defining custom error strings
|
2017-04-17 18:08:24 -04:00
|
|
|
locale interface {
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// False returns a format-string for "false" schema validation errors
|
|
|
|
False() string
|
|
|
|
|
|
|
|
// Required returns a format-string for "required" schema validation errors
|
2017-04-17 18:08:24 -04:00
|
|
|
Required() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// InvalidType returns a format-string for "invalid type" schema validation errors
|
2017-04-17 18:08:24 -04:00
|
|
|
InvalidType() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// NumberAnyOf returns a format-string for "anyOf" schema validation errors
|
2017-04-17 18:08:24 -04:00
|
|
|
NumberAnyOf() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// NumberOneOf returns a format-string for "oneOf" schema validation errors
|
2017-04-17 18:08:24 -04:00
|
|
|
NumberOneOf() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// NumberAllOf returns a format-string for "allOf" schema validation errors
|
2017-04-17 18:08:24 -04:00
|
|
|
NumberAllOf() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// NumberNot returns a format-string to format a NumberNotError
|
2017-04-17 18:08:24 -04:00
|
|
|
NumberNot() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// MissingDependency returns a format-string for "missing dependency" schema validation errors
|
2017-04-17 18:08:24 -04:00
|
|
|
MissingDependency() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// Internal returns a format-string for internal errors
|
2017-04-17 18:08:24 -04:00
|
|
|
Internal() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// Const returns a format-string to format a ConstError
|
2019-04-12 20:56:09 -04:00
|
|
|
Const() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// Enum returns a format-string to format an EnumError
|
2017-04-17 18:08:24 -04:00
|
|
|
Enum() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// ArrayNotEnoughItems returns a format-string to format an error for arrays having not enough items to match positional list of schema
|
2019-04-12 20:56:09 -04:00
|
|
|
ArrayNotEnoughItems() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// ArrayNoAdditionalItems returns a format-string to format an ArrayNoAdditionalItemsError
|
2017-04-17 18:08:24 -04:00
|
|
|
ArrayNoAdditionalItems() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// ArrayMinItems returns a format-string to format an ArrayMinItemsError
|
2017-04-17 18:08:24 -04:00
|
|
|
ArrayMinItems() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// ArrayMaxItems returns a format-string to format an ArrayMaxItemsError
|
2017-04-17 18:08:24 -04:00
|
|
|
ArrayMaxItems() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// Unique returns a format-string to format an ItemsMustBeUniqueError
|
2017-04-17 18:08:24 -04:00
|
|
|
Unique() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// ArrayContains returns a format-string to format an ArrayContainsError
|
2019-04-12 20:56:09 -04:00
|
|
|
ArrayContains() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// ArrayMinProperties returns a format-string to format an ArrayMinPropertiesError
|
2017-04-17 18:08:24 -04:00
|
|
|
ArrayMinProperties() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// ArrayMaxProperties returns a format-string to format an ArrayMaxPropertiesError
|
2017-04-17 18:08:24 -04:00
|
|
|
ArrayMaxProperties() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// AdditionalPropertyNotAllowed returns a format-string to format an AdditionalPropertyNotAllowedError
|
2017-04-17 18:08:24 -04:00
|
|
|
AdditionalPropertyNotAllowed() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// InvalidPropertyPattern returns a format-string to format an InvalidPropertyPatternError
|
2017-04-17 18:08:24 -04:00
|
|
|
InvalidPropertyPattern() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// InvalidPropertyName returns a format-string to format an InvalidPropertyNameError
|
2019-04-12 20:56:09 -04:00
|
|
|
InvalidPropertyName() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// StringGTE returns a format-string to format an StringLengthGTEError
|
2017-04-17 18:08:24 -04:00
|
|
|
StringGTE() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// StringLTE returns a format-string to format an StringLengthLTEError
|
2017-04-17 18:08:24 -04:00
|
|
|
StringLTE() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// DoesNotMatchPattern returns a format-string to format an DoesNotMatchPatternError
|
2017-04-17 18:08:24 -04:00
|
|
|
DoesNotMatchPattern() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// DoesNotMatchFormat returns a format-string to format an DoesNotMatchFormatError
|
2017-04-17 18:08:24 -04:00
|
|
|
DoesNotMatchFormat() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// MultipleOf returns a format-string to format an MultipleOfError
|
2017-04-17 18:08:24 -04:00
|
|
|
MultipleOf() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// NumberGTE returns a format-string to format an NumberGTEError
|
2017-04-17 18:08:24 -04:00
|
|
|
NumberGTE() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// NumberGT returns a format-string to format an NumberGTError
|
2017-04-17 18:08:24 -04:00
|
|
|
NumberGT() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// NumberLTE returns a format-string to format an NumberLTEError
|
2017-04-17 18:08:24 -04:00
|
|
|
NumberLTE() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// NumberLT returns a format-string to format an NumberLTError
|
2017-04-17 18:08:24 -04:00
|
|
|
NumberLT() string
|
|
|
|
|
|
|
|
// Schema validations
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// RegexPattern returns a format-string to format a regex-pattern error
|
2017-04-17 18:08:24 -04:00
|
|
|
RegexPattern() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// GreaterThanZero returns a format-string to format an error where a number must be greater than zero
|
2017-04-17 18:08:24 -04:00
|
|
|
GreaterThanZero() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// MustBeOfA returns a format-string to format an error where a value is of the wrong type
|
2017-04-17 18:08:24 -04:00
|
|
|
MustBeOfA() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// MustBeOfAn returns a format-string to format an error where a value is of the wrong type
|
2017-04-17 18:08:24 -04:00
|
|
|
MustBeOfAn() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// CannotBeUsedWithout returns a format-string to format a "cannot be used without" error
|
2017-04-17 18:08:24 -04:00
|
|
|
CannotBeUsedWithout() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// CannotBeGT returns a format-string to format an error where a value are greater than allowed
|
2017-04-17 18:08:24 -04:00
|
|
|
CannotBeGT() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// MustBeOfType returns a format-string to format an error where a value does not match the required type
|
2017-04-17 18:08:24 -04:00
|
|
|
MustBeOfType() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// MustBeValidRegex returns a format-string to format an error where a regex is invalid
|
2017-04-17 18:08:24 -04:00
|
|
|
MustBeValidRegex() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// MustBeValidFormat returns a format-string to format an error where a value does not match the expected format
|
2017-04-17 18:08:24 -04:00
|
|
|
MustBeValidFormat() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// MustBeGTEZero returns a format-string to format an error where a value must be greater or equal than 0
|
2017-04-17 18:08:24 -04:00
|
|
|
MustBeGTEZero() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// KeyCannotBeGreaterThan returns a format-string to format an error where a key is greater than the maximum allowed
|
2017-04-17 18:08:24 -04:00
|
|
|
KeyCannotBeGreaterThan() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// KeyItemsMustBeOfType returns a format-string to format an error where a key is of the wrong type
|
2017-04-17 18:08:24 -04:00
|
|
|
KeyItemsMustBeOfType() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// KeyItemsMustBeUnique returns a format-string to format an error where keys are not unique
|
2017-04-17 18:08:24 -04:00
|
|
|
KeyItemsMustBeUnique() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// ReferenceMustBeCanonical returns a format-string to format a "reference must be canonical" error
|
2017-04-17 18:08:24 -04:00
|
|
|
ReferenceMustBeCanonical() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// NotAValidType returns a format-string to format an invalid type error
|
2017-04-17 18:08:24 -04:00
|
|
|
NotAValidType() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// Duplicated returns a format-string to format an error where types are duplicated
|
2017-04-17 18:08:24 -04:00
|
|
|
Duplicated() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// HttpBadStatus returns a format-string for errors when loading a schema using HTTP
|
2019-04-12 20:56:09 -04:00
|
|
|
HttpBadStatus() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// ParseError returns a format-string for JSON parsing errors
|
2019-04-12 20:56:09 -04:00
|
|
|
ParseError() string
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// ConditionThen returns a format-string for ConditionThenError errors
|
2019-04-12 20:56:09 -04:00
|
|
|
ConditionThen() string
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// ConditionElse returns a format-string for ConditionElseError errors
|
2019-04-12 20:56:09 -04:00
|
|
|
ConditionElse() string
|
2017-04-17 18:08:24 -04:00
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// ErrorFormat returns a format string for errors
|
2017-04-17 18:08:24 -04:00
|
|
|
ErrorFormat() string
|
|
|
|
}
|
|
|
|
|
|
|
|
// DefaultLocale is the default locale for this package
|
|
|
|
DefaultLocale struct{}
|
|
|
|
)
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// False returns a format-string for "false" schema validation errors
|
|
|
|
func (l DefaultLocale) False() string {
|
|
|
|
return "False always fails validation"
|
|
|
|
}
|
|
|
|
|
|
|
|
// Required returns a format-string for "required" schema validation errors
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) Required() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `{{.property}} is required`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// InvalidType returns a format-string for "invalid type" schema validation errors
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) InvalidType() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `Invalid type. Expected: {{.expected}}, given: {{.given}}`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// NumberAnyOf returns a format-string for "anyOf" schema validation errors
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) NumberAnyOf() string {
|
|
|
|
return `Must validate at least one schema (anyOf)`
|
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// NumberOneOf returns a format-string for "oneOf" schema validation errors
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) NumberOneOf() string {
|
|
|
|
return `Must validate one and only one schema (oneOf)`
|
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// NumberAllOf returns a format-string for "allOf" schema validation errors
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) NumberAllOf() string {
|
|
|
|
return `Must validate all the schemas (allOf)`
|
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// NumberNot returns a format-string to format a NumberNotError
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) NumberNot() string {
|
|
|
|
return `Must not validate the schema (not)`
|
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// MissingDependency returns a format-string for "missing dependency" schema validation errors
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) MissingDependency() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `Has a dependency on {{.dependency}}`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// Internal returns a format-string for internal errors
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) Internal() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `Internal Error {{.error}}`
|
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// Const returns a format-string to format a ConstError
|
2019-04-12 20:56:09 -04:00
|
|
|
func (l DefaultLocale) Const() string {
|
|
|
|
return `{{.field}} does not match: {{.allowed}}`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// Enum returns a format-string to format an EnumError
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) Enum() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `{{.field}} must be one of the following: {{.allowed}}`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// ArrayNoAdditionalItems returns a format-string to format an ArrayNoAdditionalItemsError
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) ArrayNoAdditionalItems() string {
|
|
|
|
return `No additional items allowed on array`
|
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// ArrayNotEnoughItems returns a format-string to format an error for arrays having not enough items to match positional list of schema
|
2019-04-12 20:56:09 -04:00
|
|
|
func (l DefaultLocale) ArrayNotEnoughItems() string {
|
|
|
|
return `Not enough items on array to match positional list of schema`
|
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// ArrayMinItems returns a format-string to format an ArrayMinItemsError
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) ArrayMinItems() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `Array must have at least {{.min}} items`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// ArrayMaxItems returns a format-string to format an ArrayMaxItemsError
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) ArrayMaxItems() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `Array must have at most {{.max}} items`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// Unique returns a format-string to format an ItemsMustBeUniqueError
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) Unique() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `{{.type}} items[{{.i}},{{.j}}] must be unique`
|
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// ArrayContains returns a format-string to format an ArrayContainsError
|
2019-04-12 20:56:09 -04:00
|
|
|
func (l DefaultLocale) ArrayContains() string {
|
|
|
|
return `At least one of the items must match`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// ArrayMinProperties returns a format-string to format an ArrayMinPropertiesError
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) ArrayMinProperties() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `Must have at least {{.min}} properties`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// ArrayMaxProperties returns a format-string to format an ArrayMaxPropertiesError
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) ArrayMaxProperties() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `Must have at most {{.max}} properties`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// AdditionalPropertyNotAllowed returns a format-string to format an AdditionalPropertyNotAllowedError
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) AdditionalPropertyNotAllowed() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `Additional property {{.property}} is not allowed`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// InvalidPropertyPattern returns a format-string to format an InvalidPropertyPatternError
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) InvalidPropertyPattern() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `Property "{{.property}}" does not match pattern {{.pattern}}`
|
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// InvalidPropertyName returns a format-string to format an InvalidPropertyNameError
|
2019-04-12 20:56:09 -04:00
|
|
|
func (l DefaultLocale) InvalidPropertyName() string {
|
|
|
|
return `Property name of "{{.property}}" does not match`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// StringGTE returns a format-string to format an StringLengthGTEError
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) StringGTE() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `String length must be greater than or equal to {{.min}}`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// StringLTE returns a format-string to format an StringLengthLTEError
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) StringLTE() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `String length must be less than or equal to {{.max}}`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// DoesNotMatchPattern returns a format-string to format an DoesNotMatchPatternError
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) DoesNotMatchPattern() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `Does not match pattern '{{.pattern}}'`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// DoesNotMatchFormat returns a format-string to format an DoesNotMatchFormatError
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) DoesNotMatchFormat() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `Does not match format '{{.format}}'`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// MultipleOf returns a format-string to format an MultipleOfError
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) MultipleOf() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `Must be a multiple of {{.multiple}}`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// NumberGTE returns the format string to format a NumberGTEError
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) NumberGTE() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `Must be greater than or equal to {{.min}}`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// NumberGT returns the format string to format a NumberGTError
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) NumberGT() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `Must be greater than {{.min}}`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// NumberLTE returns the format string to format a NumberLTEError
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) NumberLTE() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `Must be less than or equal to {{.max}}`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// NumberLT returns the format string to format a NumberLTError
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) NumberLT() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `Must be less than {{.max}}`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Schema validators
|
2020-06-30 10:20:03 -04:00
|
|
|
|
|
|
|
// RegexPattern returns a format-string to format a regex-pattern error
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) RegexPattern() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `Invalid regex pattern '{{.pattern}}'`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// GreaterThanZero returns a format-string to format an error where a number must be greater than zero
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) GreaterThanZero() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `{{.number}} must be strictly greater than 0`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// MustBeOfA returns a format-string to format an error where a value is of the wrong type
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) MustBeOfA() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `{{.x}} must be of a {{.y}}`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// MustBeOfAn returns a format-string to format an error where a value is of the wrong type
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) MustBeOfAn() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `{{.x}} must be of an {{.y}}`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// CannotBeUsedWithout returns a format-string to format a "cannot be used without" error
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) CannotBeUsedWithout() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `{{.x}} cannot be used without {{.y}}`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// CannotBeGT returns a format-string to format an error where a value are greater than allowed
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) CannotBeGT() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `{{.x}} cannot be greater than {{.y}}`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// MustBeOfType returns a format-string to format an error where a value does not match the required type
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) MustBeOfType() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `{{.key}} must be of type {{.type}}`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// MustBeValidRegex returns a format-string to format an error where a regex is invalid
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) MustBeValidRegex() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `{{.key}} must be a valid regex`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// MustBeValidFormat returns a format-string to format an error where a value does not match the expected format
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) MustBeValidFormat() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `{{.key}} must be a valid format {{.given}}`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// MustBeGTEZero returns a format-string to format an error where a value must be greater or equal than 0
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) MustBeGTEZero() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `{{.key}} must be greater than or equal to 0`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// KeyCannotBeGreaterThan returns a format-string to format an error where a value is greater than the maximum allowed
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) KeyCannotBeGreaterThan() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `{{.key}} cannot be greater than {{.y}}`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// KeyItemsMustBeOfType returns a format-string to format an error where a key is of the wrong type
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) KeyItemsMustBeOfType() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `{{.key}} items must be {{.type}}`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// KeyItemsMustBeUnique returns a format-string to format an error where keys are not unique
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) KeyItemsMustBeUnique() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `{{.key}} items must be unique`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// ReferenceMustBeCanonical returns a format-string to format a "reference must be canonical" error
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) ReferenceMustBeCanonical() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `Reference {{.reference}} must be canonical`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// NotAValidType returns a format-string to format an invalid type error
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) NotAValidType() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `has a primitive type that is NOT VALID -- given: {{.given}} Expected valid values are:{{.expected}}`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// Duplicated returns a format-string to format an error where types are duplicated
|
2017-04-17 18:08:24 -04:00
|
|
|
func (l DefaultLocale) Duplicated() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `{{.type}} type is duplicated`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// HttpBadStatus returns a format-string for errors when loading a schema using HTTP
|
2019-04-12 20:56:09 -04:00
|
|
|
func (l DefaultLocale) HttpBadStatus() string {
|
|
|
|
return `Could not read schema from HTTP, response status is {{.status}}`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// ErrorFormat returns a format string for errors
|
2017-04-17 18:08:24 -04:00
|
|
|
// Replacement options: field, description, context, value
|
|
|
|
func (l DefaultLocale) ErrorFormat() string {
|
2019-04-12 20:56:09 -04:00
|
|
|
return `{{.field}}: {{.description}}`
|
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// ParseError returns a format-string for JSON parsing errors
|
2019-04-12 20:56:09 -04:00
|
|
|
func (l DefaultLocale) ParseError() string {
|
|
|
|
return `Expected: {{.expected}}, given: Invalid JSON`
|
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// ConditionThen returns a format-string for ConditionThenError errors
|
|
|
|
// If/Else
|
2019-04-12 20:56:09 -04:00
|
|
|
func (l DefaultLocale) ConditionThen() string {
|
|
|
|
return `Must validate "then" as "if" was valid`
|
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// ConditionElse returns a format-string for ConditionElseError errors
|
2019-04-12 20:56:09 -04:00
|
|
|
func (l DefaultLocale) ConditionElse() string {
|
|
|
|
return `Must validate "else" as "if" was not valid`
|
2017-04-17 18:08:24 -04:00
|
|
|
}
|
|
|
|
|
2020-06-30 10:20:03 -04:00
|
|
|
// constants
|
2017-04-17 18:08:24 -04:00
|
|
|
const (
|
|
|
|
STRING_NUMBER = "number"
|
|
|
|
STRING_ARRAY_OF_STRINGS = "array of strings"
|
|
|
|
STRING_ARRAY_OF_SCHEMAS = "array of schemas"
|
2019-04-12 20:56:09 -04:00
|
|
|
STRING_SCHEMA = "valid schema"
|
2017-04-17 18:08:24 -04:00
|
|
|
STRING_SCHEMA_OR_ARRAY_OF_STRINGS = "schema or array of strings"
|
|
|
|
STRING_PROPERTIES = "properties"
|
|
|
|
STRING_DEPENDENCY = "dependency"
|
|
|
|
STRING_PROPERTY = "property"
|
|
|
|
STRING_UNDEFINED = "undefined"
|
|
|
|
STRING_CONTEXT_ROOT = "(root)"
|
|
|
|
STRING_ROOT_SCHEMA_PROPERTY = "(root)"
|
|
|
|
)
|