Open Moseyza opened 6 months ago
fails to generate the swagger.json file for the endpoint
fails to document the endpoint with multiple IFormFile parameters
Can you clarify which it is please?
Is it creating a swagger.json file with a missing operation, or is it failing to generate the document at all?
If the latter, what exceptions/errors are logged by the server, if any?
It throws this exception:
ArgumentException: An item with the same key has already been added. Key: ContentType
Could you provide the full stack trace please? Then it should be much easier for us to find the source of the problem.
An unhandled exception occurred while processing the request. ArgumentException: An item with the same key has already been added. Key: ContentType System.Collections.Generic.Dictionary<TKey, TValue>.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
SwaggerGeneratorException: Failed to generate Operation for action - TestApiForTestingSwashbuckle.Controllers.WeatherForecastController.DummyAction (TestApiForTestingSwashbuckle). See inner exception Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateOperation(ApiDescription apiDescription, SchemaRepository schemaRepository)
Stack:
ArgumentException: An item with the same key has already been added. Key: ContentType
System.Collections.Generic.Dictionary<TKey, TValue>.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
System.Collections.Generic.Dictionary<TKey, TValue>.Add(TKey key, TValue value)
Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateSchemaFromFormParameters(IEnumerable
[Uploading SampleProject.zip…]()
Thanks. In future for GitHub issues, please provide details as text not screenshots. Text is much more useful for others as it can be searched, indexed, copied etc.
Turns out this is "expected" behaviour.
We might be able to improve this scenario anyway though so if it still fails it's at least more informative.
Thank you @martincostello. removing FromForm attributes obviates the exception and also files become uploaded without problem.
When defining an API endpoint in an ASP.NET Core Web API with multiple parameters of type IFormFile, the Swagger generator fails to generate the swagger.json file for the endpoint. The issue occurs when attempting to upload multiple files using IFormFile parameters in the API action.
Steps to Reproduce:
Code Snippet: