azure-functions-openapi-extension icon indicating copy to clipboard operation
azure-functions-openapi-extension copied to clipboard

Bug report - OpenApiRequestBody not able to serialise the JsonObject datatype

Open Balaji-kn opened this issue 3 years ago • 6 comments

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:

  1. Create new Azure Function POST API
  2. Add OpenApiRequestBody attribute with customModel
  3. In Model, use JsonObject for one the parameter.
  4. Run the application
  5. 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 image

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 avatar Mar 02 '22 12:03 Balaji-kn

@Balaji-kn Thanks for the issue! System.Text.Json isn't supported yet.

justinyoo avatar Mar 02 '22 12:03 justinyoo

#154

justinyoo avatar Mar 02 '22 12:03 justinyoo

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.

mujtabashareef avatar Jul 14 '22 17:07 mujtabashareef

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

pondchamp avatar Nov 26 '23 20:11 pondchamp

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.

robertjf avatar Mar 28 '24 02:03 robertjf