azure-functions-openapi-extension
azure-functions-openapi-extension copied to clipboard
"parameters" => Cannot cast Newtonsoft.Json.Linq.JObject to Newtonsoft.Json.Linq.JToken.
Describe the issue
While adding OpenApi to an Azure Function using [OpenApiResponseWithBody ... bodyType: typeof(List<MyFoo>) ...], I hit this exception, which breaks the entire Swagger UI:
Cannot cast Newtonsoft.Json.Linq.JObject to Newtonsoft.Json.Linq.JToken.
After commenting one line of code at a time I found that the exception is caused by the "parameters" string used in this attribute:
[JsonProperty(PropertyName = "parameters")]
If I change the name to something else, the exception disappears, e.g. this works
[JsonProperty(PropertyName = "parameterss")] // extra "s" at the end
Expected behavior The property name "parameters" should not cause exceptions.
Stack trace
Cannot cast Newtonsoft.Json.Linq.JObject to Newtonsoft.Json.Linq.JToken.
at Newtonsoft.Json.Linq.Extensions.Convert[T,U](T token)
at Newtonsoft.Json.Linq.Extensions.Convert[T,U](IEnumerable`1 source)+MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
at System.Linq.Enumerable.WhereEnumerableIterator`1.ToList()
at Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Render(OpenApiSpecVersion version, OpenApiFormat format)
at Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.<>c__DisplayClass18_0.<RenderAsync>b__0()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.<>c.<.cctor>b__272_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.Document.RenderAsync(OpenApiSpecVersion version, OpenApiFormat format)
at Microsoft.Azure.WebJobs.Extensions.OpenApi.OpenApiTriggerFunctions.RenderSwaggerDocument(OpenApiHttpTriggerContext openApiContext, HttpRequest req, String extension, ExecutionContext ctx, ILogger log)
Environment (please complete the following information, if applicable):
- OS: Mac
- Version: Microsoft.Azure.WebJobs.Extensions.OpenApi 1.4.0
Problem still persists in version 1.5.1 and 2.0.0-preview2