Skip to content

Update the Server project for net9.0+ #1690

@dansiegel

Description

@dansiegel

Description

Currently the Server project is making use of legacy APIs for the API Explorer and Swagger

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c =>
{
// Include XML comments for all included assemblies
Directory.EnumerateFiles(AppContext.BaseDirectory, "*.xml")
.Where(x => x.Contains("MyExtensionsApp._1")
&& File.Exists(Path.Combine(
AppContext.BaseDirectory,
$"{Path.GetFileNameWithoutExtension(x)}.dll")))
.ToList()
.ForEach(path => c.IncludeXmlComments(path));
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

This should be updated with net9.0 to use the OpenAPI extension and as it seems the more popular one these days is Scalar this should also be updated accordingly.

// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.MapOpenApi();
    app.MapScalarApiReference(o =>
    {
        o.EnabledClients = [
            ScalarClient.HttpClient,
            ScalarClient.Http11,
            ScalarClient.JQuery,
            ScalarClient.Xhr
        ];
    });
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage/untriagedIndicates an issue requires triaging or verification.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions