Format adds a "format" validation to the attribute. See http://json-schema.org/latest/json-schema-validation.html#anchor104. The formats supported by goa are: FormatDate: RFC3339 date FormatDateTime: RFC3339 date time FormatUUID: RFC4122 uuid FormatEmail: RFC5322 email address FormatHostname: R
(f expr.ValidationFormat)
| 147 | // Format(FormatDateTime) |
| 148 | // }) |
| 149 | func Format(f expr.ValidationFormat) { |
| 150 | if a, ok := eval.Current().(*expr.AttributeExpr); ok { |
| 151 | if !a.IsSupportedValidationFormat(f) { |
| 152 | eval.ReportError("invalid validation format %q", f) |
| 153 | } |
| 154 | if a.Type != nil && a.Type.Kind() != expr.StringKind { |
| 155 | incompatibleAttributeType("format", a.Type.Name(), "a string") |
| 156 | } else { |
| 157 | if a.Validation == nil { |
| 158 | a.Validation = &expr.ValidationExpr{} |
| 159 | } |
| 160 | a.Validation.Format = f |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | // Pattern adds a "pattern" validation to the attribute. |
| 166 | // See http://json-schema.org/latest/json-schema-validation.html#anchor33. |