Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Rename Microsoft.OpenApi.Readers to Microsoft.OpenApi.YamlReader #1960

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Microsoft.OpenApi.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.OpenApi.Workbench", "src\Microsoft.OpenApi.Workbench\Microsoft.OpenApi.Workbench.csproj", "{6A5E91E5-0441-46EE-AEB9-8334981B7F08}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.OpenApi.Readers", "src\Microsoft.OpenApi.Readers\Microsoft.OpenApi.Readers.csproj", "{79933258-0126-4382-8755-D50820ECC483}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.OpenApi.YamlReader", "src\Microsoft.OpenApi.YamlReader\Microsoft.OpenApi.YamlReader.csproj", "{79933258-0126-4382-8755-D50820ECC483}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.OpenApi.Tests", "test\Microsoft.OpenApi.Tests\Microsoft.OpenApi.Tests.csproj", "{AD83F991-DBF3-4251-8613-9CC54C826964}"
EndProject
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.OpenApi.Readers\Microsoft.OpenApi.Readers.csproj" />
<ProjectReference Include="..\Microsoft.OpenApi.YamlReader\Microsoft.OpenApi.YamlReader.csproj" />
<ProjectReference Include="..\Microsoft.OpenApi\Microsoft.OpenApi.csproj" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi.Hidi/OpenApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.Readers;
using Microsoft.OpenApi.Services;
using Microsoft.OpenApi.Writers;
using Microsoft.OpenApi.YamlReader;
using static Microsoft.OpenApi.Hidi.OpenApiSpecVersionHelper;

namespace Microsoft.OpenApi.Hidi
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi.Workbench/MainModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.Readers;
using Microsoft.OpenApi.YamlReader;
using Microsoft.OpenApi.Services;
using Microsoft.OpenApi.Validations;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<Resource Include="Themes\Metro\HowToApplyTheme.txt" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Microsoft.OpenApi.Readers\Microsoft.OpenApi.Readers.csproj" />
<ProjectReference Include="..\Microsoft.OpenApi.YamlReader\Microsoft.OpenApi.YamlReader.csproj" />
<ProjectReference Include="..\Microsoft.OpenApi\Microsoft.OpenApi.csproj" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using System.Linq;
using Microsoft.OpenApi.Models;

