Skip to content

Commit c9cd682

Browse files
committed
Added support for Open API (Swashbuckle)
1 parent 46bc9c8 commit c9cd682

File tree

253 files changed

+14940
-43
lines changed

Some content is hidden

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

253 files changed

+14940
-43
lines changed

Directory.Packages.props

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<PackageVersion Include="JetBrains.Profiler.Api" Version="1.4.8" />
77
<PackageVersion Include="MessagePack" Version="2.5.192" />
88
<PackageVersion Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="9.0.4" />
9+
<PackageVersion Include="Microsoft.AspNetCore.TestHost" Version="9.0.4" />
910
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
1011
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing" Version="1.1.2" />
1112
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp.CodeFix.Testing" Version="1.1.2" />
@@ -14,6 +15,7 @@
1415
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.4" />
1516
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.4" />
1617
<PackageVersion Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.4" />
18+
<PackageVersion Include="Microsoft.Extensions.ApiDescription.Server" Version="9.0.4" />
1719
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.4" />
1820
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="9.0.4" />
1921
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
@@ -23,8 +25,10 @@
2325
<PackageVersion Include="NSubstitute.Analyzers.CSharp" Version="1.0.17" />
2426
<PackageVersion Include="Serilog.Extensions.Logging" Version="9.0.1" />
2527
<PackageVersion Include="Serilog.Sinks.Console" Version="6.0.0" />
28+
<PackageVersion Include="Swashbuckle.AspNetCore.SwaggerGen" Version="8.1.1" />
2629
<PackageVersion Include="Verify.Xunit" Version="29.2.0" />
2730
<PackageVersion Include="xunit" Version="2.9.3" />
31+
<PackageVersion Include="Xunit.Extensions.Logging" Version="1.1.0" />
2832
<PackageVersion Include="xunit.runner.visualstudio" Version="3.0.2" />
2933
</ItemGroup>
3034
</Project>

Thinktecture.Runtime.Extensions.sln

