OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
22.06k stars 6.62k forks source link

[BUG][JAVA] Multiple response media types causing wrong @RequestMapping(produces=example) #19818

Open jgarciasm opened 1 month ago

jgarciasm commented 1 month ago

Bug Report Checklist

Description

I have an openapi specification that contains an endpoint with 2 possible responses (201 and 4xx). Each one has a media type different. When it is generated the api code it is generated something like this:

https://gist.github.com/jgarciasm/5853cf0dac2a2eb597981db065574f60

That code generates the following error when trying to run/debug:

´´´ org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]: Invalid mapping on handler class [package.EntityApiController]: public org.springframework.http.ResponseEntity package.EntityApiController.postEntity() ´´´

openapi-generator version
OpenAPI declaration file content or url

https://gist.github.com/jgarciasm/c9e7a3723678d14ab044cadddcaa522d

Generation Details

It is generated an api with @RequestMapping.value with the 2 media types sepparated by ",". That is an error, should be separated by ";".

Steps to reproduce

Using ´´´org.openapitools.codegen.languages.SpringCodegen´´´. Within any spec place 2 possible responses, both with different media types (as in the example).

Suggest a fix

The problem is being cause because of the "," to separate the 2 media types, it should be ",".

jgarciasm commented 1 month ago

Fixed Gist links.