Sample code for express-openapi is giving TypeError: url_1.URL is not a function
Hi,
I am trying to run https://github.com/kogosoftwarellc/open-api/tree/master/packages/express-openapi#getting-started code but it is giving below error: `/node_modules/openapi-framework/dist/src/BasePath.js:10 var serverUrl = url_1.URL(server.url, 'http://localhost'); ^
TypeError: url_1.URL is not a function
at new BasePath (/node_modules/openapi-framework/src/BasePath.ts:10:19)
at new OpenAPIFramework (node_modules/openapi-framework/index.ts:141:11)
at initialize (/node_modules/express-openapi/index.ts:80:21)
at Object.
When I further investigated inside node_modules/openapi-framework/dist/src/BasePath.js , I found that the url module really doesn't have any URL function, so if I change
var serverUrl = new url_1.URL(server.url, 'http://localhost');
to
var serverUrl = new url_1.Url(server.url, 'http://localhost'); // Notice url_1.Url
it works Let me know if you need further assistance to replicate the issue
Thanks
@ashishjain3456 please open a PR to correct the code in the README.
There's a mismatch in the path API. We are using Node v6.16.0 in production, but it doesn't support the new path API. I have to apply this diff before packaging everything up.
--- ./node_modules/openapi-framework/dist/src/BasePath.js 2019-04-03 11:31:43.000000000 -0500
+++ /node_modules/openapi-framework/dist/src/BasePath.js 2019-04-03 16:52:54.122511865 -0500
@@ -7,7 +7,7 @@
this.path = '';
// break the url into parts
// baseUrl param added to make the parsing of relative paths go well
- var serverUrl = new url_1.URL(server.url, 'http://localhost');
+ var serverUrl = url_1.parse(`http://localhost${server.url}`);
var urlPath = decodeURI(serverUrl.pathname).replace(/\/$/, '');
if (/{\w+}/.test(urlPath)) {
// has variable that we need to check out
@@ -26,4 +26,4 @@
return BasePath;
}());
exports["default"] = BasePath;
-//# sourceMappingURL=BasePath.js.map
\ No newline at end of file
+//# sourceMappingURL=BasePath.js.map