Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 3630

Generating Swagger UI from java, providing example for a RequestBody doesn't work

$
0
0

how do I provide an example for the body of a request in my Swagger UI?I am using Springboot as a framework.This is the smallest java code to reproduce the problem:

import org.springframework.http.ResponseEntity;import org.springframework.web.bind.annotation.PostMapping;import org.springframework.web.bind.annotation.RequestBody;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;import io.swagger.v3.oas.annotations.Operation;import io.swagger.v3.oas.annotations.media.Content;import io.swagger.v3.oas.annotations.media.ExampleObject;@RestController@RequestMapping("/api/my/problem")public class MyProblemResource {    @PostMapping(value = "/")    @Operation(summary = "Create person")    public ResponseEntity<PersonDTO> getPerson(            @io.swagger.v3.oas.annotations.parameters.RequestBody(                    description = "the person you want to create, in json format",                    content = @Content(examples = @ExampleObject( value = "foobar"))                    )            @RequestBody PersonDTO person){        return ResponseEntity.ok().build();    }}class PersonDTO{    String firstName;    String lastName;    public PersonDTO() {}    public String getFirstName() {        return firstName;    }    public void setFirstName(String firstName) {        this.firstName = firstName;    }    public String getLastName() {        return lastName;    }    public void setLastName(String lastName) {        this.lastName = lastName;    }}

So I would expect the string "foobar" to appear in the generated Swagger UI, but it doesn't:the text in the black box should be "foobar"

Edit: I've also tried putting the annotation at the method level as suggested by https://stackoverflow.com/users/1076463/robin, like this: https://pastebin.com/FPGHuYKd , still no luck.

By the way, those annotations come from a dependency in my Maven pom.xml :

<dependency><groupId>io.springfox</groupId><artifactId>springfox-boot-starter</artifactId><version>3.0.0</version></dependency>

Viewing all articles
Browse latest Browse all 3630

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>