From bdbb2e5e4c1e27ee2f815d8881f6ece3c06ab5ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20St=C3=A1rek?= Date: Sun, 24 Nov 2019 02:51:11 +0100 Subject: [PATCH] Handle URI parsing exception --- parser/Parser/EndpointParser.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/parser/Parser/EndpointParser.cs b/parser/Parser/EndpointParser.cs index ee6d032..90efbc4 100644 --- a/parser/Parser/EndpointParser.cs +++ b/parser/Parser/EndpointParser.cs @@ -34,7 +34,7 @@ namespace Parser string basePath = string.Empty; if (openApiDocument.Servers.Any()) { - basePath = new Uri(openApiDocument.Servers.First().Url).AbsolutePath; + basePath = GetUriFromServer(openApiDocument.Servers.First())?.AbsolutePath; } if (basePath == "/") @@ -42,5 +42,17 @@ namespace Parser return basePath; } + + static Uri GetUriFromServer(OpenApiServer server) + { + try + { + return new Uri(server.Url); + } + catch (UriFormatException) + { + return null; + } + } } }