+14
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Thinktecture.Runtime.Extens
8888
EndProject
8989
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Thinktecture.Runtime.Extensions.EntityFrameworkCore9.Tests", "test\Thinktecture.Runtime.Extensions.EntityFrameworkCore9.Tests\Thinktecture.Runtime.Extensions.EntityFrameworkCore9.Tests.csproj", "{03AA88D5-6E6F-4D19-BC90-311ACC7A0BF6}"
9090
EndProject
91+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Thinktecture.Runtime.Extensions.Swashbuckle", "src\Thinktecture.Runtime.Extensions.Swashbuckle\Thinktecture.Runtime.Extensions.Swashbuckle.csproj", "{16DFE8A6-91CC-4994-B956-FEE3D7E00E6F}"
92+
EndProject
93+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Thinktecture.Runtime.Extensions.Swashbuckle.Tests", "test\Thinktecture.Runtime.Extensions.Swashbuckle.Tests\Thinktecture.Runtime.Extensions.Swashbuckle.Tests.csproj", "{0CAADF0F-1CBA-4971-9920-8A8B31F8043A}"
94+
EndProject
9195
Global
9296
GlobalSection(SolutionConfigurationPlatforms) = preSolution
9397
Debug|Any CPU = Debug|Any CPU
@@ -202,6 +206,14 @@ Global
202206
{03AA88D5-6E6F-4D19-BC90-311ACC7A0BF6}.Debug|Any CPU.Build.0 = Debug|Any CPU
203207
{03AA88D5-6E6F-4D19-BC90-311ACC7A0BF6}.Release|Any CPU.ActiveCfg = Release|Any CPU
204208
{03AA88D5-6E6F-4D19-BC90-311ACC7A0BF6}.Release|Any CPU.Build.0 = Release|Any CPU
209+
{16DFE8A6-91CC-4994-B956-FEE3D7E00E6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
210+
{16DFE8A6-91CC-4994-B956-FEE3D7E00E6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
211+
{16DFE8A6-91CC-4994-B956-FEE3D7E00E6F}.Release|Any CPU.ActiveCfg = Release|Any CPU
212+
{16DFE8A6-91CC-4994-B956-FEE3D7E00E6F}.Release|Any CPU.Build.0 = Release|Any CPU
213+
{0CAADF0F-1CBA-4971-9920-8A8B31F8043A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
214+
{0CAADF0F-1CBA-4971-9920-8A8B31F8043A}.Debug|Any CPU.Build.0 = Debug|Any CPU
215+
{0CAADF0F-1CBA-4971-9920-8A8B31F8043A}.Release|Any CPU.ActiveCfg = Release|Any CPU
216+
{0CAADF0F-1CBA-4971-9920-8A8B31F8043A}.Release|Any CPU.Build.0 = Release|Any CPU
205217
EndGlobalSection
206218
GlobalSection(SolutionProperties) = preSolution
207219
HideSolutionNode = FALSE
@@ -234,6 +246,8 @@ Global
234246
{6638BCDF-A0A1-4742-B611-A67946CFB803} = {AE711F89-41F2-4519-B20D-BA1FAB0EB364}
235247
{08F267E9-A291-4613-BB41-75F164E2415D} = {8F117684-7943-4DCE-8861-F2B854924837}
236248
{03AA88D5-6E6F-4D19-BC90-311ACC7A0BF6} = {AE711F89-41F2-4519-B20D-BA1FAB0EB364}
249+
{16DFE8A6-91CC-4994-B956-FEE3D7E00E6F} = {8F117684-7943-4DCE-8861-F2B854924837}
250+
{0CAADF0F-1CBA-4971-9920-8A8B31F8043A} = {AE711F89-41F2-4519-B20D-BA1FAB0EB364}
237251
EndGlobalSection
238252
GlobalSection(ExtensibilityGlobals) = postSolution
239253
SolutionGuid = {1C34F508-A60B-4C0E-AFA0-0F4CFFB23603}

samples/Thinktecture.Runtime.Extensions.AspNetCore.Samples/Program.cs

+26-11
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,14 @@
1111
using Microsoft.Extensions.DependencyInjection;
1212
using Microsoft.Extensions.Hosting;
1313
using Microsoft.Extensions.Logging;
14+
using Microsoft.OpenApi.Models;
1415
using Serilog;
1516
using Serilog.Events;
1617
using Thinktecture.AspNetCore.ModelBinding;
18+
using Thinktecture.Controllers;
1719
using Thinktecture.Helpers;
1820
using Thinktecture.SmartEnums;
21+
using Thinktecture.Swashbuckle;
1922
using Thinktecture.Text.Json.Serialization;
2023
using Thinktecture.Unions;
2124
using Thinktecture.Validation;
@@ -40,7 +43,7 @@ public static async Task Main()
4043

4144
await DoHttpRequestsAsync(loggerFactory.CreateLogger<Program>(), startMinimalWebApi);
4245

43-
await Task.Delay(5000);
46+
await Task.Delay(60000);
4447
}
4548

4649
private static async Task DoHttpRequestsAsync(ILogger logger, bool forMinimalWebApi)
@@ -118,23 +121,32 @@ private static async Task DoRequestAsync(ILogger logger, HttpClient client, stri
118121
private static Task StartServerAsync(ILoggerFactory loggerFactory)
119122
{
120123
var webHost = new HostBuilder()
124+
.ConfigureServices(services =>
125+
{
126+
services.AddSingleton(loggerFactory)
127+
.AddSingleton<EmailNotificationSender>()
128+
.AddSingleton<SmsNotificationSender>();
129+
services.AddMvc(options => options.ModelBinderProviders.Insert(0, new ThinktectureModelBinderProvider()))
130+
.AddJsonOptions(options => options.JsonSerializerOptions.Converters.Add(new ThinktectureJsonConverterFactory()))
131+
.AddApplicationPart(typeof(DemoController).Assembly);
132+
133+
services.AddEndpointsApiExplorer()
134+
.AddSwaggerGen(options => options.SwaggerDoc("demo", new OpenApiInfo { Title = "Demo API", Version = "v1" }))
135+
.AddThinktectureOpenApiFilters(options => options.SmartEnumSchemaExtension = SmartEnumSchemaExtension.VarNamesFromStringRepresentation);
136+
})
121137
.ConfigureWebHostDefaults(builder =>
122138
{
123139
builder.UseKestrel()
124140
.Configure(app =>
125141
{
126142
app.UseRouting();
127-
app.UseEndpoints(endpoints => endpoints.MapControllers());
143+
app.UseEndpoints(endpoints =>
144+
{
145+
endpoints.MapSwagger();
146+
endpoints.MapControllers();
147+
});
128148
});
129149
})
130-
.ConfigureServices(collection =>
131-
{
132-
collection.AddSingleton(loggerFactory)
133-
.AddSingleton<EmailNotificationSender>()
134-
.AddSingleton<SmsNotificationSender>();
135-
collection.AddControllers(options => options.ModelBinderProviders.Insert(0, new ThinktectureModelBinderProvider()))
136-
.AddJsonOptions(options => options.JsonSerializerOptions.Converters.Add(new ThinktectureJsonConverterFactory()));
137-
})
138150
.Build();
139151

140152
return webHost.StartAsync();
@@ -150,7 +162,10 @@ private static Task StartMinimalWebApiAsync(ILoggerFactory loggerFactory)
150162
.ConfigureHttpJsonOptions(options =>
151163
{
152164
options.SerializerOptions.Converters.Add(new ThinktectureJsonConverterFactory());
153-
});
165+
})
166+
.AddEndpointsApiExplorer()
167+
.AddSwaggerGen(options => options.SwaggerDoc("demo", new OpenApiInfo { Title = "Demo API", Version = "v1" }))
168+
.AddThinktectureOpenApiFilters(options => options.SmartEnumSchemaExtension = SmartEnumSchemaExtension.VarNamesFromStringRepresentation);
154169

155170
var app = builder.Build();
156171

Original file line numberDiff line numberDiff line change
@@ -1,16 +1,30 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
23
<PropertyGroup>
34
<OutputType>EXE</OutputType>
45
<NoWarn>$(NoWarn);CA2007;CA2234</NoWarn>
56
</PropertyGroup>
7+
8+
<PropertyGroup>
9+
<OpenApiGenerateDocuments>true</OpenApiGenerateDocuments>
10+
<OpenApiDocumentsDirectory>$(MSBuildProjectDirectory)</OpenApiDocumentsDirectory>
11+
</PropertyGroup>
12+
613
<ItemGroup>
14+
<PackageReference Include="Microsoft.Extensions.ApiDescription.Server">
15+
<PrivateAssets>all</PrivateAssets>
16+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
17+
</PackageReference>
718
<PackageReference Include="Serilog.Extensions.Logging" />
819
<PackageReference Include="Serilog.Sinks.Console" />
920
</ItemGroup>
21+
1022
<ItemGroup>
1123
<ProjectReference Include="..\..\src\Thinktecture.Runtime.Extensions.AspNetCore\Thinktecture.Runtime.Extensions.AspNetCore.csproj" />
1224
<ProjectReference Include="..\..\src\Thinktecture.Runtime.Extensions.Json\Thinktecture.Runtime.Extensions.Json.csproj" />
25+
<ProjectReference Include="..\..\src\Thinktecture.Runtime.Extensions.Swashbuckle\Thinktecture.Runtime.Extensions.Swashbuckle.csproj" />
1326
<ProjectReference Include="..\Thinktecture.Runtime.Extensions.Samples\Thinktecture.Runtime.Extensions.Samples.csproj" />
1427
<ProjectReference Include="..\..\src\Thinktecture.Runtime.Extensions.SourceGenerator\Thinktecture.Runtime.Extensions.SourceGenerator.csproj" SetTargetFramework="TargetFramework=netstandard2.0" ReferenceOutputAssembly="false" OutputItemType="Analyzer" />
1528
</ItemGroup>
29+
1630
</Project>

0 commit comments

Comments
 (0)