(template, service, method string, routeIndex int)
| 445 | } |
| 446 | |
| 447 | func 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. |
no outgoing calls
no test coverage detected