Skip to content

Commit 8a76184

Browse files
committed
PR review fixes
1 parent 58c4c36 commit 8a76184

File tree

2 files changed

+9
-27
lines changed

2 files changed

+9
-27
lines changed

src/Microsoft.OpenApi.Readers/V2/OpenApiDocumentDeserializer.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ private static void MakeServers(IList<OpenApiServer> servers, ParsingContext con
137137
host = host ?? defaultUrl.GetComponents(UriComponents.NormalizedHost, UriFormat.SafeUnescaped);
138138
basePath = basePath ?? defaultUrl.GetComponents(UriComponents.Path, UriFormat.SafeUnescaped);
139139
schemes = schemes ?? new List<string> { defaultUrl.GetComponents(UriComponents.Scheme, UriFormat.SafeUnescaped) };
140-
} else if (String.IsNullOrEmpty(host) && String.IsNullOrEmpty(basePath))
140+
}
141+
else if (String.IsNullOrEmpty(host) && String.IsNullOrEmpty(basePath))
141142
{
142143
return; // Can't make a server object out of just a Scheme
143144
}
@@ -147,6 +148,11 @@ private static void MakeServers(IList<OpenApiServer> servers, ParsingContext con
147148
{
148149
foreach (var scheme in schemes)
149150
{
151+
if (String.IsNullOrEmpty(scheme))
152+
{
153+
host = "//" + host; // The double slash prefix creates a relative url where the scheme is defined by the BaseUrl
154+
}
155+
150156
var uriBuilder = new UriBuilder(scheme, host)
151157
{
152158
Path = basePath
@@ -164,7 +170,7 @@ private static void MakeServers(IList<OpenApiServer> servers, ParsingContext con
164170
{
165171
if (!String.IsNullOrEmpty(host))
166172
{
167-
host = "//" + host;
173+
host = "//" + host; // The double slash prefix creates a relative url where the scheme is defined by the BaseUrl
168174
}
169175
var uriBuilder = new UriBuilder()
170176
{

src/Microsoft.OpenApi/Extensions/OpenApiSerializableExtensions.cs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -123,31 +123,7 @@ public static void Serialize<T>(this T element, IOpenApiWriter writer, OpenApiSp
123123
public static void Serialize<T>(this T element, IOpenApiWriter writer)
124124
where T : IOpenApiSerializable
125125
{
126-
if (element == null)
127-
{
128-
throw Error.ArgumentNull(nameof(element));
129-
}
130-
131-
if (writer == null)
132-
{
133-
throw Error.ArgumentNull(nameof(writer));
134-
}
135-
136-
switch (writer.Settings.SpecVersion)
137-
{
138-
case OpenApiSpecVersion.OpenApi3_0:
139-
element.SerializeAsV3(writer);
140-
break;
141-
142-
case OpenApiSpecVersion.OpenApi2_0:
143-
element.SerializeAsV2(writer);
144-
break;
145-
146-
default:
147-
throw new OpenApiException(string.Format(SRResource.OpenApiSpecVersionNotSupported, writer.Settings.SpecVersion));
148-
}
149-
150-
writer.Flush();
126+
element.Serialize(writer, writer.Settings.SpecVersion);
151127
}
152128

153129
/// <summary>

0 commit comments

Comments
 (0)