Skip to content

"Index was outside the bounds of the array" OpenApiResponseWithBody List #380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
vrooijen opened this issue Mar 2, 2022 · 10 comments
Open

Comments

@vrooijen
Copy link

vrooijen commented Mar 2, 2022

Microsoft.Azure.Webjobs.Extensions.OpenApi 1.2.0
.NET Core 3.1

I tried

[OpenApiResponseWithBody(HttpStatusCode.BadRequest, MediaTypeNames.Application.Json, typeof(ValidationResponse))]

but got

Index was outside the bounds of the array.

   at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions.TypeExtensions.GetOpenApiSubTypeName(Type type, NamingStrategy namingStrategy)
   at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions.TypeExtensions.GetOpenApiDescription(Type type)
   at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions.OpenApiResponseWithBodyAttributeExtensions.ToOpenApiResponse(OpenApiResponseWithBodyAttribute attribute, NamingStrategy namingStrategy, VisitorCollection collection, OpenApiVersionType version)
   at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.DocumentHelper.<>c__DisplayClass7_0.<GetOpenApiResponses>b__1(OpenApiResponseWithBodyAttribute p)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Linq.Enumerable.ConcatIterator`1.MoveNext()
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
   at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.DocumentHelper.GetOpenApiResponses(MethodInfo element, NamingStrategy namingStrategy, VisitorCollection collection, OpenApiVersionType version)
   at Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Build(Assembly assembly, OpenApiVersionType version)
   at Microsoft.Azure.WebJobs.Extensions.OpenApi.OpenApiTriggerFunctionProvider.RenderSwaggerDocument(HttpRequest req, String extension, ExecutionContext ctx, ILogger log)

The response type can be as easy as the following, as long as it is a collection.

public class ValidationResponse : List<string>
{
}

When specifying directly it works, however I want to type it.

[OpenApiResponseWithBody(HttpStatusCode.BadRequest, MediaTypeNames.Application.Json, typeof(List<string>))]
@mujtabashareef
Copy link

vrooijen did you find a solution to this? I am facing the same error.

@vrooijen
Copy link
Author

vrooijen did you find a solution to this? I am facing the same error.

Yes, specify the type directly, as described on the last line. However this is not a solution for my question, more a kind of workaround

@HaakonSvane
Copy link

This bug seems to occur not only with lists. I just encountered the same bug when the bodyType is set totypeof(Microsoft.Graph.Event) as well.

@briandunnington
Copy link

Appears to be the similar to #313 - I think the root cause is here:

(at least for the Dictionary case - likely a few lines down for the List case). In both cases, it assumes an array index that appears to be wrong.

@archubbuck
Copy link

I'm running into this same issue with Microsoft.Graph.User

@danmcpherson
Copy link

I have this issue with Lists<>. I don't see any movement here really, and it's quite the blocker given there is no workaround.

@Qualizorg
Copy link

Agree, would be nice to have a solid solution.

@AJMauger
Copy link

Here is a working example https://github.com/AJMauger/sunstealer.azure.functions.

Note Model1.cs this defines an Example Model, note OpenApiCustomUIOptions.cs this maps example to open API 3 doc schema. Note Function1.cs this binds the Example to the API.

@Shuvajyoti
Copy link

Facing similar exception while using System.Text.Json as the serialization/deserialization library. Is there any solution for this yet.

@pondchamp
Copy link

This issue appears to be related: #588

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants