Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add TodoWebService.NSwag sample project #684

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions src/Samples/TodoWebService/TodoWebService.NSwag/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using Marten;
using Oakton;
using Oakton.Resources;
using Wolverine;
using Wolverine.Http;
using Wolverine.Marten;

var builder = WebApplication.CreateBuilder(args);

// Adding Marten for persistence
builder.Services.AddMarten(opts =>
{
opts.Connection(builder.Configuration.GetConnectionString("Marten"));
opts.DatabaseSchemaName = "todo";
})
.IntegrateWithWolverine();

builder.Services.AddResourceSetupOnStartup();

// Wolverine usage is required for WolverineFx.Http
builder.Host.UseWolverine(opts =>
{
// This middleware will apply to the HTTP
// endpoints as well
opts.Policies.AutoApplyTransactions();

// Setting up the outbox on all locally handled
// background tasks
opts.Policies.UseDurableLocalQueues();
});


// Learn more about configuring NSwag at https://learn.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-nswag
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddOpenApiDocument();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseOpenApi();
app.UseSwaggerUi();
}

// Let's add in Wolverine HTTP endpoints to the routing tree
app.MapWolverineEndpoints();

// TODO Investigate if this is a dotnet-getdocument issue
args = args.Where(arg => !arg.StartsWith("--applicationName")).ToArray();

return await app.RunOaktonCommands(args);
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:55609",
"sslPort": 44319
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5198",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7075;http://localhost:5198",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<!-- This can be used to generate an NSwag client -->
<!-- <OpenApiGenerateDocumentsOnBuild>true</OpenApiGenerateDocumentsOnBuild> -->
</PropertyGroup>

<ItemGroup>
<Compile Include="..\TodoWebService\Endpoints.cs" Link="Endpoints.cs" />
<Compile Include="..\TodoWebService\HelloEndpoint.cs" Link="HelloEndpoint.cs" />
<Compile Include="..\TodoWebService\TodoListEndpoint.cs" Link="TodoListEndpoint.cs" />
<None Include="..\TodoWebService\README.md" Link="README.md" />
</ItemGroup>

<ItemGroup>
<!--
To use OpenApiGenerateDocumentsOnBuild with Wolverine, upgrade Microsoft.Extensions.ApiDescription.Server (transitive NSwag dependency).
See also: https://github.com/RicoSuter/NSwag/issues/3403
-->
<!-- <PackageReference Include="Microsoft.Extensions.ApiDescription.Server" Version="8.0.1"> -->
<!-- <PrivateAssets>all</PrivateAssets> -->
<!-- <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> -->
<!-- </PackageReference> -->
<PackageReference Include="NSwag.AspNetCore" Version="14.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\Http\Wolverine.Http\Wolverine.Http.csproj" />
<ProjectReference Include="..\..\..\Persistence\Wolverine.Marten\Wolverine.Marten.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}
12 changes: 12 additions & 0 deletions src/Samples/TodoWebService/TodoWebService.NSwag/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"Marten": "Host=localhost;Port=5433;Database=postgres;Username=postgres;password=postgres"
}
}
Loading
Loading