in pkg/validation/validate/type.go [35:118]
func (t *typeValidator) schemaInfoForType(data interface{}) (string, string) {
// internal type to JSON type with swagger 2.0 format (with go-openapi/strfmt extensions),
// see https://github.com/go-openapi/strfmt/blob/master/README.md
// TODO: this switch really is some sort of reverse lookup for formats. It should be provided by strfmt.
switch data.(type) {
case []byte, strfmt.Base64, *strfmt.Base64:
return stringType, stringFormatByte
case strfmt.CreditCard, *strfmt.CreditCard:
return stringType, stringFormatCreditCard
case strfmt.Date, *strfmt.Date:
return stringType, stringFormatDate
case strfmt.DateTime, *strfmt.DateTime:
return stringType, stringFormatDateTime
case strfmt.Duration, *strfmt.Duration:
return stringType, stringFormatDuration
case strfmt.Email, *strfmt.Email:
return stringType, stringFormatEmail
case strfmt.HexColor, *strfmt.HexColor:
return stringType, stringFormatHexColor
case strfmt.Hostname, *strfmt.Hostname:
return stringType, stringFormatHostname
case strfmt.IPv4, *strfmt.IPv4:
return stringType, stringFormatIPv4
case strfmt.IPv6, *strfmt.IPv6:
return stringType, stringFormatIPv6
case strfmt.ISBN, *strfmt.ISBN:
return stringType, stringFormatISBN
case strfmt.ISBN10, *strfmt.ISBN10:
return stringType, stringFormatISBN10
case strfmt.ISBN13, *strfmt.ISBN13:
return stringType, stringFormatISBN13
case strfmt.MAC, *strfmt.MAC:
return stringType, stringFormatMAC
case strfmt.Password, *strfmt.Password:
return stringType, stringFormatPassword
case strfmt.RGBColor, *strfmt.RGBColor:
return stringType, stringFormatRGBColor
case strfmt.SSN, *strfmt.SSN:
return stringType, stringFormatSSN
case strfmt.URI, *strfmt.URI:
return stringType, stringFormatURI
case strfmt.UUID, *strfmt.UUID:
return stringType, stringFormatUUID
case strfmt.UUID3, *strfmt.UUID3:
return stringType, stringFormatUUID3
case strfmt.UUID4, *strfmt.UUID4:
return stringType, stringFormatUUID4
case strfmt.UUID5, *strfmt.UUID5:
return stringType, stringFormatUUID5
// TODO: missing binary (io.ReadCloser)
// TODO: missing json.Number
default:
val := reflect.ValueOf(data)
tpe := val.Type()
switch tpe.Kind() {
case reflect.Bool:
return booleanType, ""
case reflect.String:
return stringType, ""
case reflect.Int8, reflect.Int16, reflect.Int32, reflect.Uint8, reflect.Uint16, reflect.Uint32:
// NOTE: that is the spec. With go-openapi, is that not uint32 for unsigned integers?
return integerType, integerFormatInt32
case reflect.Int, reflect.Int64, reflect.Uint, reflect.Uint64:
return integerType, integerFormatInt64
case reflect.Float32:
// NOTE: is that not numberFormatFloat?
return numberType, numberFormatFloat32
case reflect.Float64:
// NOTE: is that not "double"?
return numberType, numberFormatFloat64
// NOTE: go arrays (reflect.Array) are not supported (fixed length)
case reflect.Slice:
return arrayType, ""
case reflect.Map, reflect.Struct:
return objectType, ""
case reflect.Interface:
// What to do here?
panic("dunno what to do here")
case reflect.Ptr:
return t.schemaInfoForType(reflect.Indirect(val).Interface())
}
}
return "", ""
}