Azure / Azure/azure-functions-openapi-extension

OpenApiResponseWithBody containing property named `parameters` throws exception

Open
#474 9 comments 0 reactions 0 assignees View on GitHub
Needs: Triage (Functions)
Dominant language
C#
Stars
388
Forks
202
PR merge metrics
No merged PRs in 30d

Description

**Describe the issue**
Using a class that contains a property named `parameters` in the `OpenApiResponseWithBody` attribute crashes the `../swagger.json` endpoint.

Using version `1.3.0`.

**To Reproduce**
Decorate a function with this:
```c#
[OpenApiOperation]
[OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, contentType: "application/json", bodyType: typeof(Output))]
```

The class `Output` looks like this
```c#
public class Output
{
public string parameters { get; set; }
}
```

Returns this when calling `/swagger.json` endpoint:
```
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.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.OpenApiTriggerFunctionProvider.RenderSwaggerDocument(HttpRequest req, String extension, ExecutionContext ctx, ILogger log)
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.