From 1056d470f1da98be027240e9e66064baff51deb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20St=C3=A1rek?= Date: Thu, 21 Nov 2019 15:35:44 +0100 Subject: [PATCH 1/2] Adding base path --- parser/Parser/EndpointParser.cs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/parser/Parser/EndpointParser.cs b/parser/Parser/EndpointParser.cs index fe1da0d..ee6d032 100644 --- a/parser/Parser/EndpointParser.cs +++ b/parser/Parser/EndpointParser.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Linq; using Microsoft.OpenApi.Models; using Models; @@ -12,19 +14,33 @@ namespace Parser foreach (var path in openApiDocument.Paths) { - endpoints.Add(ParseEndpoint(path)); + endpoints.Add(ParseEndpoint(path, GetBasePath(openApiDocument))); } return endpoints; } - static Endpoint ParseEndpoint(KeyValuePair path) + static Endpoint ParseEndpoint(KeyValuePair path, string basePath) { - Endpoint endpoint = new Endpoint(path.Key); + Endpoint endpoint = new Endpoint(basePath + path.Key); foreach (KeyValuePair operation in path.Value.Operations) { endpoint.Requests.Add(RequestParser.ParseRequest(operation)); } return endpoint; } + + static string GetBasePath(OpenApiDocument openApiDocument) + { + string basePath = string.Empty; + if (openApiDocument.Servers.Any()) + { + basePath = new Uri(openApiDocument.Servers.First().Url).AbsolutePath; + } + + if (basePath == "/") + basePath = string.Empty; + + return basePath; + } } } From be5122bf86250142c2c8d59b56dc9e0f812c8a00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20St=C3=A1rek?= Date: Thu, 21 Nov 2019 16:56:50 +0100 Subject: [PATCH 2/2] Fixed E2E tests --- tests/documentation.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/documentation.yaml b/tests/documentation.yaml index cb3cb75..864c5f5 100644 --- a/tests/documentation.yaml +++ b/tests/documentation.yaml @@ -5,7 +5,7 @@ info: license: name: MIT servers: - - url: http://petstore.swagger.io/v1 + - url: http://petstore.swagger.io paths: /pets?attributeName={attributeValue}: get: