I’m using Umbraco Engage Headless API and generating Swagger docs with .AddEngageApiDocumentation() in .NET 8 and Umbraco 13.8.
When I run the Swagger generation of the Engage API, I get the following exception:
An unhandled exception has occurred while executing the request.
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorException: Failed to generate Operation for action - Umbraco.Engage.Headless.Api.v1.Analytics.PageEventApiController.TrackPageEvent (Umbraco.Engage.Headless). See inner exception
—> Swashbuckle.AspNetCore.SwaggerGen.SwaggerGeneratorException: Failed to generate schema for type - Microsoft.AspNetCore.Mvc.StatusCodeResult. See inner exception
—> System.InvalidOperationException: Can’t use schemaId “$Task1" for type "$System.Threading.Tasks.Task1[TResult]”. The same schemaId is already used for type “$System.Threading.Tasks.Task`1[System.Boolean]”
at Swashbuckle.AspNetCore.SwaggerGen.SchemaRepository.RegisterType(Type type, String schemaId)
It looks like Swashbuckle is trying to generate schemas for all generic system classes (Task<T>, ActionResult<T>, StatusCodeResult, etc.), which causes schema ID collisions and makes the Swagger doc extremely bloated. I’ve tried by adding a incremented ID to the type name and got all kind of generic models:
Has anyone experienced anything similar? I can’t work with all these generics models since the swagger.json is used by the frontend to generate their models.
