summaryrefslogtreecommitdiff
path: root/vendor/github.com/xeipuuv/gojsonschema/schema.go
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2020-02-22 05:28:21 -0500
committerDaniel J Walsh <dwalsh@redhat.com>2020-02-25 07:46:20 -0400
commit68c313911e8a3aed605a12398442212b99f41619 (patch)
treec4273c58fd0a675d02daef9a63bc6ce9c38e4c11 /vendor/github.com/xeipuuv/gojsonschema/schema.go
parent8a30759b6b7f73c76c90e0931e6cf1ca3d94ee61 (diff)
downloadpodman-68c313911e8a3aed605a12398442212b99f41619.tar.gz
podman-68c313911e8a3aed605a12398442212b99f41619.tar.bz2
podman-68c313911e8a3aed605a12398442212b99f41619.zip
Update vendor of buildah and containers/common
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'vendor/github.com/xeipuuv/gojsonschema/schema.go')
-rw-r--r--vendor/github.com/xeipuuv/gojsonschema/schema.go75
1 files changed, 45 insertions, 30 deletions
diff --git a/vendor/github.com/xeipuuv/gojsonschema/schema.go b/vendor/github.com/xeipuuv/gojsonschema/schema.go
index 323fe8559..9e93cd795 100644
--- a/vendor/github.com/xeipuuv/gojsonschema/schema.go
+++ b/vendor/github.com/xeipuuv/gojsonschema/schema.go
@@ -45,10 +45,12 @@ var (
ErrorTemplateFuncs template.FuncMap
)
+// NewSchema instances a schema using the given JSONLoader
func NewSchema(l JSONLoader) (*Schema, error) {
return NewSchemaLoader().Compile(l)
}
+// Schema holds a schema
type Schema struct {
documentReference gojsonreference.JsonReference
rootSchema *subSchema
@@ -61,6 +63,7 @@ func (d *Schema) parse(document interface{}, draft Draft) error {
return d.parseSchema(document, d.rootSchema)
}
+// SetRootSchemaName sets the root-schema name
func (d *Schema) SetRootSchemaName(name string) {
d.rootSchema.property = name
}
@@ -83,11 +86,8 @@ func (d *Schema) parseSchema(documentNode interface{}, currentSchema *subSchema)
// As of draft 6 "true" is equivalent to an empty schema "{}" and false equals "{"not":{}}"
if *currentSchema.draft >= Draft6 && isKind(documentNode, reflect.Bool) {
b := documentNode.(bool)
- if b {
- documentNode = map[string]interface{}{}
- } else {
- documentNode = map[string]interface{}{"not": true}
- }
+ currentSchema.pass = &b
+ return nil
}
if !isKind(documentNode, reflect.Map) {
@@ -267,8 +267,9 @@ func (d *Schema) parseSchema(documentNode interface{}, currentSchema *subSchema)
"given": KEY_TYPE,
},
))
- } else {
- currentSchema.types.Add(typeInArray.(string))
+ }
+ if err := currentSchema.types.Add(typeInArray.(string)); err != nil {
+ return err
}
}
@@ -382,7 +383,7 @@ func (d *Schema) parseSchema(documentNode interface{}, currentSchema *subSchema)
if isKind(itemElement, reflect.Map, reflect.Bool) {
newSchema := &subSchema{parent: currentSchema, property: KEY_ITEMS}
newSchema.ref = currentSchema.ref
- currentSchema.AddItemsChild(newSchema)
+ currentSchema.itemsChildren = append(currentSchema.itemsChildren, newSchema)
err := d.parseSchema(itemElement, newSchema)
if err != nil {
return err
@@ -401,7 +402,7 @@ func (d *Schema) parseSchema(documentNode interface{}, currentSchema *subSchema)
} else if isKind(m[KEY_ITEMS], reflect.Map, reflect.Bool) {
newSchema := &subSchema{parent: currentSchema, property: KEY_ITEMS}
newSchema.ref = currentSchema.ref
- currentSchema.AddItemsChild(newSchema)
+ currentSchema.itemsChildren = append(currentSchema.itemsChildren, newSchema)
err := d.parseSchema(m[KEY_ITEMS], newSchema)
if err != nil {
return err
@@ -507,7 +508,7 @@ func (d *Schema) parseSchema(documentNode interface{}, currentSchema *subSchema)
currentSchema.exclusiveMinimum = currentSchema.minimum
currentSchema.minimum = nil
}
- } else if isJsonNumber(m[KEY_EXCLUSIVE_MINIMUM]) {
+ } else if isJSONNumber(m[KEY_EXCLUSIVE_MINIMUM]) {
currentSchema.exclusiveMinimum = mustBeNumber(m[KEY_EXCLUSIVE_MINIMUM])
} else {
return errors.New(formatErrorDescription(
@@ -519,7 +520,7 @@ func (d *Schema) parseSchema(documentNode interface{}, currentSchema *subSchema)
))
}
default:
- if isJsonNumber(m[KEY_EXCLUSIVE_MINIMUM]) {
+ if isJSONNumber(m[KEY_EXCLUSIVE_MINIMUM]) {
currentSchema.exclusiveMinimum = mustBeNumber(m[KEY_EXCLUSIVE_MINIMUM])
} else {
return errors.New(formatErrorDescription(
@@ -578,7 +579,7 @@ func (d *Schema) parseSchema(documentNode interface{}, currentSchema *subSchema)
currentSchema.exclusiveMaximum = currentSchema.maximum
currentSchema.maximum = nil
}
- } else if isJsonNumber(m[KEY_EXCLUSIVE_MAXIMUM]) {
+ } else if isJSONNumber(m[KEY_EXCLUSIVE_MAXIMUM]) {
currentSchema.exclusiveMaximum = mustBeNumber(m[KEY_EXCLUSIVE_MAXIMUM])
} else {
return errors.New(formatErrorDescription(
@@ -590,7 +591,7 @@ func (d *Schema) parseSchema(documentNode interface{}, currentSchema *subSchema)
))
}
default:
- if isJsonNumber(m[KEY_EXCLUSIVE_MAXIMUM]) {
+ if isJSONNumber(m[KEY_EXCLUSIVE_MAXIMUM]) {
currentSchema.exclusiveMaximum = mustBeNumber(m[KEY_EXCLUSIVE_MAXIMUM])
} else {
return errors.New(formatErrorDescription(
@@ -669,9 +670,13 @@ func (d *Schema) parseSchema(documentNode interface{}, currentSchema *subSchema)
if existsMapKey(m, KEY_FORMAT) {
formatString, ok := m[KEY_FORMAT].(string)
- if ok && FormatCheckers.Has(formatString) {
- currentSchema.format = formatString
+ if !ok {
+ return errors.New(formatErrorDescription(
+ Locale.MustBeOfType(),
+ ErrorDetails{"key": KEY_FORMAT, "type": TYPE_STRING},
+ ))
}
+ currentSchema.format = formatString
}
// validation : object
@@ -724,10 +729,13 @@ func (d *Schema) parseSchema(documentNode interface{}, currentSchema *subSchema)
requiredValues := m[KEY_REQUIRED].([]interface{})
for _, requiredValue := range requiredValues {
if isKind(requiredValue, reflect.String) {
- err := currentSchema.AddRequired(requiredValue.(string))
- if err != nil {
- return err
+ if isStringInSlice(currentSchema.required, requiredValue.(string)) {
+ return errors.New(formatErrorDescription(
+ Locale.KeyItemsMustBeUnique(),
+ ErrorDetails{"key": KEY_REQUIRED},
+ ))
}
+ currentSchema.required = append(currentSchema.required, requiredValue.(string))
} else {
return errors.New(formatErrorDescription(
Locale.KeyItemsMustBeOfType(),
@@ -802,19 +810,27 @@ func (d *Schema) parseSchema(documentNode interface{}, currentSchema *subSchema)
// validation : all
if existsMapKey(m, KEY_CONST) && *currentSchema.draft >= Draft6 {
- err := currentSchema.AddConst(m[KEY_CONST])
+ is, err := marshalWithoutNumber(m[KEY_CONST])
if err != nil {
return err
}
+ currentSchema._const = is
}
if existsMapKey(m, KEY_ENUM) {
if isKind(m[KEY_ENUM], reflect.Slice) {
for _, v := range m[KEY_ENUM].([]interface{}) {
- err := currentSchema.AddEnum(v)
+ is, err := marshalWithoutNumber(v)
if err != nil {
return err
}
+ if isStringInSlice(currentSchema.enum, *is) {
+ return errors.New(formatErrorDescription(
+ Locale.KeyItemsMustBeUnique(),
+ ErrorDetails{"key": KEY_ENUM},
+ ))
+ }
+ currentSchema.enum = append(currentSchema.enum, *is)
}
} else {
return errors.New(formatErrorDescription(
@@ -830,7 +846,7 @@ func (d *Schema) parseSchema(documentNode interface{}, currentSchema *subSchema)
if isKind(m[KEY_ONE_OF], reflect.Slice) {
for _, v := range m[KEY_ONE_OF].([]interface{}) {
newSchema := &subSchema{property: KEY_ONE_OF, parent: currentSchema, ref: currentSchema.ref}
- currentSchema.AddOneOf(newSchema)
+ currentSchema.oneOf = append(currentSchema.oneOf, newSchema)
err := d.parseSchema(v, newSchema)
if err != nil {
return err
@@ -848,7 +864,7 @@ func (d *Schema) parseSchema(documentNode interface{}, currentSchema *subSchema)
if isKind(m[KEY_ANY_OF], reflect.Slice) {
for _, v := range m[KEY_ANY_OF].([]interface{}) {
newSchema := &subSchema{property: KEY_ANY_OF, parent: currentSchema, ref: currentSchema.ref}
- currentSchema.AddAnyOf(newSchema)
+ currentSchema.anyOf = append(currentSchema.anyOf, newSchema)
err := d.parseSchema(v, newSchema)
if err != nil {
return err
@@ -866,7 +882,7 @@ func (d *Schema) parseSchema(documentNode interface{}, currentSchema *subSchema)
if isKind(m[KEY_ALL_OF], reflect.Slice) {
for _, v := range m[KEY_ALL_OF].([]interface{}) {
newSchema := &subSchema{property: KEY_ALL_OF, parent: currentSchema, ref: currentSchema.ref}
- currentSchema.AddAllOf(newSchema)
+ currentSchema.allOf = append(currentSchema.allOf, newSchema)
err := d.parseSchema(v, newSchema)
if err != nil {
return err
@@ -883,7 +899,7 @@ func (d *Schema) parseSchema(documentNode interface{}, currentSchema *subSchema)
if existsMapKey(m, KEY_NOT) {
if isKind(m[KEY_NOT], reflect.Map, reflect.Bool) {
newSchema := &subSchema{property: KEY_NOT, parent: currentSchema, ref: currentSchema.ref}
- currentSchema.SetNot(newSchema)
+ currentSchema.not = newSchema
err := d.parseSchema(m[KEY_NOT], newSchema)
if err != nil {
return err
@@ -900,7 +916,7 @@ func (d *Schema) parseSchema(documentNode interface{}, currentSchema *subSchema)
if existsMapKey(m, KEY_IF) {
if isKind(m[KEY_IF], reflect.Map, reflect.Bool) {
newSchema := &subSchema{property: KEY_IF, parent: currentSchema, ref: currentSchema.ref}
- currentSchema.SetIf(newSchema)
+ currentSchema._if = newSchema
err := d.parseSchema(m[KEY_IF], newSchema)
if err != nil {
return err
@@ -916,7 +932,7 @@ func (d *Schema) parseSchema(documentNode interface{}, currentSchema *subSchema)
if existsMapKey(m, KEY_THEN) {
if isKind(m[KEY_THEN], reflect.Map, reflect.Bool) {
newSchema := &subSchema{property: KEY_THEN, parent: currentSchema, ref: currentSchema.ref}
- currentSchema.SetThen(newSchema)
+ currentSchema._then = newSchema
err := d.parseSchema(m[KEY_THEN], newSchema)
if err != nil {
return err
@@ -932,7 +948,7 @@ func (d *Schema) parseSchema(documentNode interface{}, currentSchema *subSchema)
if existsMapKey(m, KEY_ELSE) {
if isKind(m[KEY_ELSE], reflect.Map, reflect.Bool) {
newSchema := &subSchema{property: KEY_ELSE, parent: currentSchema, ref: currentSchema.ref}
- currentSchema.SetElse(newSchema)
+ currentSchema._else = newSchema
err := d.parseSchema(m[KEY_ELSE], newSchema)
if err != nil {
return err
@@ -1004,7 +1020,7 @@ func (d *Schema) parseProperties(documentNode interface{}, currentSchema *subSch
for k := range m {
schemaProperty := k
newSchema := &subSchema{property: schemaProperty, parent: currentSchema, ref: currentSchema.ref}
- currentSchema.AddPropertiesChild(newSchema)
+ currentSchema.propertiesChildren = append(currentSchema.propertiesChildren, newSchema)
err := d.parseSchema(m[k], newSchema)
if err != nil {
return err
@@ -1042,9 +1058,8 @@ func (d *Schema) parseDependencies(documentNode interface{}, currentSchema *subS
"type": STRING_SCHEMA_OR_ARRAY_OF_STRINGS,
},
))
- } else {
- valuesToRegister = append(valuesToRegister, value.(string))
}
+ valuesToRegister = append(valuesToRegister, value.(string))
currentSchema.dependencies[k] = valuesToRegister
}