Skip to content

Commit

Permalink
Fixes #17
Browse files Browse the repository at this point in the history
Parameters should be unscaped before being sent for validation.
gorillamux returns escaped parameters, but openapi3filter expects
unescaped parameters.
  • Loading branch information
florentchauveau committed Jan 5, 2025
1 parent 58055c3 commit 9f0f858
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions oapi_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"fmt"
"log"
"net/http"
"net/url"
"os"
"strings"

Expand Down Expand Up @@ -128,6 +129,14 @@ func ValidateRequestFromContext(ctx echo.Context, router routers.Router, options
}
}

// because gorillamux.NewRouter() uses mux.NewRouter().UseEncodedPath()
// we need to unescape the path parameters for openapi3filter
for k, v := range pathParams {
if v, err := url.PathUnescape(v); err == nil {
pathParams[k] = v
}
}

validationInput := &openapi3filter.RequestValidationInput{
Request: req,
PathParams: pathParams,
Expand Down

0 comments on commit 9f0f858

Please sign in to comment.