我正在尝试使用swagger和我的代码,但并非所有方法都在swagger-ui列出一些方法没有显示
我正在使用swagger 2.5.0版本和spring boot 2.1.0.RELEASE
我的用户休息控制器
@RestController
@RequestMapping(value = "/rest")
public class UserRestController {
@Autowired
private UserService userService;
@RequestMapping(method = RequestMethod.GET, value = "/users")
public Iterator<User> getUsers() {
return userService.getUsers();
}
@RequestMapping(method = RequestMethod.GET, value = "/user/{id}")
public User getUser(@PathVariable("id") Long id) {
return userService.getUser(id);
}
@RequestMapping(method = RequestMethod.POST, value = "/user")
public User save(@RequestBody User user) {
User userValidation = userService.getUser(user.getId());
if (userValidation != null) {
throw new IllegalAddException("username already used !");
}
return userService.save(user);
}
@RequestMapping(method = RequestMethod.DELETE, value = "/user")
public User delete(@RequestBody User user) {
return userService.save(user);
}
}
这是我的配置代码
@Configuration
@EnableSwagger2
public class SwaggerApi {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2).select()
.apis(RequestHandlerSelectors.basePackage("com.social.core.rest")).paths(PathSelectors.ant("/rest/*"))
.build().apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfo("Social API", "Soccial api for gamerz zone.", "API TOS", "Terms of service",
new Contact("yali", "www.social.com", "[email protected]"), "License of API",
"API license URL");
}
}
getUser方法没有在swagger ui中显示,并且当我点击url并且已经获取数据时该方法有效
只有三种方法显示出来
我通过在配置中添加更多星形路径来解决了这个问题
paths(PathSelectors.ant("/rest/**"))