【问题标题】:Swagger (Springfox) only finding Models used in Controller @RequestBody (Spring Boot)Swagger (Springfox) 仅查找 Controller @RequestBody (Spring Boot) 中使用的模型
【发布时间】:2020-04-11 20:05:13
【问题描述】:

基本上,我感兴趣的是,Swagger 在 swagger-ui 中显示的唯一模型是否是 RestController 方法中使用的模型。它检测到我用@RequestBody 填充的两个 DTO,但它没有检测到用户模型,即使使用 ApiModel 注释也是如此。如何在不使用虚拟控制器方法的情况下解决这个问题?

例如:

@PostMapping("/signin")
@ApiOperation
public String login(
        @ApiParam(value = "The login credentials DTO (username and password)", required = true) 
        @RequestBody
        @Valid LoginCredentialsDTO loginCredentialsDTO) {
    return userService.login(loginCredentialsDTO);
}

它检测到模型“LoginCredentialsDTO”,因为它在此处用于控制器方法中。

由于我只在我的控制器中使用 DTO,它没有检测到我的主模型(用户)。我不想为了让 Swagger 能够检测到我的所有模型而制作一个虚拟方法。

【问题讨论】:

  • Swagger 描述了你的 api 的外部接口。当您的用户模型未在外部使用时,将不可见。另见swagger.io/docs/specification/2-0/basic-structure
  • @FredvN 啊,所以它不显示我在内部使用的实体,只是我用来存储和直接从请求/响应发送信息的 DTO?如果您可以将此作为答案,我很乐意将其标记为解决方案。我认为这就是 stackoveflow 的工作原理?

标签: java rest spring-boot swagger springfox


【解决方案1】:

Swagger 描述了你的 api 的外部接口。当您的用户模型未在外部使用时,将不可见。另请参阅 swagger.io/docs/specification/2-0/basic-structure

【讨论】:

    猜你喜欢
    • 2016-12-11
    • 2020-02-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多