dotnet / dotnet/aspnetcore

ApiDescription server should inject Environment variable

Open
#65,618 4 comments 1 reaction 0 assignees View on GitHub
area-commandlinetools feature-openapi
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

Currently if you use the [ApiDescription.Server](https://www.nuget.org/packages/microsoft.extensions.apidescription.server/) you need to do [reflection](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/openapi/aspnetcore-openapi?view=aspnetcore-10.0&tabs=visual-studio%2Cvisual-studio-code#customize-runtime-behavior-during-build-time-document-generation) to see if it is running with this server.

```csharp
using System.Reflection;

var builder = WebApplication.CreateBuilder(args);
// I don't want this!!
if (Assembly.GetEntryAssembly()?.GetName().Name != "GetDocument.Insider")
{
builder.AddServiceDefaults();
}
```

This is very bad, I don't want any reflection in my code (AOT build), maybe it can inject a special environment variable in the config?

I want (or similar):
```csharp
if (builder.Configuration.GetValue("ASPNET_APIDESCRIPTION"))
{
...
}
```

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.