端点未显示相同的请求映射但不同的参数

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

我使用弹簧靴

这 2 个端点位于控制器中

@RequestMapping(value = "/deposits")

@GetMapping(params = "idDepositSignal")
public ResponseEntity<Boolean> adviseDeposit(@RequestParam List<Long> idDepositSignal) {
        return new ResponseEntity<>(depositService.adviceDeposit(idDepositSignal), HttpStatus.OK);
}


@GetMapping(params = "idDepositDuplicate")
public ResponseEntity<Deposit> duplicateDeposit(@RequestParam Long idDepositDuplicate) {
        return new ResponseEntity<>(depositService.duplicateDeposit(idDepositDuplicate), HttpStatus.OK);
}

在另一个控制器中

@RequestMapping(value = "/deposits")


@GetMapping("/{depositId}")
public ResponseEntity<DepositInfo> getDepositInfo(@PathVariable Long depositId) {

    return new ResponseEntity<>(depositService.getDeposit(depositId), HttpStatus.OK);
}

当我进入 swagger ui 时,我的第一个和第二个端点未显示,但我可以调用它

我尝试删除前两个端点之一...但另一个未显示。

似乎是一个错误

swagger 在同一空间中显示两个端点,取两个描述之一并显示两个函数的所有参数....

非常非常糟糕...

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

这是如下所示的解决方案

由于您的前两个端点(/deposits)使用具有不同查询参数的相同路径,因此

Swagger
无法正确区分它们。

1)使用显式

@Operation
注释(解决方案的第一种方法)

@RequestMapping(value = "/deposits")
@RestController
public class DepositController {

    @GetMapping(params = "idDepositSignal")
    @Operation(
        summary = "Advise Deposit",
        description = "Advise a deposit based on a list of deposit signal IDs",
        operationId = "adviseDeposit"
    )
    public ResponseEntity<Boolean> adviseDeposit(@RequestParam List<Long> idDepositSignal) {
        return new ResponseEntity<>(depositService.adviceDeposit(idDepositSignal), HttpStatus.OK);
    }

    @GetMapping(params = "idDepositDuplicate")
    @Operation(
        summary = "Duplicate Deposit",
        description = "Duplicate a deposit based on the given deposit ID",
        operationId = "duplicateDeposit"
    )
    public ResponseEntity<Deposit> duplicateDeposit(@RequestParam Long idDepositDuplicate) {
        return new ResponseEntity<>(depositService.duplicateDeposit(idDepositDuplicate), HttpStatus.OK);
    }
}

2)将端点分成不同的路径(解决方案的第二种方法)

@RequestMapping(value = "/deposits")
@RestController
public class DepositController {

    @GetMapping("/advise")
    public ResponseEntity<Boolean> adviseDeposit(@RequestParam List<Long> idDepositSignal) {
        return new ResponseEntity<>(depositService.adviceDeposit(idDepositSignal), HttpStatus.OK);
    }

    @GetMapping("/duplicate")
    public ResponseEntity<Deposit> duplicateDeposit(@RequestParam Long idDepositDuplicate) {
        return new ResponseEntity<>(depositService.duplicateDeposit(idDepositDuplicate), HttpStatus.OK);
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.