-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Net6.0 Minimal API projects without Startup, issue #3794 #3814
Conversation
Fixes missing controllers in the specification when generating Net6.0 Minimal API projects using CLI/MSBuild
@@ -140,7 +140,13 @@ void OnEntryPointExit(Exception exception) | |||
try | |||
{ | |||
// Get the IServiceProvider from the host | |||
#if NET6_0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NET6_0_OR_GEATER
or else it will be broken in NET 7 again
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea.
From my understanding, NSwag style has been code tailored to each dotnet version and I made it NET6 specific. DotNet has had many breaking changes in recent versions, so I do hope this works for NET7 as well. :-)
Hello @RicoSuter |
@vpetrusevici There's now a new release on NuGet |
just tried it, works fine :) However when also setting up API versioning (Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer) with the following line in Program.cs. Note that the versioning is not really used in the minimal endpoints or controller.
the minimal endpoints are not present in the swagger, the controller operations are present. ==================================================================== using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.Extensions.DependencyInjection;
using System;
var builder = WebApplication.CreateBuilder(args);
// Optional: Use controllers
builder.Services.AddControllers();
builder.Services.AddApiVersioning(options => ConfigureApiVersioning(options));
builder.Services.AddVersionedApiExplorer(options => options.SubstituteApiVersionInUrl = true);
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddOpenApiDocument(settings =>
{
settings.Title = "Minimal API";
settings.Version = "v1";
});
var app = builder.Build();
app.UseDeveloperExceptionPage();
app.UseOpenApi();
app.UseSwaggerUi3();
app.MapGet("/", (Func<string>)(() => "Hello World!"))
.WithTags("General123");
app.MapGet("/sum/{a}/{b}", (Func<int, int, int>)((a, b) => a + b))
.WithName("CalculateSum")
.WithTags("Calculator");
// Optional: Use controllers
app.UseRouting();
app.MapControllers();
app.Run();
void ConfigureApiVersioning(ApiVersioningOptions options)
{
options.DefaultApiVersion = new ApiVersion(1, 0);
options.AssumeDefaultVersionWhenUnspecified = true;
options.ReportApiVersions = true;
}
// Optional: Use controllers
[ApiController]
[Route("api/examples")]
public class ExampleController : ControllerBase
{
[HttpGet]
public IActionResult Get()
{
return Ok("Examples");
}
} |
Seems that for some reason the minimal operations are not reported anymore by API Explorer... needs investigating. |
do we have to wait for this (OpenAPI in .NET ), or is it more NSwag specific that operations stop being reported. |
Is this still a problem with v13.15.10? |
yes, just tried again with 13.15.10. |
…coSuter#3814) Fixes missing controllers in the specification when generating Net6.0 Minimal API projects using CLI/MSBuild
…coSuter#3814) Fixes missing controllers in the specification when generating Net6.0 Minimal API projects using CLI/MSBuild
Fixes missing controllers in the specification when generating Net6.0 Minimal API projects using CLI/MSBuild