为什么Swagger不显示同一类中的所有方法?

时间:2019-04-05 15:32:58

标签: spring spring-boot swagger swagger-ui swagger-2.0

我正尝试在代码中使用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", "prg@gmail.com"), "License of API",
                "API license URL");
    }
}

getUser方法未在swagger ui中显示,当我点击url并已获取数据时,该方法有效

仅显示三种方法

1 个答案:

答案 0 :(得分:0)

我通过使用config在路径中添加更多星形来解决了这个问题

paths(PathSelectors.ant("/rest/**"))