namespace Microsoft.OpenApi.Readers
namespace Microsoft.OpenApi.YamlReader
{
/// <summary>
/// Reader for parsing YAML files into an OpenAPI document.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using SharpYaml;
using SharpYaml.Serialization;

namespace Microsoft.OpenApi.Reader
namespace Microsoft.OpenApi.YamlReader
{
/// <summary>
/// Provides extensions to convert YAML models to JSON models.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Readers;
using Microsoft.OpenApi.Services;
using Microsoft.OpenApi.Tests.UtilityFiles;
using Moq;
using SharpYaml.Tokens;
using Xunit;

namespace Microsoft.OpenApi.Hidi.Tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.OData;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.Readers;
using Microsoft.OpenApi.Services;
using Microsoft.OpenApi.YamlReader;
using Xunit;

namespace Microsoft.OpenApi.Hidi.Tests
Expand Down Expand Up @@ -335,7 +335,7 @@ public async Task InvokeShowCommandAsync()
var openApi = Path.Combine(".", "UtilityFiles", "SampleOpenApi.yml");
var args = new[] { "show", "-d", openApi, "-o", "sample.md" };
var parseResult = rootCommand.Parse(args);
var handler = rootCommand.Subcommands.Where(c => c.Name == "show").First().Handler;
var handler = rootCommand.Subcommands.First(c => c.Name == "show").Handler;
var context = new InvocationContext(parseResult);

await handler!.InvokeAsync(context);
Expand All @@ -351,7 +351,7 @@ public async Task InvokePluginCommandAsync()
var manifest = Path.Combine(".", "UtilityFiles", "exampleapimanifest.json");
var args = new[] { "plugin", "-m", manifest, "--of", AppDomain.CurrentDomain.BaseDirectory };
var parseResult = rootCommand.Parse(args);
var handler = rootCommand.Subcommands.Where(c => c.Name == "plugin").First().Handler;
var handler = rootCommand.Subcommands.First(c => c.Name == "plugin").Handler;
var context = new InvocationContext(parseResult);

await handler!.InvokeAsync(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.OpenApi.YamlReader\Microsoft.OpenApi.YamlReader.csproj" />
<ProjectReference Include="..\..\src\Microsoft.OpenApi\Microsoft.OpenApi.csproj" />
<ProjectReference Include="..\..\src\Microsoft.OpenApi.Readers\Microsoft.OpenApi.Readers.csproj" />
<ProjectReference Include="..\..\src\Microsoft.OpenApi.YamlReader\Microsoft.OpenApi.YamlReader.csproj" />
<ProjectReference Include="..\Microsoft.OpenApi.Tests\Microsoft.OpenApi.Tests.csproj" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
using System.Threading.Tasks;
using System;
using FluentAssertions;
using Microsoft.OpenApi.Exceptions;
using Microsoft.OpenApi.Models;
using Xunit;
using System.IO;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.YamlReader;

namespace Microsoft.OpenApi.Readers.Tests.OpenApiReaderTests
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Threading.Tasks;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.YamlReader;
using Xunit;

namespace Microsoft.OpenApi.Readers.Tests.OpenApiReaderTests
Expand Down Expand Up @@ -48,7 +49,7 @@ public async Task StreamShouldNotBeDisposedIfLeaveStreamOpenSettingIsTrueAsync()
memoryStream.Position = 0;
var stream = memoryStream;

var result = OpenApiDocument.Load(stream, "yaml", new OpenApiReaderSettings { LeaveStreamOpen = true });
_ = await OpenApiDocument.LoadAsync(stream, "yaml", new OpenApiReaderSettings { LeaveStreamOpen = true });
stream.Seek(0, SeekOrigin.Begin); // does not throw an object disposed exception
Assert.True(stream.CanRead);
}
Expand All @@ -64,7 +65,7 @@ public async Task StreamShouldReadWhenInitializedAsync()
var stream = await httpClient.GetStreamAsync("20fe7a7b720a0e48e5842d002ac418b12a8201df/tests/v3.0/pass/petstore.yaml");

// Read V3 as YAML
var result = OpenApiDocument.Load(stream, "yaml");
var result = await OpenApiDocument.LoadAsync(stream, "yaml");
Assert.NotNull(result.OpenApiDocument);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
using System;
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.YamlReader;
using Xunit;

namespace Microsoft.OpenApi.Readers.Tests.OpenApiWorkspaceTests
{
public class OpenApiWorkspaceStreamTests
{
private const string SampleFolderPath = "V3Tests/Samples/OpenApiWorkspace/";

{
public OpenApiWorkspaceStreamTests()
{
OpenApiReaderRegistry.RegisterReader(OpenApiConstants.Yaml, new OpenApiYamlReader());
Expand Down
2 changes: 1 addition & 1 deletion test/Microsoft.OpenApi.Readers.Tests/ParseNodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Microsoft.OpenApi.Exceptions;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.Readers;
using Microsoft.OpenApi.YamlReader;
using Xunit;

namespace Microsoft.OpenApi.Tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Models.References;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.YamlReader;
using Xunit;

namespace Microsoft.OpenApi.Readers.Tests.ReferenceService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.Writers;
using Microsoft.OpenApi.YamlReader;
using Xunit;

namespace Microsoft.OpenApi.Readers.Tests
Expand Down Expand Up @@ -39,7 +40,6 @@ public void ParseCustomExtension()
};

OpenApiReaderRegistry.RegisterReader("yaml", new OpenApiYamlReader());
var diag = new OpenApiDiagnostic();
var actual = OpenApiDocument.Parse(description, "yaml", settings: settings);

var fooExtension = actual.OpenApiDocument.Info.Extensions["x-foo"] as FooExtension;
Expand Down
6 changes: 3 additions & 3 deletions test/Microsoft.OpenApi.Readers.Tests/TestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
// Licensed under the MIT license.

using System.IO;
using System.Linq;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.Reader.ParseNodes;
using Microsoft.OpenApi.YamlReader;
using SharpYaml.Serialization;

namespace Microsoft.OpenApi.Readers.Tests
{
internal class TestHelper
internal static class TestHelper
{
public static MapNode CreateYamlMapNode(Stream stream)
{
var yamlStream = new YamlStream();
yamlStream.Load(new StreamReader(stream));
var yamlNode = yamlStream.Documents.First().RootNode;
var yamlNode = yamlStream.Documents[0].RootNode;

var context = new ParsingContext(new OpenApiDiagnostic());
var asJsonNode = yamlNode.ToJsonNode();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System.IO;
using FluentAssertions;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.YamlReader;
using Xunit;

namespace Microsoft.OpenApi.Readers.Tests.V2Tests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Models.References;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.YamlReader;
using Xunit;

namespace Microsoft.OpenApi.Readers.Tests.V2Tests
Expand Down Expand Up @@ -329,8 +330,7 @@ public void ParseDocumentWithDefaultContentTypeSettingShouldSucceed()
public void testContentType()
{
var contentType = "application/json; charset = utf-8";
var res = contentType.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).First();
var expected = res.Split('/').LastOrDefault();
var res = contentType.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[0];
Assert.Equal("application/json", res);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.Reader.ParseNodes;
using Microsoft.OpenApi.Reader.V2;
using Microsoft.OpenApi.YamlReader;
using SharpYaml.Serialization;
using Xunit;

Expand Down Expand Up @@ -216,7 +217,7 @@ static YamlDocument LoadYamlDocument(Stream input)
using var reader = new StreamReader(input);
var yamlStream = new YamlStream();
yamlStream.Load(reader);
return yamlStream.Documents.First();
return yamlStream.Documents[0];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using FluentAssertions;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.YamlReader;
using Xunit;

namespace Microsoft.OpenApi.Readers.Tests.V2Tests
Expand Down Expand Up @@ -62,7 +63,7 @@ public void JustHostNoDefault()
""";
var result = OpenApiDocument.Parse(input, "yaml");

var server = result.OpenApiDocument.Servers.First();
var server = result.OpenApiDocument.Servers[0];
Assert.Single(result.OpenApiDocument.Servers);
Assert.Equal("//www.foo.com", server.Url);
}
Expand All @@ -87,7 +88,7 @@ public void NoBasePath()
};

var result = OpenApiDocument.Parse(input, "yaml", settings);
var server = result.OpenApiDocument.Servers.First();
var server = result.OpenApiDocument.Servers[0];
Assert.Single(result.OpenApiDocument.Servers);
Assert.Equal("http://www.foo.com", server.Url);
}
Expand All @@ -106,7 +107,7 @@ public void JustBasePathNoDefault()
""";
var result = OpenApiDocument.Parse(input, "yaml");

var server = result.OpenApiDocument.Servers.First();
var server = result.OpenApiDocument.Servers[0];
Assert.Single(result.OpenApiDocument.Servers);
Assert.Equal("/baz", server.Url);
}
Expand All @@ -131,7 +132,7 @@ public void JustSchemeWithCustomHost()

var result = OpenApiDocument.Parse(input, "yaml", settings);

var server = result.OpenApiDocument.Servers.First();
var server = result.OpenApiDocument.Servers[0];
Assert.Single(result.OpenApiDocument.Servers);
Assert.Equal("http://bing.com/foo", server.Url);
}
Expand All @@ -156,7 +157,7 @@ public void JustSchemeWithCustomHostWithEmptyPath()

var result = OpenApiDocument.Parse(input, "yaml", settings);

var server = result.OpenApiDocument.Servers.First();
var server = result.OpenApiDocument.Servers[0];
Assert.Single(result.OpenApiDocument.Servers);
Assert.Equal("http://bing.com", server.Url);
}
Expand All @@ -180,7 +181,7 @@ public void JustBasePathWithCustomHost()

var result = OpenApiDocument.Parse(input, "yaml", settings);

var server = result.OpenApiDocument.Servers.First();
var server = result.OpenApiDocument.Servers[0];
Assert.Single(result.OpenApiDocument.Servers);
Assert.Equal("https://bing.com/api", server.Url);
}
Expand All @@ -204,7 +205,7 @@ public void JustHostWithCustomHost()

var result = OpenApiDocument.Parse(input, "yaml", settings);

var server = result.OpenApiDocument.Servers.First();
var server = result.OpenApiDocument.Servers[0];
Assert.Single(result.OpenApiDocument.Servers);
Assert.Equal("https://www.example.com", server.Url);
}
Expand All @@ -228,7 +229,7 @@ public void JustHostWithCustomHostWithApi()
};

var result = OpenApiDocument.Parse(input, "yaml", settings);
var server = result.OpenApiDocument.Servers.First();
var server = result.OpenApiDocument.Servers[0];
Assert.Single(result.OpenApiDocument.Servers);
Assert.Equal("https://prod.bing.com", server.Url);
}
Expand All @@ -254,7 +255,7 @@ public void MultipleServers()
};

var result = OpenApiDocument.Parse(input, "yaml", settings);
var server = result.OpenApiDocument.Servers.First();
var server = result.OpenApiDocument.Servers[0];
Assert.Equal(2, result.OpenApiDocument.Servers.Count);
Assert.Equal("http://dev.bing.com/api", server.Url);
Assert.Equal("https://dev.bing.com/api", result.OpenApiDocument.Servers.Last().Url);
Expand All @@ -280,7 +281,7 @@ public void LocalHostWithCustomHost()

var result = OpenApiDocument.Parse(input, "yaml", settings);

var server = result.OpenApiDocument.Servers.First();
var server = result.OpenApiDocument.Servers[0];
Assert.Single(result.OpenApiDocument.Servers);
Assert.Equal("https://localhost:23232", server.Url);
}
Expand Down
Loading
Loading