Azure / Azure/azure-functions-openapi-extension

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

Open
#380 10 comments 6 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
388
Forks
202
PR merge metrics
No merged PRs in 30d

Description

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

I tried
```c#
[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.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.
```c#
public class ValidationResponse : List
{
}
```

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

```c#
[OpenApiResponseWithBody(HttpStatusCode.BadRequest, MediaTypeNames.Application.Json, typeof(List))]
```

Contributor guide

Open the contributing guide

Research direction

Start at TypeExtensions.GetOpenApiSubTypeName, using the stack trace from OpenApiResponseWithBodyAttributeExtensions.ToOpenApiResponse as the entry path. Reproduce the failure with a typed ValidationResponse collection and compare it with the working List case; done means the typed collection no longer throws while generating the OpenAPI response.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, openapi
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.