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

Function Pattern

dsl/validation.go:173–189  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

171// Pattern("^[A-Z].*[0-9]$")
172// })
173func 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.

Callers 4

result_dsls.goFile · 0.85
payload_dsls.goFile · 0.85
type_spec_test.goFile · 0.85

Calls 6

CurrentFunction · 0.92
ReportErrorFunction · 0.92
CompileMethod · 0.80
KindMethod · 0.65
NameMethod · 0.65

Tested by

no test coverage detected