QueryParams computes a mapped attribute containing the subset of e.Params that describe query parameters.
()
| 165 | // QueryParams computes a mapped attribute containing the subset of e.Params |
| 166 | // that describe query parameters. |
| 167 | func (e *HTTPEndpointExpr) QueryParams() *MappedAttributeExpr { |
| 168 | obj := Object{} |
| 169 | v := &ValidationExpr{} |
| 170 | pp := make(map[string]struct{}) |
| 171 | for _, r := range e.Routes { |
| 172 | for _, p := range r.Params() { |
| 173 | pp[p] = struct{}{} |
| 174 | } |
| 175 | } |
| 176 | pat := e.Params.Attribute() // need "attribute:name" style keys |
| 177 | for _, at := range *(pat.Type.(*Object)) { |
| 178 | found := false |
| 179 | for n := range pp { |
| 180 | if n == at.Name { |
| 181 | found = true |
| 182 | break |
| 183 | } |
| 184 | } |
| 185 | if !found { |
| 186 | obj.Set(at.Name, at.Attribute) |
| 187 | // when looking for required attributes we need the unmapped keys |
| 188 | // (i.e. without the "attribute:name" syntax) |
| 189 | attName := strings.Split(at.Name, ":")[0] |
| 190 | if e.Params.IsRequired(attName) { |
| 191 | v.AddRequired(attName) |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | at := &AttributeExpr{Type: &obj, Validation: v} |
| 196 | return NewMappedAttributeExpr(at) |
| 197 | } |
| 198 | |
| 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. |
no test coverage detected