One of the current problems with the Microsoft OpenAPI Microsoft.Extensions.ApiDescription.Server package is its build-time document generation process.
When generating the OpenAPI JSON file, it effectively calls the Main() method in Program.cs before the application builder is created with:
var builder = WebApplication.CreateBuilder(args);Because this happens during the build process rather than at runtime, the system does not know which environment it is meant to run in. As a result, it defaults to the Production environment. This means the build process expects required secrets to be present and throws errors if they are missing.