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

Function ExclusiveMaximum

dsl/validation.go:279–309  ·  view source on GitHub ↗

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

(val any)

Source from the content-addressed store, hash-verified

277// ExclusiveMaximum(100)
278// })
279func ExclusiveMaximum(val any) {
280 if a, ok := eval.Current().(*expr.AttributeExpr); ok {
281 if a.Type != nil &&
282 a.Type.Kind() != expr.IntKind && a.Type.Kind() != expr.UIntKind &&
283 a.Type.Kind() != expr.Int32Kind && a.Type.Kind() != expr.UInt32Kind &&
284 a.Type.Kind() != expr.Int64Kind && a.Type.Kind() != expr.UInt64Kind &&
285 a.Type.Kind() != expr.Float32Kind && a.Type.Kind() != expr.Float64Kind {
286 incompatibleAttributeType("exclusiveMaximum", a.Type.Name(), "a number")
287 } else {
288 var f float64
289 switch v := val.(type) {
290 case float32, float64, int, int8, int16, int32, int64, uint8, uint16, uint32, uint64:
291 f = reflect.ValueOf(v).Convert(reflect.TypeOf(float64(0.0))).Float()
292 case string:
293 var err error
294 f, err = strconv.ParseFloat(v, 64)
295 if err != nil {
296 eval.ReportError("invalid number value %#v", v)
297 return
298 }
299 default:
300 eval.ReportError("invalid number value %#v", v)
301 return
302 }
303 if a.Validation == nil {
304 a.Validation = &expr.ValidationExpr{}
305 }
306 a.Validation.ExclusiveMaximum = &f
307 }
308 }
309}
310
311// Maximum adds a "maximum" validation to the attribute.
312// See http://json-schema.org/latest/json-schema-validation.html#anchor17.

Callers 1

Calls 5

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

Tested by

no test coverage detected