MCPcopy Create free account
hub / github.com/goadesign/goa / ExclusiveMinimum

Function ExclusiveMinimum

dsl/validation.go:199–229  ·  view source on GitHub ↗

ExclusiveMinimum adds a "exclusiveMinimum" validation to the attribute. See http://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.2.5. Example: Attribute("float", float32, func() { ExclusiveMinimum(100) })

(val any)

Source from the content-addressed store, hash-verified

197// ExclusiveMinimum(100)
198// })
199func ExclusiveMinimum(val any) {
200 if a, ok := eval.Current().(*expr.AttributeExpr); ok {
201 if a.Type != nil &&
202 a.Type.Kind() != expr.IntKind && a.Type.Kind() != expr.UIntKind &&
203 a.Type.Kind() != expr.Int32Kind && a.Type.Kind() != expr.UInt32Kind &&
204 a.Type.Kind() != expr.Int64Kind && a.Type.Kind() != expr.UInt64Kind &&
205 a.Type.Kind() != expr.Float32Kind && a.Type.Kind() != expr.Float64Kind {
206 incompatibleAttributeType("exclusiveMinimum", a.Type.Name(), "a number")
207 } else {
208 var f float64
209 switch v := val.(type) {
210 case float32, float64, int, int8, int16, int32, int64, uint8, uint16, uint32, uint64:
211 f = reflect.ValueOf(v).Convert(reflect.TypeOf(float64(0.0))).Float()
212 case string:
213 var err error
214 f, err = strconv.ParseFloat(v, 64)
215 if err != nil {
216 eval.ReportError("invalid number value %#v", v)
217 return
218 }
219 default:
220 eval.ReportError("invalid number value %#v", v)
221 return
222 }
223 if a.Validation == nil {
224 a.Validation = &expr.ValidationExpr{}
225 }
226 a.Validation.ExclusiveMinimum = &f
227 }
228 }
229}
230
231// Minimum adds a "minimum" validation to the attribute.
232// See http://json-schema.org/latest/json-schema-validation.html#anchor21.

Callers 1

Calls 5

CurrentFunction · 0.92
ReportErrorFunction · 0.92
KindMethod · 0.65
NameMethod · 0.65

Tested by

no test coverage detected