dotnet / dotnet/aspnetcore

Microsoft.Extensions.ApiDescription.Server should allow setting the complete filename

Open
#63,049 2 comments 0 reactions 0 assignees View on GitHub
area-commandlinetools feature-openapi
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 6h
Merged PRs (30d)
290

Description

Microsoft.Extensions.ApiDescription.Server allows build-time generation of OpenAPI documents, but [as per the documentation](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/openapi/aspnetcore-openapi):

> If multiple documents are registered, and document name is not v1, it's post-fixed with the document name. E.g., {ProjectName}_{DocumentName}.json.

There is an option to set the filename:
```xml

--file-name my-open-api

```

But this does not set the filename, only the project name prefix. If your document name is not `v1`, the `--file-name` parameters only sets the prefix. My document name, for example is `openapi.json`, using the above, I end up with `my-filename_openapi.json`.

So if I want to match my OpenAPI endpoint configuration below:

```csharp
var builder = WebApplication.CreateBuilder(args);

services.AddOpenApi("openapi");

var app = builder.Build();

app.MapOpenApi("/{documentName}.json");

app.Run();
```

There's simply no way and requires me to run a post-build script to rename the output file.

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.