Azure / Azure/azure-functions-openapi-extension
Cryptic error message when IOpenApiConfigurationOptions.Info == null
- Dominant language
- C#
- Stars
- 388
- Forks
- 202
- PR merge metrics
- No merged PRs in 30d
Description
**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 Servers { get; set; } = new();
public OpenApiVersionType OpenApiVersion { get; set; } = OpenApiVersionType.V3;
}
```
2. Access the ``/swagger/ui`` page
3. 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.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 Servers { get; set; } = new();
public OpenApiVersionType OpenApiVersion { get; set; } = OpenApiVersionType.V3;
}
```
Contributor guide
Research direction
Start at the SwaggerUI.Render entry point named in the stack trace and reproduce the issue by opening /swagger/ui with an IOpenApiConfigurationOptions implementation whose Info property is unset. Trace the null value to the error response; done means the response clearly identifies Info as required and needing a non-null value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100