You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
Currently there is no way to enforce a pattern on a string field similar to the pattern regex field in the Swagger 2.0 spec.
Describe the solution you'd like
String fields could use a new .Pattern() to supply a regex and enforce a pattern on string fields. I think fields of other types would just ignore this helper?
This could look something like the following (I didn't show it below, but could also add Pattern to the Parameter/JsonSchema structs so that field also gets included in the swagger):
Let me know what you think. If you accept PRs, I could also try to put something together after the holiday week.
// Field allows specification of swagger or json schema types using the builder pattern.typeFieldstruct {
kindstringobjmap[string]Fieldmax*float64min*float64// TODO: New pattern fieldpattern*regexp.Regexprequired*boolexampleinterface{}
descriptionstringenumenum_defaultinterface{}
arr*Fieldallowenumstrip*boolunknown*bool
}
...var (
errRequired=fmt.Errorf("value is required")
errWrongType=fmt.Errorf("wrong type passed")
errMaximum=fmt.Errorf("maximum exceeded")
errMinimum=fmt.Errorf("minimum exceeded")
errEnumNotFound=fmt.Errorf("value not in enum")
errUnknown=fmt.Errorf("unknown value")
// TODO: New ErrorerrPattern=fmt.Errorf("value does not match pattern")
)
...case string:
iff.kind!=KindString {
returnerrWrongType
}
iff.required!=nil&&*f.required&&v==""&&!f.allow.has("") {
returnerrRequired
}
iff.max!=nil&&len(v) >int(*f.max) {
returnerrMaximum
}
iff.min!=nil&&len(v) <int(*f.min) {
returnerrMinimum
}
// TODO: This would be a new checkif!f.pattern.MatchString(v) {
returnerrPattern
}
...// Pattern specifies a regex pattern value for this fieldfunc (fField) Pattern(patternstring) Field {
f.pattern=regexp.MustCompile(pattern)
returnf
}
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
Currently there is no way to enforce a pattern on a string field similar to the pattern regex field in the Swagger 2.0 spec.
Describe the solution you'd like
String fields could use a new
.Pattern()
to supply a regex and enforce a pattern on string fields. I think fields of other types would just ignore this helper?This could look something like the following (I didn't show it below, but could also add Pattern to the Parameter/JsonSchema structs so that field also gets included in the swagger):
Let me know what you think. If you accept PRs, I could also try to put something together after the holiday week.
The text was updated successfully, but these errors were encountered: