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

"parameters" => Cannot cast Newtonsoft.Json.Linq.JObject to Newtonsoft.Json.Linq.JToken.

Open dluc opened this issue 3 years ago • 1 comments

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
image

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

dluc avatar Dec 08 '22 08:12 dluc

Problem still persists in version 1.5.1 and 2.0.0-preview2

qbq-ber-m-moeller avatar Jan 01 '25 21:01 qbq-ber-m-moeller