Swagger-如何使用相同的http方法和路径但内容类型不同进行多个操作?

时间:2018-12-02 14:35:40

标签: java spring-boot swagger swagger-ui

如本主题中所述。我想在具有相同路径和http方法但内容类型不同的情况下进行不同的操作。例: 我目前在2.0.5版中使用Spring Boot,在2.9.2版中使用Swagger ui。 在我的API中,我有两种注册用户的方法:

@RequestMapping(method = RequestMethod.POST, consumes = "application/customer+json", produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Registers a new application customer", notes = "Registers a new application customer.\n", response = CustomerResource.class)
@ApiResponses(value = {
        @ApiResponse(code = 201, message = "Customer successfully registered"),
        @ApiResponse(code = 409, message = "User with such email is already registered"),
        @ApiResponse(code = 422, message = "Customer registration request contains validation errors. Response contains detailed field validation error message"),
        @ApiResponse(code = 428, message = "Database error. Application log needs to be checked")})
public ResponseEntity<UserResource> registerCustomer(
        @ApiParam(value = "Model representation of the transferred data to register a new customer")  @Valid @RequestBody CustomerDto customerDto,
        UriComponentsBuilder uriComponentsBuilder,  BindingResult bindingResult)
{
...
}

@RequestMapping(method = RequestMethod.POST, consumes  = "application/partner+json", produces = MediaType.APPLICATION_JSON_VALUE)
@ApiOperation(value = "Registers a new application partner", notes = "Registers a new Easy Parking partner.\n", response = PartnerResource.class)
@ApiResponses(value = {
        @ApiResponse(code = 201, message = "Partner successfully registered"),
        @ApiResponse(code = 409, message = "User with such email is already registered"),
        @ApiResponse(code = 422, message = "Partner registration request contains validation errors. Response contains detailed field validation error message"),
        @ApiResponse(code = 428, message = "Database error. Application log needs to be checked")})
public ResponseEntity<UserResource> registerPartner(
        @ApiParam(value = "Model representation of the transferred data to register a new user")  @Valid @RequestBody PartnerDto partnerDto,
        UriComponentsBuilder uriComponentsBuilder, BindingResult bindingResult)
{ ... }

我想拥有一个POST路径:/ api / users以注册两种类型的用户:客户和合作伙伴。由于合作伙伴的属性与客户的属性略有不同,因此需要执行两次操作。我想使用content-type(consums)进行不同的操作,但是大招似乎仅适用于path和http方法。这不是错误吗?有没有办法在Spring Boot Swagger中配置它?

0 个答案:

没有答案