Azure / Azure/azure-functions-openapi-extension
"parameters" => Cannot cast Newtonsoft.Json.Linq.JObject to Newtonsoft.Json.Linq.JToken.
- Dominant language
- C#
- Stars
- 388
- Forks
- 202
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the issue**
While adding OpenApi to an Azure Function using `[OpenApiResponseWithBody ... bodyType: typeof(List) ...]`, 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.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
Contributor guide
Research direction
Reproduce the failure with OpenApiResponseWithBody using bodyType List and the JsonProperty name "parameters". Start at Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Render, then trace the parameter handling shown in the stack trace. Done means Swagger UI renders successfully without the JObject-to-JToken exception while retaining the property name.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp, openapi
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100