Skip to content

Commit

Permalink
Move Swagger to Configure.OpenApi.cs
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Feb 7, 2024
1 parent 89feacb commit 2fb6e0f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
32 changes: 32 additions & 0 deletions MyApp/Configure.OpenApi.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[assembly: HostingStartup(typeof(MyApp.ConfigureOpenApi))]

namespace MyApp;

public class ConfigureOpenApi : IHostingStartup
{
public void Configure(IWebHostBuilder builder) => builder
.ConfigureServices((context, services) =>
{
if (context.HostingEnvironment.IsDevelopment())
{
services.AddEndpointsApiExplorer();
services.AddSwaggerGen();

services.AddServiceStackSwagger();
services.AddBasicAuth<Data.ApplicationUser>();
//services.AddJwtAuth();

services.AddTransient<IStartupFilter, StartupFilter>();
}
});

public class StartupFilter : IStartupFilter
{
public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next) => app =>
{
app.UseSwagger();
app.UseSwaggerUI();
next(app);
};
}
}
5 changes: 4 additions & 1 deletion MyApp/MyApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.*" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.*" />
<PackageReference Include="Markdig" Version="0.34.*" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.*" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.*" />
<PackageReference Include="ServiceStack.AspNetCore.OpenApi" Version="8.*" />
</ItemGroup>

<ItemGroup>
Expand All @@ -32,7 +36,6 @@
<PackageReference Include="ServiceStack.OrmLite.Sqlite.Data" Version="8.*" />
<PackageReference Include="ServiceStack.Extensions" Version="8.*" />
<PackageReference Include="ServiceStack.Server" Version="8.*" />
<PackageReference Include="ServiceStack.AspNetCore.OpenApi" Version="8.*" />
</ItemGroup>

<ItemGroup>
Expand Down
12 changes: 1 addition & 11 deletions MyApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
options.DefaultScheme = IdentityConstants.ApplicationScheme;
options.DefaultSignInScheme = IdentityConstants.ExternalScheme;
})
.AddBasicAuth<ApplicationUser>()
.AddIdentityCookies();
services.AddDataProtection()
.PersistKeysToFileSystem(new DirectoryInfo("App_Data"));
Expand Down Expand Up @@ -58,23 +57,14 @@
services.AddBlazorServerIdentityApiClient(baseUrl);
services.AddLocalStorage();

services.AddEndpointsApiExplorer();
services.AddSwaggerGen();

services.AddServiceStack(typeof(MyServices).Assembly, c => {
c.AddSwagger(o => {
o.AddBasicAuth();
});
});
services.AddServiceStack(typeof(MyServices).Assembly);

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseMigrationsEndPoint();
app.UseSwagger();
app.UseSwaggerUI();
}
else
{
Expand Down

0 comments on commit 2fb6e0f

Please sign in to comment.