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

Method extractPathParams

http/codegen/service_data.go:2428–2496  ·  view source on GitHub ↗
(a *expr.MappedAttributeExpr, service *expr.AttributeExpr, scope *codegen.NameScope)

Source from the content-addressed store, hash-verified

2426}
2427
2428func (sds *ServicesData) extractPathParams(a *expr.MappedAttributeExpr, service *expr.AttributeExpr, scope *codegen.NameScope) []*ParamData {
2429 var params []*ParamData
2430 codegen.WalkMappedAttr(a, func(name, elem string, _ bool, c *expr.AttributeExpr) error { // nolint: errcheck
2431 // The StringSlice field of ParamData must be false for aliased primitive types
2432 var stringSlice bool
2433 if arr := expr.AsArray(c.Type); arr != nil {
2434 stringSlice = arr.ElemType.Type.Kind() == expr.StringKind
2435 }
2436
2437 c = makeHTTPType(c)
2438 var (
2439 varn = scope.Name(codegen.Goify(name, false))
2440 arr = expr.AsArray(c.Type)
2441 ctx = serviceContext("", scope)
2442 ft = service.Type
2443
2444 fptr bool
2445 )
2446 fieldName := codegen.GoifyAtt(c, name, true)
2447 if !expr.IsObject(service.Type) {
2448 fieldName = ""
2449 } else {
2450 fptr = service.IsPrimitivePointer(name, true)
2451 ft = service.Find(name).Type
2452 }
2453 validate := codegen.AttributeValidationCode(c, nil, ctx, true, expr.IsAlias(c.Type), varn, name)
2454 if isStringMetaType(c) {
2455 // Build a copy of the attribute with Format cleared so the shared
2456 // validation code does not emit a format check (UnmarshalText covers it).
2457 cNoFmt := *c
2458 if c.Validation != nil {
2459 v := *c.Validation
2460 v.Format = ""
2461 cNoFmt.Validation = &v
2462 }
2463 validate = codegen.AttributeValidationCode(&cNoFmt, nil, ctx, true, expr.IsAlias(c.Type), varn+"Raw", name)
2464 }
2465 params = append(params, &ParamData{
2466 Map: false,
2467 MapStringSlice: false,
2468 Element: &Element{
2469 HTTPName: elem,
2470 AttributeName: name,
2471 Slice: arr != nil,
2472 StringSlice: stringSlice,
2473 AttributeData: &AttributeData{
2474 Name: name,
2475 Description: c.Description,
2476 FieldName: fieldName,
2477 FieldPointer: fptr,
2478 FieldType: ft,
2479 VarName: varn,
2480 Required: true,
2481 Type: c.Type,
2482 TypeName: scope.GoTypeName(c),
2483 TypeRef: scope.GoTypeRef(c),
2484 Pointer: false,
2485 Validate: validate,

Callers 1

buildPayloadDataMethod · 0.95

Calls 15

WalkMappedAttrFunction · 0.92
AsArrayFunction · 0.92
GoifyFunction · 0.92
GoifyAttFunction · 0.92
IsObjectFunction · 0.92
AttributeValidationCodeFunction · 0.92
IsAliasFunction · 0.92
makeHTTPTypeFunction · 0.85
serviceContextFunction · 0.85
isStringMetaTypeFunction · 0.85
FindMethod · 0.80
GoTypeNameMethod · 0.80

Tested by

no test coverage detected