Azure / azure-functions-openapi-extension

This extension provides an Azure Functions app with Open API capability for better discoverability to consuming parties
https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.OpenApi/
MIT License
373 stars 195 forks source link

Support Specification Extensions #638

Open iwaldman opened 10 months ago

iwaldman commented 10 months ago

Do you support or have plans to support Specification Extensions?

For example, I need to include the x-ms-openai-data internal property to help Power Platform do its required processing:

image

iwaldman commented 10 months ago

I was able to implement support for info and operations extensions via the IDocumentFilter.


public class DocumentFilter : IDocumentFilter
{
    public void Apply(IHttpRequestDataObject request, OpenApiDocument document)
    {
        if (!document.Info.Extensions.ContainsKey("x-ms-keywords"))
        {
            document.Info.Extensions.Add(
                "x-ms-keywords",
                new OpenApiArray { new OpenApiString("Acme") }
            );
        }

        var paths = document.Paths;
        foreach (var path in paths)
        {
            var pathItem = path.Value;
            foreach (var operation in pathItem.Operations)
            {
                var operationItem = operation.Value;
                if (!operationItem.Extensions.ContainsKey("x-ms-openai-data"))
                {
                    operationItem.Extensions.Add(
                        "x-ms-openai-data",
                        new OpenApiObject { { "openai-enabled", new OpenApiBoolean(true) } }
                    );
                }
            }
        }
    }
}
` ``