Swashbuckle.aspnetcore: When JArray is used on response / request as datatype, generator fails with System.InvalidOperationException

Created on 10 May 2019  路  5Comments  路  Source: domaindrivendev/Swashbuckle.AspNetCore

Version: <PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc2" />

Response class:

    public class FooResponse
    {
        public JArray RowData { get; set; } // = new JArray();
    }

Controller:

        [HttpPost("/v1/x/")]
        public ActionResult<FooResponse> GetFoo()
        {
            return Ok(new FooResponse());
        }

When swagger document is requested it fails with:

fail: Microsoft.AspNetCore.Server.Kestrel[13]
      Connection id "0HLML4VELUGHU", Request id "0HLML4VELUGHU:00000002": An unhandled exception was thrown by the application.
System.InvalidOperationException: TODO:
   at Swashbuckle.AspNetCore.SwaggerGen.ChainableSchemaGenerator.GenerateSchema(Type type, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.GenerateSchema(Type type, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.ObjectSchemaGenerator.GeneratePropertySchema(JsonProperty jsonProperty, Object[] attributes, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.ObjectSchemaGenerator.GenerateSchemaFor(Type type, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.ChainableSchemaGenerator.GenerateSchema(Type type, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.ReferencedSchemaGenerator.GenerateSchemaFor(Type type, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.ChainableSchemaGenerator.GenerateSchema(Type type, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.SchemaGenerator.GenerateSchema(Type type, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.CreateResponseMediaType(Type type, SchemaRepository schemaRespository)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateResponse(String statusCode, ApiResponseType apiResponseType, IEnumerable`1 methodAttributes, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateResponses(ApiDescription apiDescription, IEnumerable`1 methodAttributes, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperation(ApiDescription apiDescription, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperations(IEnumerable`1 apiDescriptions, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GeneratePaths(IEnumerable`1 apiDescriptions, SchemaRepository schemaRepository)
   at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GetSwagger(String documentName, String host, String basePath)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)

Most helpful comment

Should be resolved by 6f9e899cfe46e8d99a12e42e378e7c03693dd1c2

All 5 comments

Should be resolved by 6f9e899cfe46e8d99a12e42e378e7c03693dd1c2

Getting error InvalidOperationException: Unable to generate schema for type - System.Exception when using FirebaseAdmin.Messaging.MulticastMessage as Controller Method parameter type.

Using https://myget.org/feed/domaindrivendev/package/nuget/Swashbuckle.AspNetCore/5.0.0-rc2-preview-0896

@binaraT did you solve this issue?

Should be resolved by 6f9e899

I was facing the same issue when integrating odata for asp.net core in comibination with swashbuckle.aspnet core 5.0.0 rc-2. Since I switched to rc3 preview from myget.org the errors are gone. I am not using odata base controller, instead the parameter of type ODataQueryOptions is beeing added as the controller's method parameter which acutally caused these errors. I've seen quiet a lot of reports rerading this odata issue. Thanks for your fix :-)!

I am still seeing an issue where Swagger does not work if you have a parameter that contains a JArray property.

Was this page helpful?
0 / 5 - 0 ratings