You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to set a specific consumes / produces Type for multiple Mappings.
I know that i can set them like this:
@PostMapping( "/testPostMapping", consumes = { MediaType.APPLICATION_CBOR_VALUE } )
but then i have to add consumes and produces to every Mapping method.
I have an Controller Class which sets produces for all my RequestMappings
@RequestMapping( produces = { MediaType.APPLICATION_XML_VALUE, MediaType.APPLICATION_JSON_VALUE } )
public abstract class Controller
{
}
I extend this Controller and have some Mappings inside it.
public class ExampleController extends Controller
{
@GetMapping( value = "/getTest" )
public @ResponseBody ResponseEntity<String> testGetMapping()
{
return new ResponseEntity<String>( "TestString", HttpStatus.OK );
}
@PostMapping( "/testPostMapping" )
public @ResponseBody ResponseEntity<String> testPostMapping( String testString )
{
return new ResponseEntity<String>( "TestString", HttpStatus.OK );
}
}
Now i only want to set the consumes Type to the PostMapping.
What i already tried
I already tried to add The @ApiResponse Annotation
but this will override the content Type of my Requests
if i add this to two @PostMappings , and one Returns a String the other one Returns an HTML element
@ApiResponse will override the schema type information
What i am trying to do
I am trying to set a specific consumes / produces Type for multiple Mappings.
I know that i can set them like this:
@PostMapping( "/testPostMapping", consumes = { MediaType.APPLICATION_CBOR_VALUE } )
but then i have to add consumes and produces to every Mapping method.
I have an Controller Class which sets produces for all my RequestMappings
I extend this Controller and have some Mappings inside it.
Now i only want to set the consumes Type to the PostMapping.
What i already tried
I already tried to add The @ApiResponse Annotation
but this will override the content Type of my Requests
if i add this to two @PostMappings , and one Returns a String the other one Returns an HTML element
@ApiResponse will override the schema type information
Without the ApiResponse Annotation
With the ApiResponse Annotation
How i attampted it
I made my own Annotations
and extended the WebMvcConfig RequestMappingHandler
So that if i add
@DefaultProduces
to a RequestMapping it will have the MediaTypes which i added thereI overrode the RequestMappingInfo with my customized infos.
But OpenAPI does not take the Informations from RequestMappingInfo .
Describe the solution you'd like
Is there a way to let openAPI get his Informations from the RequestMappingInfo.
Or is there an Annotation like Request
@ApiResponse
where i can only set the consumes or produces Types without chaning anything else.** TestProject **
In my TestProject is a Controller with a PostMapping like this
My annotation DefaultConsomes makes the PostMapping only accapt text/plain
The OpenAPI Json still says that the content is /
which leads to the following Curl request in Swagger-ui
The PostMapping will response with
If text/plain is set it is working.
should output "TestString"
Here is a basic Project with my issue
https://github.com/T-Developer1/SpringdocCustomAnnotationSample
Additional Informations
In OpenApiResources the consumes and Produces are correct
springdoc-openapi/springdoc-openapi-webmvc-core/src/main/java/org/springdoc/webmvc/api/OpenApiResource.java
Lines 216 to 217 in 378edcf
but the Informations get lost after that
In AbstractOpenApiResources produces and consumes are null
springdoc-openapi/springdoc-openapi-common/src/main/java/org/springdoc/api/AbstractOpenApiResource.java
Lines 397 to 398 in 378edcf
And even if you change the value there, it will be overriden again in MethodAttribute
springdoc-openapi/springdoc-openapi-common/src/main/java/org/springdoc/core/MethodAttributes.java
Lines 228 to 232 in 378edcf
The text was updated successfully, but these errors were encountered: