6

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\": test@gmail.Com,"
                                        + "\"firstName\": \"josh\","
                                        + "\"lastName\": \"spring...\""
                                        + "}")
        }))

I get below excptiontion -

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

Can anyone give me a solution please?
Koziołek
  • 2,791
  • 1
  • 28
  • 48
Rabin Mallilck
  • 431
  • 6
  • 13

1 Answers1

8

This worked for me

@Schema( type = "string", example = "Clark Kent")
private String name;
Rabin Mallilck
  • 431
  • 6
  • 13