dotnet / dotnet/aspnetcore

[OpenAPI] Use transformers that are registered in DI.

Open
#62,088 2 comments 0 reactions 0 assignees View on GitHub
area-minimal feature-openapi
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Is there an existing issue for this?

- [x] 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:

```C#
builder.Services.AddScoped();
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:

```C#
public static void AddCustomOpenApi(this IServiceCollection services, string documentName, Action configure)
{
services.AddOpenApi(documentName, options =>
{
options.AddDocumentTransformer();
configure(options);
}
}
```
But I think the first suggestion would be more useful.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.