Swagger UI不显示Params

时间:2018-11-14 16:54:55

标签: spring http spring-boot swagger-ui

我有一个Spring-Application(2.1.0.RELEASE),并添加了Swagger和Swagger-UI(2.9.2)。

我有一个SwaggerConfig类,是我从Baeldung tutorial复制过来的

然后是App类:

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
@EnableAutoConfiguration
public class App
{
    public static void main(String[] args) throws Exception {
        SpringApplication.run(App.class, args);
    }
}

并且有实际的REST控制器:

@RestController
public class TweetRating {

    @GetMapping("/{userid}/tweet")
    public static void getTweet(@PathVariable String userid){
        System.out.println("UserID: "+ userid);
    }

    @GetMapping("/")
    public static void isWorking(@RequestParam String id){
        System.out.println("ID: "+ id);
    }
}

Swagger-UI不会显示方法的参数。 PathVariable都不是RequestParam。因此,“试用”功能当然没有任何意义。看起来像这样:

Screenshot1 Screenshot2

那是为什么,我该如何解决?

1 个答案:

答案 0 :(得分:1)

尝试在SwaggerConfig中应用enableUrlTemplating(true)

@Configuration
@EnableSwagger2
public class SwaggerConfig {                                    
    @Bean
    public Docket api() { 
        return new Docket(DocumentationType.SWAGGER_2)  
          .select()                                  
          .apis(RequestHandlerSelectors.any())              
          .paths(PathSelectors.any())  
          .enableUrlTemplating(true)                        
          .build();                                           
    }

也试试这个:

@ApiOperation(value = "Dexcription of endpoint")
@RequestMapping
public String doSomething(@ApiParam(value = "Description of path vaiable")@PathVariable("/{code}")