Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/dist/
/bin/
.worktrees/
*.out
.DS_Store

Expand Down
14 changes: 14 additions & 0 deletions applications.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

101 changes: 101 additions & 0 deletions incidents.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions integrations.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/cmd/gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (g *Gen) collectServices(paths map[string]any) []service {
for _, e := range entries {
opIDs = append(opIDs, str(e.op, "operationId"))
}
names := methodNames(opIDs)
names := methodNames(tag, opIDs)

svc := service{Name: serviceName(tag), Tag: tag}
for _, e := range entries {
Expand Down
24 changes: 22 additions & 2 deletions internal/cmd/gen/naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,14 @@ func commonPrefixLen(opTokens [][]string) int {
}
}

var methodPrefixByTag = map[string][]string{
"On-call/Incidents": {"incident"},
"On-call/Integrations": {"webhook", "history"},
}

// methodNames computes a unique Go method name for each operationId within a
// service by stripping the shared leading resource tokens, then deduping.
func methodNames(opIDs []string) map[string]string {
// service by stripping stable service-specific leading tokens, then deduping.
func methodNames(tag string, opIDs []string) map[string]string {
opTokens := make([][]string, len(opIDs))
for i, id := range opIDs {
opTokens[i] = tokens(id)
Expand All @@ -133,6 +138,9 @@ func methodNames(opIDs []string) map[string]string {
used := make(map[string]int)
for i, id := range opIDs {
toks := opTokens[i][n:]
if prefix, ok := methodPrefixByTag[tag]; ok && hasTokenPrefix(opTokens[i], prefix) {
toks = opTokens[i][len(prefix):]
}
if len(toks) == 0 {
toks = opTokens[i]
}
Expand All @@ -155,6 +163,18 @@ func methodNames(opIDs []string) map[string]string {
return result
}

func hasTokenPrefix(toks, prefix []string) bool {
if len(toks) <= len(prefix) {
return false
}
for i, p := range prefix {
if strings.ToLower(toks[i]) != p {
return false
}
}
return true
}

func itoa(n int) string {
if n == 0 {
return "0"
Expand Down
Loading