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

Function parseOperationIDTemplate

http/codegen/openapi/v3/builder.go:447–472  ·  view source on GitHub ↗
(template, service, method string, routeIndex int)

Source from the content-addressed store, hash-verified

445}
446
447func parseOperationIDTemplate(template, service, method string, routeIndex int) string {
448 // Early return if no replacement is needed for the template.
449 if !strings.Contains(template, "{") && routeIndex == 0 {
450 return template
451 }
452
453 // The template replacer
454 repl := strings.NewReplacer(
455 "{service}", service,
456 "{method}", method,
457 )
458
459 operationID := repl.Replace(template)
460
461 if routeIndex == 0 {
462 return routeIndexReplacementRegExp.ReplaceAllString(operationID, "")
463 }
464
465 // If the routeIndex is greater than 0, we need to add the routeIndex to the operationId.
466 if sep := routeIndexReplacementRegExp.FindStringSubmatch(template); sep != nil {
467 return routeIndexReplacementRegExp.ReplaceAllString(operationID, fmt.Sprintf("%s%d", sep[1], routeIndex))
468 }
469
470 // Fallback in the event that the operationId doesn't contain the routeIndex placeholder.
471 return fmt.Sprintf("%s#%d", operationID, routeIndex)
472}
473
474// buildServers builds the OpenAPI Server objects from the given server
475// expressions.

Callers 2

buildOperationFunction · 0.85
buildFileServerOperationFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected