Skip to content

Commit 92e5e07

Browse files
authored
Merge pull request #1216 from microsoft/vnext
Merges dev into master
2 parents 14ec838 + 2acc209 commit 92e5e07

File tree

6 files changed

+55
-12
lines changed

6 files changed

+55
-12
lines changed

src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<Company>Microsoft</Company>
1111
<Title>Microsoft.OpenApi.Readers</Title>
1212
<PackageId>Microsoft.OpenApi.Readers</PackageId>
13-
<Version>1.6.4-preview2</Version>
13+
<Version>1.6.4-preview3</Version>
1414
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
1515
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
1616
<PackageTags>OpenAPI .NET</PackageTags>

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ private static void MakeServers(IList<OpenApiServer> servers, ParsingContext con
139139
var schemes = context.GetFromTempStorage<List<string>>("schemes");
140140
Uri defaultUrl = rootNode.Context.BaseUrl;
141141

142+
// so we don't default to the document path when a host is provided
143+
if (string.IsNullOrEmpty(basePath) && !string.IsNullOrEmpty(host))
144+
{
145+
basePath = "/";
146+
}
147+
142148
// If nothing is provided, don't create a server
143149
if (host == null && basePath == null && schemes == null)
144150
{

src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFramework>net7.0-windows</TargetFramework>
44
<OutputType>WinExe</OutputType>
@@ -10,7 +10,7 @@
1010
<PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.4.410601">
1111
<PrivateAssets>all</PrivateAssets>
1212
</PackageReference>
13-
<PackageReference Include="Microsoft.Windows.Compatibility" Version="7.0.0" />
13+
<PackageReference Include="Microsoft.Windows.Compatibility" Version="7.0.1" />
1414
</ItemGroup>
1515
<ItemGroup>
1616
<Resource Include="Themes\Metro\HowToApplyTheme.txt" />

src/Microsoft.OpenApi/Helpers/DictionaryCloneHelper.cs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Microsoft.OpenApi.Helpers
99
/// <summary>
1010
/// Helper class for deep cloning dictionaries.
1111
/// </summary>
12-
internal class DictionaryCloneHelper
12+
internal static class DictionaryCloneHelper
1313
{
1414
/// <summary>
1515
/// Deep clone key value pairs in a dictionary.
@@ -21,14 +21,26 @@ internal class DictionaryCloneHelper
2121
internal static Dictionary<T, U> Clone<T, U>(IDictionary<T, U> dictionary)
2222
{
2323
if (dictionary is null) return null;
24+
2425
var clonedDictionary = new Dictionary<T, U>(dictionary.Keys.Count);
26+
var clonedObjects = new Dictionary<object, object>();
2527

26-
foreach (var kvp in dictionary)
28+
foreach (var keyValuePair in dictionary)
2729
{
28-
// Create instance of the specified type using the constructor matching the specified parameter types.
29-
clonedDictionary[kvp.Key] = (U)Activator.CreateInstance(kvp.Value.GetType(), kvp.Value);
30-
}
31-
30+
// If the object has already been cloned, use the cloned object instead of cloning it again
31+
if (clonedObjects.TryGetValue(keyValuePair.Value, out var clonedValue))
32+
{
33+
clonedDictionary[keyValuePair.Key] = (U)clonedValue;
34+
}
35+
else
36+
{
37+
// Create instance of the specified type using the constructor matching the specified parameter types.
38+
clonedDictionary[keyValuePair.Key] = (U)Activator.CreateInstance(keyValuePair.Value.GetType(), keyValuePair.Value);
39+
40+
// Add the cloned object to the dictionary of cloned objects
41+
clonedObjects.Add(keyValuePair.Value, clonedDictionary[keyValuePair.Key]);
42+
}
43+
}
3244

3345
return clonedDictionary;
3446
}

src/Microsoft.OpenApi/Microsoft.OpenApi.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<Company>Microsoft</Company>
1212
<Title>Microsoft.OpenApi</Title>
1313
<PackageId>Microsoft.OpenApi</PackageId>
14-
<Version>1.6.4-preview2</Version>
14+
<Version>1.6.4-preview3</Version>
1515
<Description>.NET models with JSON and YAML writers for OpenAPI specification</Description>
1616
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
1717
<PackageTags>OpenAPI .NET</PackageTags>

test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiServerTests.cs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,31 @@ public void JustHostNoDefault()
7474
Assert.Equal("//www.foo.com", server.Url);
7575
}
7676

77+
[Fact]
78+
public void NoBasePath()
79+
{
80+
var input = @"
81+
swagger: 2.0
82+
info:
83+
title: test
84+
version: 1.0.0
85+
host: www.foo.com
86+
schemes:
87+
- http
88+
paths: {}
89+
";
90+
var reader = new OpenApiStringReader(new OpenApiReaderSettings()
91+
{
92+
BaseUrl = new Uri("https://www.foo.com/spec.yaml")
93+
});
94+
95+
var doc = reader.Read(input, out var diagnostic);
96+
97+
var server = doc.Servers.First();
98+
Assert.Equal(1, doc.Servers.Count);
99+
Assert.Equal("http://www.foo.com", server.Url);
100+
}
101+
77102
[Fact]
78103
public void JustBasePathNoDefault()
79104
{
@@ -203,14 +228,14 @@ public void JustHostWithCustomHostWithApi()
203228
";
204229
var reader = new OpenApiStringReader(new OpenApiReaderSettings()
205230
{
206-
BaseUrl = new Uri("https://dev.bing.com/api")
231+
BaseUrl = new Uri("https://dev.bing.com/api/description.yaml")
207232
});
208233

209234
var doc = reader.Read(input, out var diagnostic);
210235

211236
var server = doc.Servers.First();
212237
Assert.Equal(1, doc.Servers.Count);
213-
Assert.Equal("https://prod.bing.com/api", server.Url);
238+
Assert.Equal("https://prod.bing.com", server.Url);
214239
}
215240

216241
[Fact]

0 commit comments

Comments
 (0)