为什么Swagger没有在同一个类中显示所有方法?

问题描述 投票:0回答:1

我正在尝试使用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并且已经获取数据时该方法有效

只有三种方法显示出来

spring spring-boot swagger swagger-ui swagger-2.0
1个回答
0
投票

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

paths(PathSelectors.ant("/rest/**"))
© www.soinside.com 2019 - 2024. All rights reserved.