azure-functions-openapi-extension
azure-functions-openapi-extension copied to clipboard
Parameters set to the type of `List<int>` do not bind properly
Describe the issue
Parameters set to the type of List<int>
do not bind properly. I suspect that I'm missing something?
Expected behavior
I would expect the id
parameter to map to an array without using the strategy demonstrated in the screenshots below.
Screenshots
Setting the Id
property of NotificationListRequest
results in the following:
@justinyoo, is this something you might be able to advise on?
Your issue comes from Azure Functions limitations and not from Open API document generation that is provided by this repository and NuGet package. Most developers who start working with Azure Functions and have some ASP.NET experience under their belt encounter this issue sooner or later because we are accustomed to advanced model binding features like [FromQuery]
, [FromPath]
or [FromBody]
attributes. Although Azure Functions .NET in-process model references and leverages few ASP.NET Core types like Microsoft.AspNetCore.Http.HttpRequest
or Microsoft.AspNetCore.Http.HttpContext
it does not provide the same rich web application features like ASP.NET does. Azure Functions is a much more generic, lightweight and not so deeply web focused technology, instead it focuses heavily on event driven Azure service integrations with plenty of triggers and bindings. The problem with differentiating what Azure Functions supports and what it does not was so prevalent that in the new out-of-process hosting model Azure Functions does not reference ASP.NET types and it provides its own HTTP related types such as Microsoft.Azure.Functions.Worker.Http.HttpRequestData
or Microsoft.Azure.Functions.Worker.Http.HttpResponseData
.
Simply put, you have encountered HttpTrigger
model binding limitation and you'll have to some workaround stuff to keep your code clean and without boilerplate. From my point of view, you have three options from most advanced (but cleanest) to least advanced (but with lots of boilerplate):
- Write your own binding that supports your model binding scenarios, here's an example
- Do some manual string manipulation (that's what you did in your code, you've split a string into an array of integers)
- Work directly with
Microsoft.AspNetCore.Http.HttpRequest.Query
and parse your query string manually
You're not the first person to encounter this issue, you can read more in the Azure Functions host repository, here's a similar issue.