Question Details

No question body available.

Tags

c# azure-functions openapi .net-10.0

Answers (1)

Accepted Answer Available
Accepted Answer
February 23, 2026 Score: 3 Rep: 6,183 Quality: High Completeness: 80%

Given IS THIS REPO DEAD??? and Notice: This OpenAPI extension project is in maintenance mode, I wonder if you should rely on that package, i.e. from the later:

If the current scope of this project meets your needs, you can continue to use it.

Maybe it doesn't meet your needs?

The .ConfigureOpenApi() method doesn't seem to allow any type of customizations.....

That's correct. ConfigureOpenApi() merely adds the service implementations. Not sure why there's a commented out line at the end.

Looking around, I found Configure(), which looks suspiciously like a duplicate of ConfigureOpenApi(), including that commented out line, but additionally injects some OpenApiSettings object. I assume the line [assembly: WorkerExtensionStartup(typeof(OpenApiWorkerStartup))] causes this to be executed automagically1 and am not sure if ConfigureOpenApi() is even necessary.

Btw: there are three similar classes (OpenApiSettings, OpenApiSettings and OpenApiSettings) that all look like they have the purpose to hold the data that you'd like to set.

I guess that the intended functionality of PR Add built-in OpenAPI app settings object is to allow you to set these values through environment variables. That could be a viable option for you, as your values are hard coded.

If you want to set those values in code instead, you can inject your own configuration object:

Injecting OpenApiConfigurationOptions during Startup

You may want to inject the OpenApiConfigurationOptions instance during startup, through the Program.cs class. Here's the example:

namespace MyFunctionApp
{
    public class Program
    {
        public static void Main()
        {
            var host = new HostBuilder()
                .ConfigureFunctionsWorkerDefaults(worker => worker.UseNewtonsoftJson())
                / ⬇️⬇️⬇️ Add this ⬇️⬇️⬇️ /
                .ConfigureServices(services =>
                {
                    services.AddSingleton(_ =>
                            {
                                var options = new OpenApiConfigurationOptions()
                                {
                                    Info = new OpenApiInfo()
                                    {
                                        Version = "1.0.0",
                                        Title = "Swagger Petstore",
                                        Description = "This is a sample server Petstore API designed by [http://swagger.io](http://swagger.io).",
                                        TermsOfService = new Uri("https://github.com/Azure/azure-functions-openapi-extension"),
                                        Contact = new OpenApiContact()
                                        {
                                            Name = "Enquiry",
                                            Email = "azfunc-openapi@microsoft.com",
                                            Url = new Uri("https://github.com/Azure/azure-functions-openapi-extension/issues"),
                                        },
                                        License = new OpenApiLicense()
                                        {
                                            Name = "MIT",
                                            Url = new Uri("http://opensource.org/licenses/MIT"),
                                        }
                                    },
                                    Servers = DefaultOpenApiConfigurationOptions.GetHostNames(),
                                    OpenApiVersion = OpenApiVersionType.V2,
                                    IncludeRequestingHostName = true,
                                    ForceHttps = false,
                                    ForceHttp = false,
                                };

return options; }); }) / ⬆️⬆️⬆️ Add this ⬆️⬆️⬆️ / .Build();

host.Run(); } } }

1If I remember correctly, you need to pay attention to the order of service registrations, so that yours is last and thus wins.

If the hard coded values in your question are a simplification and you actually need to do this at runtime (maybe even influenced by the request/context), you might be able to achieve that through filters:

Modifying Swagger and OpenAPI documents

If the generated document needs to be modified in more complex ways, you can use an IDocumentFilter that can modify the Swagger and OpenAPI documents just before it is rendered to the client. To register such a filter you must create a class that inherits from the DefaultOpenApiConfigurationOptions class and add your IDocumentFilter to its DocumentFilters list:

public class OpenApiConfigurationOptions : DefaultOpenApiConfigurationOptions { public OpenApiConfigurationOptions() { this.DocumentFilters.Add(new ExampleDocumentFilter()); } }

This code adds the ExampleDocumentFilter class to the list of document filters. Within a document filter you access to an IHttpRequestDataObject object, which contains request data like the current host and scheme, and to the OpenApiDocument object which contains all the generated documentation.

public class ExampleDocumentFilter : IDocumentFilter { public void Apply(IHttpRequestDataObject request, OpenApiDocument document) { // TO DO } }