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
10 changes: 10 additions & 0 deletions codegen/examples/overdub.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"GET /v3/overdubs":
- "heygen overdub list --limit 10"
"POST /v3/overdubs":
- "cat request.json | heygen overdub create -d -"
"GET /v3/overdubs/{overdub_id}":
- "heygen overdub get <overdub-id>"
"PATCH /v3/overdubs/{overdub_id}":
- "heygen overdub update <overdub-id> --title 'Updated title'"
"DELETE /v3/overdubs/{overdub_id}":
- "heygen overdub delete <overdub-id>"
11 changes: 9 additions & 2 deletions codegen/grouper.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,14 @@ func deriveCommandName(method string, subGroups, allRemaining []string, op *open
return strings.Join(subGroups, " ")
}

verb := terminalVerb(method, allRemaining)
verb := terminalVerb(method, allRemaining, op)
if len(subGroups) == 0 {
return verb
}
return strings.Join(subGroups, " ") + " " + verb
}

func terminalVerb(method string, remaining []string) string {
func terminalVerb(method string, remaining []string, op *openapi3.Operation) string {
hasParam := slices.ContainsFunc(remaining, func(s string) bool {
return strings.HasPrefix(s, "{")
})
Expand All @@ -253,6 +253,13 @@ func terminalVerb(method string, remaining []string) string {
if hasParam {
return "get"
}
// Singleton GET endpoints (e.g., GET /v3/user/me with summary "Get current user info")
// are "get" not "list". We detect this from the summary because the URL structure
// alone can't distinguish a singleton from a collection when there's no {param}.
// This is the one heuristic in the naming algorithm — everything else is structural.
if strings.HasPrefix(strings.ToLower(op.Summary), "get ") {
return "get"
}
return "list"
case "POST":
return "create"
Expand Down
15 changes: 15 additions & 0 deletions codegen/grouper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,18 @@ func TestGroupEndpoints_SubGroupNaming(t *testing.T) {
}
t.Error("video 'caption get' not found")
}

func TestGroupEndpoints_SingletonGetUsesGetVerb(t *testing.T) {
doc := loadGroupTestSpec(t)
examples := loadTestExamples(t)
groups, err := GroupEndpoints(doc, examples)
if err != nil {
t.Fatalf("GroupEndpoints: %v", err)
}
for _, s := range groups["user"] {
if s.Name == "me get" {
return
}
}
t.Error("user 'me get' not found")
}
2 changes: 2 additions & 0 deletions codegen/testdata/test_examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@
- "heygen avatar get <group-id>"
"POST /v3/avatars/{group_id}/consent":
- "heygen avatar consent <group-id>"
"GET /v3/user/me":
- "heygen user me get"
16 changes: 16 additions & 0 deletions codegen/testdata/test_spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,22 @@ paths:
"200":
description: OK

/v3/user/me:
get:
tags: [User]
summary: Get current user info
description: Returns the authenticated user's profile.
responses:
"200":
description: OK
content:
application/json:
schema:
type: object
properties:
data:
type: object

/v1/legacy:
get:
tags: [Legacy]
Expand Down
33 changes: 33 additions & 0 deletions gen/asset.go

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

200 changes: 200 additions & 0 deletions gen/avatar.go

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

Loading
Loading