open-api icon indicating copy to clipboard operation
open-api copied to clipboard

Path slash differences with Windows and Linux

Open mcottontensor opened this issue 1 year ago • 3 comments

On trying to get started with express-openapi on a Windows development environment, I got a nasty error about Unmatched ')' in a regular expression. Trying to hunt it down led me to fs-routes where files are being resolved. Using path.resolve on Windows resolves paths with back slashes and on Linux, forward slashes. Code further down the line seems to assume all path separators are forward slashes. This means that some of the generated routes will become invalid and lead to broken code. I changed the end of the fsRoutes() function to look like

.map(function (file) { return ({
            path: path.resolve(dir, file).replace(/\\/g, '/'),
            route: '/' + file.replace(options.indexFileRegExp, '').replace(/\\/g, '/')
        }); });

as a test and that fixed the issues I was having.

Is there a better way of handling this? I was a little surprised no one else had stumbled across this error so it leads me to believe I'm doing something wrong.

mcottontensor avatar Feb 19 '24 00:02 mcottontensor

I've already fixed this with PR877. Unfortunately, there is no maintenance for months by the author of this project... Hopefully this will change again in future...

renkei avatar Mar 22 '24 10:03 renkei

I've been dealing with the same issue for a couple of weeks until I posted on StackOverflow and fortunately, @Narretz pointed me to this channel where finally my suspicion is confirmed. Thnx!!

JPotterH avatar Mar 27 '24 13:03 JPotterH

I wanted to come back to this since I stumbled across the issue again a year later. Rather than altering the code of fs-routes as described in the original post, you can also override glob to v7 since that's where the issue seems to arise. eg. adding the following to the package.json file

    "overrides": {
        "fs-routes": {
            "glob": "7.2.3"
        }
    },

and then making sure the package-lock.json is up to date with

npm install fs-routes

This should override the glob version in the fs-routes package that can be confirmed with

npm list glob

and the issue should be resolved without code changes.

mcottontensor avatar May 14 '25 05:05 mcottontensor