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

Method QueryParams

expr/http_endpoint.go:167–197  ·  view source on GitHub ↗

QueryParams computes a mapped attribute containing the subset of e.Params that describe query parameters.

()

Source from the content-addressed store, hash-verified

165// QueryParams computes a mapped attribute containing the subset of e.Params
166// that describe query parameters.
167func (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.

Callers 4

validateParamsMethod · 0.95
buildPayloadDataMethod · 0.80
buildResponsesMethod · 0.80
buildErrorsDataMethod · 0.80

Calls 6

SetMethod · 0.95
AddRequiredMethod · 0.95
NewMappedAttributeExprFunction · 0.85
IsRequiredMethod · 0.80
AttributeMethod · 0.65
ParamsMethod · 0.45

Tested by

no test coverage detected