OpenAPITools / OpenAPITools/openapi-generator
[BUG] [aspnetcore] Problem when using several identical schemas in request
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The swagger UI is not accessible, due to 3 similar object types in the test method
public virtual IActionResult TestPost(IFormFile bin, [FromForm]Vec3 location, [FromForm]Vec3 roation, [FromForm]Vec3 scale)
The resulting error:
`Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware: Error: An unhandled exception has occurred while executing the request.
System.ArgumentException: An item with the same key has already been added. Key: X
at System.Collections.Generic.Dictionary'2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateSchemaFromFormParameters(IEnumerable'1 formParameters, SchemaRepository schemaRepository)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateRequestBodyFromFormParameters(ApiDescription apiDescription, SchemaRepository schemaRepository, IEnumerable'1 formParameters)
at Swashbuckle.AspNetCore.SwaggerGen.SwaggerGenerator.GenerateRequestBody(ApiDescription apiDescription, 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.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)`
openapi-generator version
5.1.1 and tested with 5.2.0 snapshot from 29.06
OpenAPI declaration file content or url
https://gist.github.com/tschumacher93/9abcf1ddbc839eddbc804cd5f9760efb
Generation Details
I just used the following command to generate the server files:
java -jar ..\openapi-generator-cli.jar generate -i ..\openapi.json -g aspnetcore -o .
Steps to reproduce
1.) Generate code
2.) Adjust Startup.cs and Program.cs, so that the restapi is runnable
3.) open swagger page
Related issues/PRs
Suggest a fix
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the generated aspnetcore project from the linked OpenAPI declaration with the stated Java CLI command, then inspect Startup.cs, Program.cs, and the Swagger page. Trace the duplicate-key exception from Swashbuckle's GenerateSchemaFromFormParameters for the three Vec3 form parameters. Done means the Swagger page loads without this exception for the reported endpoint.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100