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

Method buildPayloadData

http/codegen/service_data.go:1075–1517  ·  view source on GitHub ↗

buildPayloadData returns the data structure used to describe the endpoint payload including the HTTP request details. It also returns the user types used by the request body type recursively if any.

(e *expr.HTTPEndpointExpr, sd *ServiceData)

Source from the content-addressed store, hash-verified

1073// payload including the HTTP request details. It also returns the user types
1074// used by the request body type recursively if any.
1075func (sds *ServicesData) buildPayloadData(e *expr.HTTPEndpointExpr, sd *ServiceData) *PayloadData {
1076 e.Body = makeHTTPType(e.Body)
1077 var (
1078 payload = e.MethodExpr.Payload
1079 svc = sd.Service
1080 body = e.Body.Type
1081 ep = svc.Method(e.MethodExpr.Name)
1082 httpsvrctx = httpContext(sd.Scope, true, true)
1083 httpclictx = httpContext(sd.Scope, true, false)
1084 pkg = pkgWithDefault(ep.PayloadLoc, svc.PkgName)
1085 svcctx = serviceContext(pkg, sd.Service.Scope)
1086
1087 request *RequestData
1088 mapQueryParam *ParamData
1089 )
1090 {
1091 var (
1092 serverBodyData = sds.buildRequestBodyType(e.Body, payload, e, true, sd)
1093 clientBodyData = sds.buildRequestBodyType(e.Body, payload, e, false, sd)
1094 paramsData = sds.extractPathParams(e.PathParams(), payload, sd.Scope)
1095 queryData = sds.extractQueryParams(e.QueryParams(), payload, sd.Scope)
1096 headersData = sds.extractHeaders(e.Headers, payload, svcctx, sd.Scope)
1097 cookiesData = sds.extractCookies(e.Cookies, payload, svcctx, sd.Scope)
1098 origin string
1099
1100 mustValidate bool
1101 mustHaveBody = true
1102 )
1103 if e.MapQueryParams != nil {
1104 var (
1105 fieldName string
1106 name = "query"
1107 required = true
1108 pAtt = payload
1109 )
1110 if n := *e.MapQueryParams; n != "" {
1111 pAtt = expr.AsObject(payload.Type).Attribute(n)
1112 required = payload.IsRequired(n)
1113 name = n
1114 fieldName = codegen.Goify(name, true)
1115 }
1116 varn := codegen.Goify(name, false)
1117 mapQueryParam = &ParamData{
1118 MapQueryParams: e.MapQueryParams,
1119 Map: expr.AsMap(payload.Type) != nil,
1120 Element: &Element{
1121 HTTPName: name,
1122 AttributeData: &AttributeData{
1123 Name: name,
1124 VarName: varn,
1125 FieldName: fieldName,
1126 FieldType: pAtt.Type,
1127 Required: required,
1128 Type: pAtt.Type,
1129 TypeName: sd.Scope.GoTypeName(pAtt),
1130 TypeRef: sd.Scope.GoTypeRef(pAtt),
1131 Validate: codegen.AttributeValidationCode(pAtt, nil, httpsvrctx, required, expr.IsAlias(pAtt.Type), varn, name),
1132 DefaultValue: pAtt.DefaultValue,

Callers 1

analyzeMethod · 0.95

Calls 15

buildRequestBodyTypeMethod · 0.95
extractPathParamsMethod · 0.95
extractQueryParamsMethod · 0.95
extractHeadersMethod · 0.95
extractCookiesMethod · 0.95
AsObjectFunction · 0.92
GoifyFunction · 0.92
AsMapFunction · 0.92
AttributeValidationCodeFunction · 0.92
IsAliasFunction · 0.92
IsObjectFunction · 0.92
ValidationCodeFunction · 0.92

Tested by

no test coverage detected