From 27fc8b0bad3829c4109a403be88d710ffd2d0d89 Mon Sep 17 00:00:00 2001 From: Richard Carson Derr Date: Sun, 29 Sep 2024 18:59:00 -0400 Subject: [PATCH] fix(issue-293): remove ... wildcard before registering open api operation --- rest/rest.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/rest/rest.go b/rest/rest.go index fc8ea9d..a818c08 100644 --- a/rest/rest.go +++ b/rest/rest.go @@ -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