Prepare computes the request path and query string parameters as well as the headers and body taking into account the inherited values from the service.
()
| 199 | // Prepare computes the request path and query string parameters as well as the |
| 200 | // headers and body taking into account the inherited values from the service. |
| 201 | func (e *HTTPEndpointExpr) Prepare() { |
| 202 | // Avoid infinite recursions when traversing parents. |
| 203 | if e.prepared { |
| 204 | return |
| 205 | } |
| 206 | e.prepared = true |
| 207 | if e.Headers == nil { |
| 208 | e.Headers = NewEmptyMappedAttributeExpr() |
| 209 | } |
| 210 | if e.Cookies == nil { |
| 211 | e.Cookies = NewEmptyMappedAttributeExpr() |
| 212 | } |
| 213 | if e.Params == nil { |
| 214 | e.Params = NewEmptyMappedAttributeExpr() |
| 215 | } |
| 216 | |
| 217 | // Inherit headers, cookies and params from parent service and API |
| 218 | headers := NewEmptyMappedAttributeExpr() |
| 219 | headers.Merge(Root.API.HTTP.Headers) |
| 220 | headers.Merge(e.Service.Headers) |
| 221 | |
| 222 | cookies := NewEmptyMappedAttributeExpr() |
| 223 | cookies.Merge(Root.API.HTTP.Cookies) |
| 224 | cookies.Merge(e.Service.Cookies) |
| 225 | |
| 226 | params := NewEmptyMappedAttributeExpr() |
| 227 | params.Merge(Root.API.HTTP.Params) |
| 228 | params.Merge(e.Service.Params) |
| 229 | |
| 230 | if p := e.Service.Parent(); p != nil { |
| 231 | if c := p.CanonicalEndpoint(); c != nil { |
| 232 | c.Prepare() |
| 233 | if !e.HasAbsoluteRoutes() { |
| 234 | headers.Merge(c.Headers) |
| 235 | cookies.Merge(c.Cookies) |
| 236 | cpp := c.PathParams() |
| 237 | params.Merge(cpp) |
| 238 | |
| 239 | // Inherit attributes for path params from parent service |
| 240 | WalkMappedAttr(cpp, func(name, _ string, _ *AttributeExpr) error { // nolint: errcheck |
| 241 | if att := c.MethodExpr.Payload.Find(name); att != nil { |
| 242 | if e.MethodExpr.Payload.Type == Empty { |
| 243 | e.MethodExpr.Payload.Type = &Object{} |
| 244 | } |
| 245 | if o := AsObject(e.MethodExpr.Payload.Type); o != nil && o.Attribute(name) == nil { |
| 246 | if c.MethodExpr.Payload.IsRequired(name) { |
| 247 | if e.MethodExpr.Payload.Validation == nil { |
| 248 | e.MethodExpr.Payload.Validation = &ValidationExpr{} |
| 249 | } |
| 250 | e.MethodExpr.Payload.Validation.AddRequired(name) |
| 251 | } |
| 252 | o.Set(name, att) |
| 253 | } |
| 254 | } |
| 255 | return nil |
| 256 | }) |
| 257 | } |
| 258 | } |
nothing calls this directly
no test coverage detected