Skip to content
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

OpenApiResponseWithBody fails to serialize object #588

Open
michaelelleby opened this issue Jun 15, 2023 · 1 comment · May be fixed by #611
Open

OpenApiResponseWithBody fails to serialize object #588

michaelelleby opened this issue Jun 15, 2023 · 1 comment · May be fixed by #611

Comments

@michaelelleby
Copy link

michaelelleby commented Jun 15, 2023

Describe the issue
Swagger JSON fails to generate when using OpenApiResponseWithBody attribute.

To Reproduce
Steps to reproduce the behavior:

  1. dotnet openapi add url https://developer.swift.com/sites/default/files/specs/Swift-Messaging-API-v1.0.0.yaml
  2. Add Function with HTTP trigger and attributes [OpenApiOperation] and [OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, bodyType: typeof(ListDistributionsResponse), contentType: "application/json")]
  3. Open generated Swagger JSON URI at http://localhost:7097/api/swagger.json

Expected behavior
Swagger JSON is generated correctly.

Screenshots
If applicable, add screenshots to help explain your issue.

Environment (please complete the following information, if applicable):

  • OS: [e.g. Windows/Mac/Linux] Windows
  • Browser [e.g. edge, chrome, firefox, safari] Firefox
  • Version [e.g. 22] Tried both 1.5.1 and 2.0.0-preview2

Additional context
https://github.com/michaelelleby/azure-functions-openapi-extension-bugreport is a small project demonstrating the issue.

This is the response from the Swagger JSON page:

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, KeyValuePair`2 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, Dictionary`2 properties, NamingStrategy namingStrategy)
   at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Visitors.ObjectTypeVisitor.Visit(IAcceptor acceptor, KeyValuePair`2 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.ListObjectTypeVisitor.Visit(IAcceptor acceptor, KeyValuePair`2 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, Dictionary`2 properties, NamingStrategy namingStrategy)
   at Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Visitors.ObjectTypeVisitor.Visit(IAcceptor acceptor, KeyValuePair`2 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(List`1 elements, NamingStrategy namingStrategy, VisitorCollection collection)
   at Microsoft.Azure.WebJobs.Extensions.OpenApi.Document.Build(Assembly assembly, OpenApiVersionType version)
   at Microsoft.Azure.WebJobs.Extensions.OpenApi.OpenApiTriggerFunctions.RenderSwaggerDocument(OpenApiHttpTriggerContext openApiContext, HttpRequest req, String extension, ExecutionContext ctx, ILogger log)

Removing the line [OpenApiResponseWithBody(statusCode: HttpStatusCode.OK, bodyType: typeof(ListDistributionsResponse), contentType: "application/json")] makes the problem go away, however I need this to make the return type of the API available to users.

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