Pattern adds a "pattern" validation to the attribute. See http://json-schema.org/latest/json-schema-validation.html#anchor33. Example: Attribute("pattern", String, func() { Pattern("^[A-Z].*[0-9]$") })
(p string)
| 171 | // Pattern("^[A-Z].*[0-9]$") |
| 172 | // }) |
| 173 | func Pattern(p string) { |
| 174 | if a, ok := eval.Current().(*expr.AttributeExpr); ok { |
| 175 | if a.Type != nil && a.Type.Kind() != expr.StringKind { |
| 176 | incompatibleAttributeType("pattern", a.Type.Name(), "a string") |
| 177 | } else { |
| 178 | _, err := regexp.Compile(p) |
| 179 | if err != nil { |
| 180 | eval.ReportError("invalid pattern %#v, %s", p, err) |
| 181 | } else { |
| 182 | if a.Validation == nil { |
| 183 | a.Validation = &expr.ValidationExpr{} |
| 184 | } |
| 185 | a.Validation.Pattern = p |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | // ExclusiveMinimum adds a "exclusiveMinimum" validation to the attribute. |
| 192 | // See http://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.2.5. |
no test coverage detected