From 0ff5930800e21f9776c30dfad5c78d3173232b1b Mon Sep 17 00:00:00 2001 From: Afonso Jorge Ramos Date: Thu, 26 Oct 2023 16:25:01 +0100 Subject: [PATCH] fix: check for empty servers array --- openapi-to-har.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openapi-to-har.js b/openapi-to-har.js index 2d9daf2..c4d91ef 100644 --- a/openapi-to-har.js +++ b/openapi-to-har.js @@ -407,10 +407,10 @@ const getPayloads = function (openApi, path, method) { * @return {string} Base URL */ const getBaseUrl = function (openApi, path, method) { - if (openApi.paths[path][method].servers) + if (openApi.paths[path][method].servers && openApi.paths[path][method].servers.length > 0) return openApi.paths[path][method].servers[0].url; - if (openApi.paths[path].servers) return openApi.paths[path].servers[0].url; - if (openApi.servers) return openApi.servers[0].url; + if (openApi.paths[path].servers && openApi.paths[path].servers.length > 0) return openApi.paths[path].servers[0].url; + if (openApi.servers && openApi.servers.length > 0) return openApi.servers[0].url; let baseUrl = ''; if (typeof openApi.schemes !== 'undefined') {