Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger - Setting Default media-type or Accept Header for responses

I'm setting my API to produce both JSON And XML for POST requests, with this spring boot code:

@PostMapping(
    consumes = { APPLICATION_JSON_VALUE, APPLICATION_XML_VALUE },
    produces = { APPLICATION_JSON_VALUE, APPLICATION_XML_VALUE }
)
public Game create(
        @Valid @RequestBody Game request,
        BindingResult bindingResult
) .../

This is working fine, and I can select either JSON or XML as the media-type in Swagger, but I want the default field to be JSON - at the moment it is always XML:

enter image description here

How can I achieve this?

like image 665
JamesWillett Avatar asked Sep 03 '25 06:09

JamesWillett


1 Answers

Add the following property to application.properties:

springdoc.default-produces-media-type=application/json

For reference: springdoc.org

EDIT:

This solution is only applicable to springdoc-openapi java library.

like image 71
Toni Avatar answered Sep 04 '25 21:09

Toni