我有一个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
。因此,“试用”功能当然没有任何意义。看起来像这样:
那是为什么,我该如何解决?
答案 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}")