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

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