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

Method buildMethodData

codegen/service/service_data.go:1268–1414  ·  view source on GitHub ↗

buildMethodData creates the data needed to render the given endpoint. It records the user types needed by the service definition in userTypes.

(m *expr.MethodExpr, scope *codegen.NameScope)

Source from the content-addressed store, hash-verified

1266// buildMethodData creates the data needed to render the given endpoint. It
1267// records the user types needed by the service definition in userTypes.
1268func (d *ServicesData) buildMethodData(m *expr.MethodExpr, scope *codegen.NameScope) *MethodData {
1269 var (
1270 vname string
1271 desc string
1272 payloadName string
1273 payloadLoc *codegen.Location
1274 payloadDef string
1275 payloadRef string
1276 payloadDesc string
1277 payloadEx any
1278 rname string
1279 resultLoc *codegen.Location
1280 resultDef string
1281 resultRef string
1282 resultDesc string
1283 resultEx any
1284 errors []*ErrorInitData
1285 errorLocs map[string]*codegen.Location
1286 isJSONRPC bool
1287 reqs = make(RequirementsData, 0, len(m.Requirements))
1288 schemes SchemesData
1289 )
1290 vname = scope.Unique(codegen.Goify(m.Name, true), "Endpoint")
1291 desc = m.Description
1292 if desc == "" {
1293 desc = codegen.Goify(m.Name, true) + " implements " + m.Name + "."
1294 }
1295 if m.Payload.Type != expr.Empty {
1296 payloadName = scope.GoTypeName(m.Payload)
1297 if dt, ok := m.Payload.Type.(expr.UserType); ok {
1298 payloadDef = scope.GoTypeDef(dt.Attribute(), false, true)
1299 payloadLoc = codegen.UserTypeLocation(dt)
1300 }
1301 payloadRef = scope.GoFullTypeRef(m.Payload, payloadLoc.PackageName())
1302 payloadDesc = m.Payload.Description
1303 if payloadDesc == "" {
1304 payloadDesc = fmt.Sprintf("%s is the payload type of the %s service %s method.",
1305 payloadName, m.Service.Name, m.Name)
1306 }
1307 payloadEx = m.Payload.Example(d.Root.API.ExampleGenerator)
1308 }
1309 if m.Result.Type != expr.Empty {
1310 rname = scope.GoTypeName(m.Result)
1311 if dt, ok := m.Result.Type.(expr.UserType); ok {
1312 resultDef = scope.GoTypeDef(dt.Attribute(), false, true)
1313 resultLoc = codegen.UserTypeLocation(dt)
1314 }
1315 resultRef = scope.GoFullTypeRef(m.Result, resultLoc.PackageName())
1316 resultDesc = m.Result.Description
1317 if resultDesc == "" {
1318 resultDesc = fmt.Sprintf("%s is the result type of the %s service %s method.",
1319 rname, m.Service.Name, m.Name)
1320 }
1321 resultEx = m.Result.Example(d.Root.API.ExampleGenerator)
1322 }
1323 if len(m.Errors) > 0 {
1324 errors = make([]*ErrorInitData, len(m.Errors))
1325 errorLocs = make(map[string]*codegen.Location, len(m.Errors))

Callers 1

analyzeMethod · 0.95

Calls 15

AppendMethod · 0.95
EndpointMethod · 0.95
initStreamDataMethod · 0.95
GoifyFunction · 0.92
UserTypeLocationFunction · 0.92
buildErrorInitDataFunction · 0.85
BuildSchemeDataFunction · 0.85
UniqueMethod · 0.80
GoTypeNameMethod · 0.80
GoTypeDefMethod · 0.80
GoFullTypeRefMethod · 0.80

Tested by

no test coverage detected