Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Springdoc Openapi - Add Response Example Value

I'm trying to add example response values to my springdoc-openapi swagger documentation.

Like replace the "string" with "Mark Twain" etc.

enter image description here

I tried using this solution - springdoc-openapi: How to add example of POST request?

I'm already using org.springframework.web.bind.annotation.RequestBody in my class.

If I use this -

@io.swagger.v3.oas.annotations.parameters.RequestBody(content = @Content(examples = {
                @ExampleObject(
                        name = "Person sample",
                        summary = "person example",
                        value =
                                "{\"email\": [email protected],"
                                        + "\"firstName\": \"josh\","
                                        + "\"lastName\": \"spring...\""
                                        + "}")
        }))

I get below exception -

no viable alternative at input ',@io.swagger.v3.oas.annotations.parameters.RequestBody(content=@Content(examples={@ExampleObject(name="Person sample",summary="person example",value="{\"email\": [email protected],"+"\"firstName\": \"josh\","+"\"lastName\": \"spring...\""+"}")})))': NoViableAltException

Can anyone give me a solution please?

like image 727
Rabin Mallilck Avatar asked Jul 22 '26 23:07

Rabin Mallilck


1 Answers

This worked for me

@Schema( type = "string", example = "Clark Kent")
private String name;
like image 145
Rabin Mallilck Avatar answered Jul 24 '26 14:07

Rabin Mallilck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!