Skip to content

Commit

Permalink
fix(issue-293): remove ... wildcard before registering open api opera…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
Zaba505 committed Sep 29, 2024
1 parent ebc5549 commit 27fc8b0
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,15 @@ func (app *App) registerEndpoints(mux *http.ServeMux) error {
// the {$} needs to be stripped because OpenAPI will believe it's
// an actual path parameter.
trimmedPattern := strings.TrimSuffix(e.pattern, "{$}")

// Per the net/http.ServeMux docs, https://pkg.go.dev/net/http#ServeMux:
//
// A path can include wildcard segments of the form {NAME} or {NAME...}.
//
// The '...' wildcard has no equivalent in OpenAPI so we must remove it
// before registering the OpenAPI operation with the spec.
trimmedPattern = strings.ReplaceAll(trimmedPattern, "...", "")

err := app.spec.AddOperation(e.method, trimmedPattern, e.op.OpenApi())
if err != nil {
return err
Expand Down

0 comments on commit 27fc8b0

Please sign in to comment.