Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openapi-framework: fixed windows path names #871

Open
rossi-p opened this issue May 24, 2023 · 4 comments
Open

openapi-framework: fixed windows path names #871

rossi-p opened this issue May 24, 2023 · 4 comments

Comments

@rossi-p
Copy link

rossi-p commented May 24, 2023

When using express-openapi to generate the Swagger file on windows, the openapi-framework package is generating the paths with backslashes, as shown in the image below.

image

Even though the PR #869 solves part of the problem, the docs are still generated with backslashes.

@renkei
Copy link

renkei commented Jun 1, 2023

I was able to fix this in the package fs-routes in file dist/index.js at line 44:

Change

route: '/' + file.replace(options.indexFileRegExp, '')

to

route: '/' + file.replace(options.indexFileRegExp, '').replace(/\\/g, '/')

Then the entire openapi-framework, express-openapi, etc. packages don't see Windows backslashes anymore. Swagger looks good again.

@renkei
Copy link

renkei commented Jun 2, 2023

I've created a PR #877

@renkei
Copy link

renkei commented Jun 5, 2023

Strange, I've found out that downgrading package glob from 10.x to 7.x also solves the issue.

openapi-framework comes with a "glob": "*" dependency, this installs the latest version 10.x. And in this setup the backslash issue on windows occurs. Now, I've added (beside express-openapi) another npm package to my dependency section. This new dependency depends on "glob": "^7.1.3". Now npm resolves "glob": "*" and "glob": "^7.1.3" to version 7.2.0, the highest version available and allowed by range "*" and "^7.1.3". Now, the backslash issue on Windows is "automatically" solved.

Although it could also be a solution to change "glob": "*" into "glob": "7" in express-openapi to fix the issue, I think it is still a good idea to make fs-routes more solid to also work with latest glob version 10.

@renkei
Copy link

renkei commented Jun 8, 2023

I think, I've found a better solution. Instead of calling replace(/\\/, '/') to get rid of backslashes for routes on Windows, we can use the glob option posix: true that was introduced with glob 10.1.0, this I've found in the glob changelog

Add posix: true option to return / delimited paths, even on Windows.

I've already updated my PR where I've also updated package.json and package-lock.json to request the latest glob version >= 10.2.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants