github.com/kaptinlin/jsonschema@v0.4.6/minimum.go (about) 1 package jsonschema 2 3 // EvaluateMinimum checks if the numeric data's value meets or exceeds the minimum value specified in the schema. 4 // According to the JSON Schema Draft 2020-12: 5 // - The value of the "minimum" keyword must be a number, representing an inclusive lower limit for a numeric instance. 6 // - This keyword validates only if the instance is greater than or exactly equal to "minimum". 7 // 8 // This method ensures that the numeric data instance conforms to the minimum constraints defined in the schema. 9 // If the instance is below the minimum value, it returns a EvaluationError detailing the expected minimum and actual value. 10 // 11 // Reference: https://json-schema.org/draft/2020-12/json-schema-validation#name-minimum 12 func evaluateMinimum(schema *Schema, value *Rat) *EvaluationError { 13 if schema.Minimum != nil { 14 if value.Cmp(schema.Minimum.Rat) < 0 { 15 // If the data value is below the minimum value, construct and return an error. 16 return NewEvaluationError("minimum", "value_below_minimum", "{value} should be at least {minimum}", map[string]interface{}{ 17 "value": FormatRat(value), 18 "minimum": FormatRat(schema.Minimum), 19 }) 20 } 21 } 22 return nil 23 }