Skip to content

Commit 2bd8576

Browse files
[OpenAPI] Add OpenAPI adapter (#8886)
1 parent d96e96e commit 2bd8576

File tree

140 files changed

+10796
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+10796
-0
lines changed

src/All.slnx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,15 @@
181181
<Folder Name="/HotChocolate/Diagnostics/test/">
182182
<Project Path="HotChocolate/Diagnostics/test/Diagnostics.Tests/HotChocolate.Diagnostics.Tests.csproj" />
183183
</Folder>
184+
<Folder Name="/HotChocolate/Adapters/" />
185+
<Folder Name="/HotChocolate/Adapters/src/">
186+
<Project Path="HotChocolate/Adapters/src/Adapters.OpenApi/HotChocolate.Adapters.OpenApi.csproj" />
187+
<Project Path="HotChocolate/Adapters/src/Adapters.OpenApi.Core/HotChocolate.Adapters.OpenApi.Core.csproj" />
188+
<Project Path="HotChocolate/Adapters/src/Adapters.OpenApi.Fusion/HotChocolate.Fusion.Adapters.OpenApi.csproj" />
189+
</Folder>
190+
<Folder Name="/HotChocolate/Adapters/test/">
191+
<Project Path="HotChocolate/Adapters/test/Adapters.OpenApi.Tests/HotChocolate.Adapters.OpenApi.Tests.csproj" />
192+
</Folder>
184193
<Folder Name="/HotChocolate/Fusion-vnext/" />
185194
<Folder Name="/HotChocolate/Fusion-vnext/benchmarks/">
186195
<Project Path="HotChocolate/Fusion-vnext/benchmarks/Fusion.Execution.Benchmarks/Fusion.Execution.Benchmarks.csproj" />

src/Directory.Packages.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
8080
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="10.0.0-rc.2.25502.107" />
8181
<PackageVersion Include="Microsoft.AspNetCore.Components.Web" Version="10.0.0-rc.2.25502.107" />
82+
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0-rc.2.25502.107" />
8283
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="10.0.0-rc.2.25502.107" />
8384
<PackageVersion Include="Microsoft.AspNetCore.WebUtilities" Version="10.0.0-rc.2.25502.107" />
8485
<PackageVersion Include="Microsoft.Data.Sqlite.Core" Version="10.0.0-rc.2.25502.107" />
@@ -106,6 +107,7 @@
106107
<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
107108
<PackageVersion Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="9.0.0" />
108109
<PackageVersion Include="Microsoft.AspNetCore.Components.Web" Version="9.0.2" />
110+
<PackageVersion Include="Microsoft.AspNetCore.OpenApi" Version="9.0.2" />
109111
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="9.0.2" />
110112
<PackageVersion Include="Microsoft.AspNetCore.WebUtilities" Version="9.0.2" />
111113
<PackageVersion Include="Microsoft.Data.Sqlite.Core" Version="9.0.2" />
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Solution>
2+
<Folder Name="/src/" />
3+
<Folder Name="/src/Adapters.OpenApi/">
4+
<Project Path="src\Adapters.OpenApi.Core\HotChocolate.Adapters.OpenApi.Core.csproj" />
5+
<Project Path="src\Adapters.OpenApi.Fusion\HotChocolate.Fusion.Adapters.OpenApi.csproj" />
6+
<Project Path="src\Adapters.OpenApi\HotChocolate.Adapters.OpenApi.csproj" />
7+
</Folder>
8+
<Folder Name="/test/" />
9+
<Folder Name="/test/Adapters.OpenApi.Tests/">
10+
<Project Path="test\Adapters.OpenApi.Tests\HotChocolate.Adapters.OpenApi.Tests.csproj" />
11+
</Folder>
12+
</Solution>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project>
2+
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)..\'))" />
3+
4+
<PropertyGroup>
5+
<TargetFrameworks>net10.0; net9.0</TargetFrameworks>
6+
<LangVersion>Preview</LangVersion>
7+
</PropertyGroup>
8+
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace HotChocolate.Adapters.OpenApi;
2+
3+
internal sealed class AggregateOpenApiDiagnosticEventListener(IOpenApiDiagnosticEventListener[] listeners)
4+
: IOpenApiDiagnosticEventListener
5+
{
6+
public void ValidationErrors(IReadOnlyList<IOpenApiError> errors)
7+
{
8+
foreach (var listener in listeners)
9+
{
10+
listener.ValidationErrors(errors);
11+
}
12+
}
13+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace HotChocolate.Adapters.OpenApi;
2+
3+
/// <summary>
4+
/// Register an implementation of this interface in the DI container to
5+
/// listen to diagnostic events. Multiple implementations can be registered,
6+
/// and they will all be called in the registration order.
7+
/// </summary>
8+
/// <seealso cref="OpenApiDiagnosticEventListener"/>
9+
public interface IOpenApiDiagnosticEventListener : IOpenApiDiagnosticEvents;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace HotChocolate.Adapters.OpenApi;
2+
3+
/// <summary>
4+
/// Provides diagnostic events for the OpenAPI integration.
5+
/// </summary>
6+
public interface IOpenApiDiagnosticEvents
7+
{
8+
/// <summary>
9+
/// Called when errors occur while parsing or validating an OpenAPI document.
10+
/// </summary>
11+
/// <param name="errors">The errors.</param>
12+
void ValidationErrors(IReadOnlyList<IOpenApiError> errors);
13+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
namespace HotChocolate.Adapters.OpenApi;
2+
3+
internal sealed class NoOpOpenApiDiagnosticEventListener : OpenApiDiagnosticEventListener;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
namespace HotChocolate.Adapters.OpenApi;
2+
3+
/// <summary>
4+
/// This class can be used as a base class for <see cref="IOpenApiDiagnosticEventListener"/>
5+
/// implementations, so that they only have to override the methods they
6+
/// are interested in instead of having to provide implementations for all of them.
7+
/// </summary>
8+
public class OpenApiDiagnosticEventListener : IOpenApiDiagnosticEventListener
9+
{
10+
/// <summary>
11+
/// A no-op activity scope that can be returned from
12+
/// event methods that are not interested in when the scope is disposed.
13+
/// </summary>
14+
protected static IDisposable EmptyScope { get; } = new EmptyActivityScope();
15+
16+
public virtual void ValidationErrors(IReadOnlyList<IOpenApiError> errors)
17+
{
18+
}
19+
20+
private sealed class EmptyActivityScope : IDisposable
21+
{
22+
public void Dispose()
23+
{
24+
}
25+
}
26+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using HotChocolate.Language;
2+
3+
namespace HotChocolate.Adapters.OpenApi;
4+
5+
public interface IOpenApiDocument
6+
{
7+
string Id { get; }
8+
9+
string Name { get; }
10+
11+
string? Description { get; }
12+
13+
Dictionary<string, FragmentDefinitionNode> LocalFragmentLookup { get; }
14+
15+
HashSet<string> ExternalFragmentReferences { get; }
16+
}

0 commit comments

Comments
 (0)