swagger-node-runner icon indicating copy to clipboard operation
swagger-node-runner copied to clipboard

Handle basePath together with express sub-app

Open CallMeLaNN opened this issue 9 years ago • 2 comments

I have this URL format: domain.com/api/resource The baseUrl defined in swagger.yaml is /api The express configured so that the /api is just a sub-app:

app = express();
apiApp = express();
app.use('/api', apiApp);

The swagger middleware is then added into apiApp.

Both swagger definition and express already configured to use the /api basePath, but connect middleware bypass it by calling next() because the runner.getPath return undefined.

Note the api.getPath, the pathOrReq.url here is returning only the sub path. In this case the pathOrReq.url = '/resource' instead of '/api/resource'. Therefore the regexp and isArray return false.

I suggest we fix this by calling api.getPath(req.originalUrl) either in runner or connect middleware since originalUrl contain the full path.

Refer to this also https://github.com/apigee-127/sway/issues/81

CallMeLaNN avatar May 16 '16 17:05 CallMeLaNN

@theganyo what do you think about this? If you feel ok, let me know if I can do it, run npm run test and send PR.

CallMeLaNN avatar May 21 '16 04:05 CallMeLaNN

It seems reasonable to me as long as it's completely backward compatible. Do you see any potential issues there? Thanks!

theganyo avatar Jun 02 '16 03:06 theganyo