JamesWillett
JamesWillett

Reputation: 1041

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?

Upvotes: 3

Views: 6820

Answers (1)

Toni
Toni

Reputation: 5165

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.

Upvotes: 8

Related Questions