You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The useRequestUrl option implemented #857 has a bug in that when set to true, schemas with query parameters defined will cause the validator to fail to find the route where the parameters are defined. The root cause seems to be within the openapi.metadata.xx file, in the lookupRoute function. See exerp below:
functionlookupRoute(req,useRequestUrl){constpath=useRequestUrl ? req.url : req.originalUrl.split('?')[0];////////// Bug here// .. snip ..constregexp=(0,path_to_regexp_1.pathToRegexp)(expressRoute,keys,pathOpts);constmatchedRoute=regexp.exec(path);if(matchedRoute){// Need to get here to successfully validate the route}}
Note the the code compares the path against a regex, and that regex ASUMES there is no ?parameters at the end of the path. When useRequestUrl is false, the ?parameters are stripped via: req.originalUrl.split('?')[0],
However when useRequestUrl is true, it uses req.url which does NOT strip the ?parameters, failing the regex checks.
I confirmed this by console logging the variables:
useRequestUrl: false => /some/path/here
useRequestUrl: true => /some/path/here?interval=600
And the comparing Regex: /^/some/path/here[/#?]?$/i
The solution I believe is updating the path declaration:
Describe the bug
The
useRequestUrl
option implemented #857 has a bug in that when set to true, schemas with query parameters defined will cause the validator to fail to find the route where the parameters are defined. The root cause seems to be within theopenapi.metadata.xx
file, in thelookupRoute
function. See exerp below:Note the the code compares the
path
against a regex, and that regex ASUMES there is no ?parameters at the end of the path. WhenuseRequestUrl
is false, the ?parameters are stripped via:req.originalUrl.split('?')[0]
,However when
useRequestUrl
is true, it usesreq.url
which does NOT strip the ?parameters, failing the regex checks.I confirmed this by console logging the variables:
useRequestUrl: false => /some/path/here
useRequestUrl: true => /some/path/here?interval=600
And the comparing Regex: /^/some/path/here[/#?]?$/i
The solution I believe is updating the path declaration:
To Reproduce
Actual behavior
Expected behavior
The requests is validated / accepted and not erroneously blocked with a "Not Found" error.
Examples and context
An example or relevant context e.g. an OpenAPI snippet, an Express handler function snippet
The text was updated successfully, but these errors were encountered: