fetch a shared correlated object off the validation options if it exists

c
This commit is contained in:
Alexander Zielenski 2023-10-23 12:14:56 -07:00
parent 0a19b5ab6e
commit dfeab6eca8

View File

@ -60,8 +60,20 @@ func (r *RatchetingSchemaValidator) Validate(new interface{}, options ...Validat
}
func (r *RatchetingSchemaValidator) ValidateUpdate(new, old interface{}, options ...ValidationOption) *validate.Result {
opts := NewValidationOptions(options...)
if !opts.Ratcheting {
sv := validate.NewSchemaValidator(r.schema, r.root, r.path, r.knownFormats, r.options...)
return sv.Validate(new)
}
correlation := opts.CorrelatedObject
if correlation == nil {
correlation = common.NewCorrelatedObject(new, old, &celopenapi.Schema{Schema: r.schema})
}
return newRatchetingValueValidator(
common.NewCorrelatedObject(new, old, &celopenapi.Schema{Schema: r.schemaArgs.schema}),
correlation,
r.schemaArgs,
).Validate(new)
}