question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Introduce Microsoft.AspNetCore.OpenApi package

See original GitHub issue

Consider introducing a new package Microsoft.AspNetCore.OpenApi that provides integration features for ASP.NET Core HTTP APIs and OpenAPI. This package takes a dependency on Microsoft.OpenApi and contains the logic that maps primitive ASP.NET Core endpoint details to representations in endpoint metadata using the object model provided by Microsoft.OpenApi, along with projecting these details into the legacy ApiExplorer API from MVC. Furthermore, it provides helper methods for easily adding user-specified OpenAPI relevant details directly to endpoint metadata.

This would essentially be a strategy shift so that instead of continuing to add more metadata types to the framework to allow more details about endpoint APIs to be declared and published in MVC’s ApiExplorer (e.g. #40084), we embrace the existing OpenAPI object model in Microsoft.OpenApi and allow all operation details to be specified in an endpoint’s metadata and projected into ApiExplorer so that existing libraries like Swashbuckle continue to work.

The package would do the following:

  • Depend on Microsoft.OpenApi
  • Contain the logic that maps the MethodInfo for a route handler delegate in the endpoint metadata, to the requisite Microsoft.OpenApi.Models.OpenApiOperation
  • Provide extension methods to easily allow mutating a route handler delegate’s OpenApi metadata, e.g.
    app.MapGet("/todos", async (TodoDb db) => await db.Todos.ToListAsync())
        .WithOpenApiDetails(operation =>
        {
            operation.OperationId = "GetAllTodos";
            operation.Description = "This API returns all the Todos.";
        });
    
  • Preserves the Microsoft.OpenApi.Models.OpenApiOperation in the endpoint metadata
    • This requires a new extensibility point be added such that the package can mutate the metadata for endpoints built by the route endpoint builder
  • Contain the IApiDescriptionProvider that projects a route handler’s details from its OpenAPI endpoint metadata into ApiExplorer
  • Be referenced in the Web API project template
  • Would not reference Swashbuckle.AspNetCore, rather a project would still need to reference the SwaggerUI/OpenAPI library it wishes to use and call the requisite configuration methods for it to be configured

We need to consider of course how we do this without breaking (too much) stuff. In .NET 6, Minimal API endpoints are added to the ApiExplorer if MVC is configured, or the AddEndpointsApiExplorer() services extension method is called.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:43
  • Comments:12 (10 by maintainers)

github_iconTop GitHub Comments

4reactions
jchannoncommented, Apr 7, 2022

giphy

3reactions
darrelmillercommented, Mar 15, 2022

Sign us up.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Microsoft.AspNetCore.OpenApi 7.0.10
Provides APIs for annotating route handler endpoints in ASP.NET Core with OpenAPI annotations. This package was built from the source code at...
Read more >
ASP.NET Core web API documentation with Swagger ...
This tutorial provides a walkthrough of adding Swagger to generate documentation and help pages for a web API app.
Read more >
How to use OpenAPI in ASP.NET Core
Launch the Visual Studio 2022 IDE. · Click on “Create new project.” · In the “Create new project” window, select “ASP.NET Core Web...
Read more >
Get started with Swashbuckle and ASP.NET Core
Go to View > Other Windows > Package Manager Console · Navigate to the directory in which the .csproj file exists · Execute...
Read more >
Enriched Web API Documentation using Swagger/OpenAPI in ...
To provide OpenAPI Documentation, we would start by installing the Swashbuckle.AspNetCore NuGet package. To support API documentation for ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found