Skip to content

Commit

Permalink
Trying to set up Swagger in the Web app
Browse files Browse the repository at this point in the history
  • Loading branch information
Piedone committed Jul 11, 2024
1 parent 6431354 commit c3714d5
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/OrchardCore.Cms.Web/OrchardCore.Cms.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<RazorRuntimeCompilation>false</RazorRuntimeCompilation>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OpenApiGenerateDocumentsOnBuild>false</OpenApiGenerateDocumentsOnBuild>
</PropertyGroup>
<!-- For Unit Tests-->
<ItemGroup>
Expand All @@ -28,6 +29,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Condition="'$(RazorRuntimeCompilation)' == 'true'" />
<PackageReference Include="Swashbuckle.AspNetCore" />
</ItemGroup>

<ItemGroup>
Expand Down
12 changes: 10 additions & 2 deletions src/OrchardCore.Cms.Web/Program.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
using Microsoft.OpenApi.Models;
using OrchardCore.Logging;

var builder = WebApplication.CreateBuilder(args);

builder.Host.UseNLogHost();

builder.Services
.AddOrchardCms()
.AddSetupFeatures("OrchardCore.AutoSetup");
.AddOrchardCms(orchardCoreBuilder =>
{
orchardCoreBuilder.ApplicationServices.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
});
});

var app = builder.Build();

if (!app.Environment.IsDevelopment())
{
app.UseSwagger();

app.UseExceptionHandler("/Error");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

Provides features to manage tenants from the Admin UI</Description>
<PackageTags>$(PackageTags) OrchardCoreCMS</PackageTags>
<OpenApiGenerateDocumentsOnBuild>false</OpenApiGenerateDocumentsOnBuild>
</PropertyGroup>

<ItemGroup>
Expand All @@ -33,7 +32,6 @@

<ItemGroup>
<PackageReference Include="NJsonSchema" />
<PackageReference Include="Swashbuckle.AspNetCore" />
</ItemGroup>

</Project>
8 changes: 0 additions & 8 deletions src/OrchardCore.Modules/OrchardCore.Tenants/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Microsoft.Net.Http.Headers;
using Microsoft.OpenApi.Models;
using OrchardCore.Deployment;
using OrchardCore.DisplayManagement.Descriptors;
using OrchardCore.Environment.Shell;
Expand Down Expand Up @@ -75,11 +74,6 @@ public override void ConfigureServices(IServiceCollection services)
{
return serviceProvider.GetRequiredService<ITenantFileProvider>();
});

services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
});
}

public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, IServiceProvider serviceProvider)
Expand All @@ -98,8 +92,6 @@ public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder ro
ctx.Context.Response.Headers[HeaderNames.CacheControl] = $"public, max-age={TimeSpan.FromDays(30).TotalSeconds}, s-max-age={TimeSpan.FromDays(365.25).TotalSeconds}";
}
});

app.UseSwagger();
}

private static string GetContentRoot(ShellOptions shellOptions, ShellSettings shellSettings) =>
Expand Down

0 comments on commit c3714d5

Please sign in to comment.