Skip to content

Commit

Permalink
fix: generate operation ID if not present, fixes #201
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgtaylor committed Aug 4, 2023
1 parent c47eb00 commit 04a021c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
5 changes: 4 additions & 1 deletion openapi/openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,12 @@ func openapiOperation(cmd *cobra.Command, method string, uriTemplate *url.URL, p
aliases := getExtSlice(op.Extensions, ExtAliases, []string{})

name := casing.Kebab(op.OperationId)
if name == "" {
name = casing.Kebab(method + "-" + strings.Trim(uriTemplate.Path, "/"))
}
if override := getExt(op.Extensions, ExtName, ""); override != "" {
name = override
} else if oldName := slug.Make(op.OperationId); oldName != name {
} else if oldName := slug.Make(op.OperationId); oldName != "" && oldName != name {
// For backward-compatibility, add the old naming scheme as an alias
// if it is different. See https://github.com/danielgtaylor/restish/issues/29
// for additional context; we prefer kebab casing for readability.
Expand Down
1 change: 0 additions & 1 deletion openapi/testdata/request/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ paths:
foo:
type: string
delete:
operationId: delete-item
responses:
"204":
description: ""
2 changes: 1 addition & 1 deletion openapi/testdata/request/output.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
short: Test API
operations:
- name: delete-item
- name: delete-items-item-id
aliases: []
short: ""
long: |
Expand Down

0 comments on commit 04a021c

Please sign in to comment.