Skip to content

Reduce reliance on ApiExplorer types for Microsoft.AspNetCore.OpenApi consumption #44209

Closed
@captainsafia

Description

@captainsafia

In .NET 7, we introduced the new Microsoft.AspNetCore.OpenApi package that generates an OpenApiOperation definition for a given minimal endpoint and its metadata. One of the goals of this package was to remove the reliance on ApiExplorer and it's types that existed in the current implementation for OpenAPI definitions.

Currently, even if a user is using WithOpenApi exclusively to document their endpoints they still have to include the following in their application to register the minimal API-specific implementations of ApiExplorer.

builder.Services.AddEndpointsApiExplorer();

Open source dependencies like Swashbuckle and NSwag still rely on ApiExplorer-specific types, like IApiDescriptionGroupCollectionProvider, to determine all of the endpoints that are associated with an application. Reducing the reliance on this type for minimal API scenarios in particular would allow us to remove the AddEndpointsApiExplorer from the template.

There's a chance that if we do #44192, then we wouldn't need to find a different way to derive all the endpoints in an application and can instead use the OpenApiDocument directly as the source of truth.

Activity

added this to the .NET 8 Planning milestone on Sep 27, 2022
ghost

ghost commented on Sep 27, 2022

@ghost

Thanks for contacting us.

We're moving this issue to the .NET 8 Planning milestone for future evaluation / consideration. We would like to keep this around to collect more feedback, which can help us with prioritizing this work. We will re-evaluate this issue, during our next planning meeting(s).
If we later determine, that the issue has no community involvement, or it's very rare and low-impact issue, we will close it - so that the team can focus on more important and high impact issues.
To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.

davidfowl

davidfowl commented on Sep 28, 2022

@davidfowl
Member

I would also like to bring up the fact that all endpoints are opt into open API by default because of this. If we design a new way I like the explicit opt in via an explicit call to WithOpenApi. Using groups, you can also apply that to many endpoints without much hassle. It's a much cleaner way to enable things.

captainsafia

captainsafia commented on Sep 28, 2022

@captainsafia
MemberAuthor

I would also like to bring up the fact that all endpoints are opt into open API by default because of this. If we design a new way I like the explicit opt in via an explicit call to WithOpenApi. Using groups, you can also apply that to many endpoints without much hassle. It's a much cleaner way to enable things.

Agree here. I'll add that this would mean we have WithOpenApi enabled by default in the templates.

davidfowl

davidfowl commented on Oct 1, 2022

@davidfowl
Member

@captainsafia We should write down what we think the template would look like after we finish the work (basically start with that end goal in mind). As well as a before and after simple todo API.

added
area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etc
and removed
old-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels
on Jun 20, 2023
nithinbandaru1

nithinbandaru1 commented on Jan 23, 2024

@nithinbandaru1

So,

Does this mean

For Controller based APIs use?

builder.Services.AddEndpointsApiExplorer();

For Minimal APIs use?

builder.Services.WithOpenApi();

Also is this OpenApiDocument there? Does this mean Nswag, Swashbuck libraries doesn't need to construct OpenAPI doc from APIExplorer?

captainsafia

captainsafia commented on Jan 29, 2024

@captainsafia
MemberAuthor

For Controller based APIs use?

Not quite. For controller-based APIs, you'll want to use AddApiExplorer. However, you'll rarely need to do this yourself since the ApiExplorer service is implicitly registered by by AddControllers (or AddMvc if you're using that).

builder.Services.WithOpenApi();

Something like this, but AddOpenApi to match the syntax of other DI-related APIs.

Also is this OpenApiDocument there?

Perhaps, or some type approximate to it. The main goal is to provide a way to capture the entire collection of OpenApiOperation descriptions in the app instead of a single one per endpoint.

captainsafia

captainsafia commented on Apr 23, 2024

@captainsafia
MemberAuthor

Closing this.

We support generating the OpenAPI document by default now, and implicitly take a dependency on ApiExplorer so that we can generate docs for both minimal and controller-style APIs. Templates will be updated in .NET 9 Preview 5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-openapi

    Type

    No type

    Projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @davidfowl@captainsafia@nithinbandaru1

        Issue actions

          Reduce reliance on ApiExplorer types for `Microsoft.AspNetCore.OpenApi` consumption · Issue #44209 · dotnet/aspnetcore