Skip to content

Commit

Permalink
✨ Use .NET OpenAPI and Scalar (#385)
Browse files Browse the repository at this point in the history
* asdf

* Update DependencyInjection.cs

* Added CORS exception

* Revert "Added CORS exception"

This reverts commit 12ae815.

* fix openapi with aspire

---------

Co-authored-by: Daniel Mackay [SSW] <[email protected]>
  • Loading branch information
MattParkerDev and danielmackay authored Oct 23, 2024
1 parent 986c62e commit 335a8d0
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 53 deletions.
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "9.0.0",
"version": "9.0.100-rc.2",
"rollForward": "latestFeature",
"allowPrerelease": true
}
Expand Down
2 changes: 1 addition & 1 deletion src/Infrastructure/Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<FrameworkReference Include="Microsoft.AspNetCore.App"/>

<PackageReference Include="Aspire.Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0-rc.1.24511.1" />
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="8.10.0"/>
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="9.0.0-preview.9.24507.7" />
<PackageReference Include="Microsoft.Extensions.ServiceDiscovery" Version="9.0.0-rc.1.24511.1"/>
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.9.0"/>
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.9.0"/>
Expand Down
5 changes: 2 additions & 3 deletions src/WebApi/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ public static void AddWebApi(this IServiceCollection services, IConfiguration co
{
services.AddHttpContextAccessor();
services.AddScoped<ICurrentUserService, CurrentUserService>();

services.AddOpenApiDocument(configure => configure.Title = "CleanArchitecture API");
services.AddEndpointsApiExplorer();

services.AddOpenApi();

AddHealthChecks(services, config);
}
Expand Down
8 changes: 3 additions & 5 deletions src/WebApi/Program.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Scalar.AspNetCore;
using SSW.CleanArchitecture.Application;
using SSW.CleanArchitecture.Infrastructure;
using SSW.CleanArchitecture.WebApi;
Expand Down Expand Up @@ -25,16 +26,13 @@
app.UseHsts();
}

app.MapOpenApi();
app.MapScalarApiReference(options => options.WithDefaultHttpClient(ScalarTarget.CSharp, ScalarClient.HttpClient));
app.UseHealthChecks();

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseOpenApi();
app.UseSwaggerUi();

app.UseRouting();

app.UseDefaultExceptionHandler();
app.MapHeroEndpoints();
app.MapTeamEndpoints();
Expand Down
30 changes: 2 additions & 28 deletions src/WebApi/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -1,38 +1,12 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:14064",
"sslPort": 44349
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5024",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7255;http://localhost:5024",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"launchUrl": "scalar/v1",
"applicationUrl": "https://localhost:7255",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
2 changes: 1 addition & 1 deletion src/WebApi/WebApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
<PackageReference Include="AspNetCore.HealthChecks.UI.InMemory.Storage" Version="8.0.1" />
<!-- Need to explictly reference Azure.Identity to remove vulnerability as Respawn uses a vulnerable version -->
<PackageReference Include="Azure.Identity" Version="1.13.0" />
<PackageReference Include="NSwag.AspNetCore" Version="14.0.3" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.0-rc.2.24474.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0-rc.2.24474.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="9.0.0-rc.2.24474.3" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="9.0.0-rc.2.24474.3" />
<PackageReference Include="Scalar.AspNetCore" Version="1.2.20" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion tools/AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

builder
.AddProject<WebApi>("api")
.WithExternalHttpEndpoints()
.WithEndpoint("https", endpoint => endpoint.IsProxied = false)
.WithReference(db)
.WaitForCompletion(migrationService);

Expand Down
14 changes: 1 addition & 13 deletions tools/AppHost/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,13 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17161;http://localhost:15231",
"applicationUrl": "https://localhost:17161",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21227",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22288"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15231",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19133",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20264"
}
}
}
}

0 comments on commit 335a8d0

Please sign in to comment.