Skip to content

Minimal APIs #3560

@Megasware128

Description

@Megasware128

ASP.NET Core 6 Preview 6 introduces OpenAPI support for minimal APIs. It does this by exposing an API Explorer from Endpoint metadata builder.Services.AddEndpointsApiExplorer(). This works correctly with Swashbuckle but doesn't with NSwag. NSwag loads without errors but the swagger.json doesn't contain any paths. Got some sample code bellow. (Working) Swashbuckle code has been commented out:

using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddEndpointsApiExplorer();

//builder.Services.AddSwaggerGen(c =>
//{
//    c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Description = "Docs for my API", Version = "v1" });
//});

builder.Services.AddOpenApiDocument();

var app = builder.Build();

if (app.Environment.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
}

//SwaggerBuilderExtensions.UseSwagger(app);

//app.UseSwaggerUI(c =>
//{
//    c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
//});

app.UseOpenApi();
app.UseSwaggerUi3();

app.MapGet("/", () => "Hello World!");

app.Run();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions