Skip to content

[OpenAPI] Use transformers that are registered in DI. #62088

@dnperfors

Description

@dnperfors

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

I am trying to use the same transformers for multiple OpenAPI documents, but instead of registering them in every .AddOpenApi() call, I want to register certain transformers globally in de the services.

Describe the solution you'd like

I would like to be able to do something like:

builder.Services.AddScoped<IOpenApiDocumentTransformer, GenericDocumentInfoTransformer>();
builder.Services.AddOpenApi("v1");
builder.Services.AddOpenApi("v2");

so that when running generating the OpenApi document, all the transformers that are registered in the Services are also used.

Additional context

Of course I can work around this by using a custom extension method:

public static void AddCustomOpenApi(this IServiceCollection services, string documentName, Action<OpenApiOptions> configure)
{
    services.AddOpenApi(documentName, options =>
    {
        options.AddDocumentTransformer<GenericDocumentInfoTransformer>();
        configure(options);
    }
}

But I think the first suggestion would be more useful.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions