Skip to content

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

@vrooijen

Description

@vrooijen

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>))]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions