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

Method Validate

expr/server.go:135–168  ·  view source on GitHub ↗

Validate validates the host.

()

Source from the content-addressed store, hash-verified

133
134// Validate validates the host.
135func (h *HostExpr) Validate() error {
136 verr := new(eval.ValidationErrors)
137 if len(h.URIs) == 0 {
138 verr.Add(h, "host must define at least one URI")
139 }
140 for _, u := range h.URIs {
141 vu := uriVariableRegex.ReplaceAllString(string(u), "/w")
142 pu, err := url.Parse(vu)
143 if err != nil {
144 verr.Add(h, "malformed URI %q", u)
145 continue
146 }
147 if pu.Scheme == "" {
148 verr.Add(h, "missing scheme for URI %q, scheme must be one of 'http', 'https', 'grpc' or 'grpcs'", u)
149 } else if _, ok := validSchemes[pu.Scheme]; !ok {
150 verr.Add(h, "invalid scheme for URI %q, scheme must be one of 'http', 'https', 'grpc' or 'grpcs'", u)
151 }
152 }
153 if h.Variables != nil {
154 for _, v := range *(h.Variables.Type.(*Object)) {
155 if !IsPrimitive(v.Attribute.Type) {
156 verr.Add(h, "invalid type for URI variable %q: type must be a primitive", v.Name)
157 }
158 if v.Attribute.Validation == nil {
159 if v.Attribute.DefaultValue == nil {
160 verr.Add(h, "URI variable %q must have a default value or an enum validation", v.Name)
161 }
162 } else if v.Attribute.DefaultValue == nil && len(v.Attribute.Validation.Values) == 0 {
163 verr.Add(h, "URI variable %q must have a default value or an enum validation", v.Name)
164 }
165 }
166 }
167 return verr
168}
169
170// Finalize makes sure Variables is set.
171func (h *HostExpr) Finalize() {

Callers 1

TestHostExprValidateFunction · 0.95

Calls 2

IsPrimitiveFunction · 0.85
AddMethod · 0.80

Tested by 1

TestHostExprValidateFunction · 0.76