github.com/kaptinlin/jsonschema@v0.4.6/exclusiveMinimum.go (about)

     1  package jsonschema
     2  
     3  // EvaluateExclusiveMinimum checks if a numeric instance is strictly greater than the value specified by exclusiveMinimum.
     4  // According to the JSON Schema Draft 2020-12:
     5  //   - The value of the "exclusiveMinimum" keyword must be a number.
     6  //   - The instance is valid only if it is strictly greater than (not equal to) the value specified by "exclusiveMinimum".
     7  //
     8  // This method ensures that the numeric data instance meets the exclusive minimum limit defined in the schema.
     9  // If the instance does not meet this limit, it returns a EvaluationError detailing the expected minimum value and the actual value.
    10  //
    11  // Reference: https://json-schema.org/draft/2020-12/json-schema-validation#name-exclusiveminimum
    12  func evaluateExclusiveMinimum(schema *Schema, value *Rat) *EvaluationError {
    13  	if schema.ExclusiveMinimum != nil {
    14  		if value.Cmp(schema.ExclusiveMinimum.Rat) <= 0 {
    15  			// Data does not meet the exclusive minimum value.
    16  			return NewEvaluationError("exclusiveMinimum", "exclusive_minimum_mismatch", "{value} should be greater than {exclusive_minimum}", map[string]interface{}{
    17  				"exclusive_minimum": FormatRat(schema.ExclusiveMinimum),
    18  				"value":             FormatRat(value),
    19  			})
    20  		}
    21  	}
    22  	return nil
    23  }