azure-functions-openapi-extension
azure-functions-openapi-extension copied to clipboard
Bug report - OpenApiRequestBody not able to serialise the JsonObject datatype
Describe the issue OpenApiRequestBody not able to serialise the JsonObject datatype (System.Text.Json.Nodes) in version 1.2.0 .
To Reproduce Steps to reproduce the behavior:
- Create new Azure Function POST API
- Add OpenApiRequestBody attribute with customModel
- In Model, use JsonObject for one the parameter.
- Run the application
- See error
Expected behavior OpenApiRequestBody should able to serialise the JsonObject data type and should able to generate the swagger.json file and swagger UI.
Screenshots

Index was outside the bounds of the array.
at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Extensions.TypeExtensions.GetUnderlyingType(Type type)
at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Visitors.ListObjectTypeVisitor.Visit(IAcceptor acceptor, KeyValuePair2 type, NamingStrategy namingStrategy, Attribute[] attributes) at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Visitors.OpenApiSchemaAcceptor.Accept(VisitorCollection collection, NamingStrategy namingStrategy) at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Visitors.ObjectTypeVisitor.ProcessProperties(IOpenApiSchemaAcceptor instance, String schemaName, Dictionary2 properties, NamingStrategy namingStrategy)
at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Visitors.ObjectTypeVisitor.Visit(IAcceptor acceptor, KeyValuePair2 type, NamingStrategy namingStrategy, Attribute[] attributes) at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Visitors.OpenApiSchemaAcceptor.Accept(VisitorCollection collection, NamingStrategy namingStrategy) at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.DocumentHelper.GetOpenApiSchemas(List1 elements, NamingStrategy namingStrategy, VisitorCollection collection)
at Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Document.Build(Assembly assembly, OpenApiVersionType version)
at Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Functions.OpenApiTriggerFunction.RenderSwaggerDocument(HttpRequestData req, String extension, FunctionContext ctx)
Environment (please complete the following information, if applicable):
- OS: [Mac]
- Browser [chrome]
- Version [1.2.0, 1.1.0]
@Balaji-kn Thanks for the issue! System.Text.Json isn't supported yet.
#154
Is there a workaround if I am still using System.Text.Json? I want to be able to display a custom example for a property of type JsonObject.
Is there a workaround if I am still using System.Text.Json? I want to be able to display a custom example for a property of type
JsonObject.
I was able to work around this issue by replacing OpenApi references to JsonObject with Dictionary<string, object> since those are interchangeable in my case
I am seeing this issue on .net8 in an Isolated mode FunctionApp with the following:
[OpenApiRequestBody(contentType: "application/json", bodyType: typeof(EvidenceUpload), Required = true, Description = "Describes the evidence to be uploaded")]
Model:
public class EvidenceUpload
{
public int ActivityId { get; set; }
public required string EvidenceName { get; set; }
public required IFormFile File { get; set; }
}
Removing public required IFormFile File { get; set; } from the above object works, but with it we get the "Index was outside the bounds of the array." error.