azure-functions-openapi-extension icon indicating copy to clipboard operation
azure-functions-openapi-extension copied to clipboard

Cryptic error message when IOpenApiConfigurationOptions.Info == null

Open rubens-farias opened this issue 3 years ago • 1 comments

Describe the issue OpenApi doesn't provide a good error message when IOpenApiConfigurationOptions is implemented but Info property isn't set.

To Reproduce Steps to reproduce the behavior:

  1. Implement IOpenApiConfigurationOptions but do not provide a value to the Info property:
public class Foo : IOpenApiConfigurationOptions
{
    public OpenApiInfo Info                  { get; set; } // HERE
    public bool ForceHttp                    { get; set; } = false;
    public bool ForceHttps                   { get; set; } = true;
    public bool IncludeRequestingHostName    { get; set; } = false;
    public List<OpenApiServer> Servers       { get; set; } = new();
    public OpenApiVersionType OpenApiVersion { get; set; } = OpenApiVersionType.V3;
}
  1. Access the /swagger/ui page
  2. Receive the cryptic, contextless error message
Object reference not set to an instance of an object.

   at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.SwaggerUI.Render(String endpoint, OpenApiAuthLevelType authLevel, String authKey)
   at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.SwaggerUI.<>c__DisplayClass28_0.<RenderAsync>b__0()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.Tasks.Task.<>c.<.cctor>b__271_0(Object obj)
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.SwaggerUI.RenderAsync(String endpoint, OpenApiAuthLevelType authLevel, String authKey)
   at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions.SwaggerUIExtensions.RenderAsync(Task`1 ui, String endpoint, OpenApiAuthLevelType authLevel, String authKey)
   at Microsoft.Azure.WebJobs.Extensions.OpenApi.OpenApiTriggerFunctionProvider.RenderSwaggerUI(HttpRequest req, ExecutionContext ctx, ILogger log)

Expected behavior An indication that is a required property and a non-null value must be informed.

Environment (please complete the following information, if applicable):

  • OS: Windows
  • Browser Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36
  • Version 1.0.0

Workaround Provide some non-null value for that property:

public class Foo : IOpenApiConfigurationOptions
{
    public OpenApiInfo Info                  { get; set; } = new(); // HERE
    public bool ForceHttp                    { get; set; } = false;
    public bool ForceHttps                   { get; set; } = true;
    public bool IncludeRequestingHostName    { get; set; } = false;
    public List<OpenApiServer> Servers       { get; set; } = new();
    public OpenApiVersionType OpenApiVersion { get; set; } = OpenApiVersionType.V3;
}

rubens-farias avatar Nov 17 '21 00:11 rubens-farias

This is still the case and the approach shown by rubens-farias works. I have tried that.

sauradiptac avatar Aug 06 '22 08:08 sauradiptac