When JArray is used on response / request as datatype, generator fails with System.InvalidOperationException
See original GitHub issueVersion: <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)
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
c# - Deserialize JSON to array giving System. ...
Your problem can occur when Deserialize() cannot create a new instance of the object your are deserializing. In order to make Deserialize() ...
Read more >Migrate from Newtonsoft.Json to System.Text.Json - .NET
Supported by built-in functionality. Getting similar behavior from System.Text.Json may require the use of an attribute or global option.
Read more >Working with System.Text.Json in C# - CodeProject
As the Converter is strongly typed, if you try to use the converter on the wrong data type, a System.InvalidOperationException will be thrown...
Read more >Cannot cast type json to integer
JArray ' The thing is it was working. (millisecond precision) In this section, we will use the CAST function to convert the data...
Read more >SSIS Productivity Pack
Fixed: CDM source component may make repetitive failed service calls to retrieve the list of partitions when the specified path does not exist...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Should be resolved by 6f9e899cfe46e8d99a12e42e378e7c03693dd1c2
I am still seeing an issue where Swagger does not work if you have a parameter that contains a JArray property.