Java 招摇过市-如何使用相同的http方法和路径获得多个操作,但内容类型不同?

Java 招摇过市-如何使用相同的http方法和路径获得多个操作,但内容类型不同?,java,spring-boot,swagger,swagger-ui,Java,Spring Boot,Swagger,Swagger Ui,就像这个话题一样。我希望在swagger中使用相同的路径和http方法进行不同的操作,但使用不同的内容类型。例子: 我目前在2.0.5版中使用Spring Boot,在2.9.2版中使用Swagger ui。 在我的API中,我有两种注册用户的方法: @RequestMapping(method = RequestMethod.POST, consumes = "application/customer+json", produces = MediaType.APPLICATION_JSON_V

就像这个话题一样。我希望在swagger中使用相同的路径和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/customer+json”,products=MediaType.application\u json\u VALUE)
@ApiOperation(value=“注册一个新的应用程序客户”,notes=“注册一个新的应用程序客户。\n”,response=CustomerResource.class)
@ApiResponses(值={
@ApiResponse(code=201,message=“客户成功注册”),
@ApiResponse(code=409,message=“拥有此类电子邮件的用户已注册”),
@ApiResponse(code=422,message=“客户注册请求包含验证错误。响应包含详细的字段验证错误消息”),
@ApiResponse(code=428,message=“数据库错误。需要检查应用程序日志”)}
公共责任登记处客户(
@ApiParam(value=“注册新客户的传输数据的模型表示”)@Valid@RequestBody CustomerDto CustomerDto,
UriComponentsBuilder UriComponentsBuilder,BindingResult(绑定结果)
{
...
}

@RequestMapping(method=RequestMethod.POST,consumes=“application/partner+json”,products=MediaType.application\u json\u VALUE)
@ApiOperation(value=“注册一个新的应用程序合作伙伴”,notes=“注册一个新的轻松停车合作伙伴。\n”,response=partnersource.class)
@ApiResponses(值={
@ApiResponse(code=201,message=“合作伙伴成功注册”),
@ApiResponse(code=409,message=“拥有此类电子邮件的用户已注册”),
@ApiResponse(code=422,message=“合作伙伴注册请求包含验证错误。响应包含详细的字段验证错误消息”),
@ApiResponse(code=428,message=“数据库错误。需要检查应用程序日志”)}
公共责任登记处合伙人(
@ApiParam(value=“注册新用户所传输数据的模型表示”)@Valid@RequestBody PartnerDto PartnerDto,
UriComponentsBuilder UriComponentsBuilder,BindingResult(绑定结果)
{ ... }

我想要一个POST路径:/api/users来注册两种类型的用户:客户和合作伙伴。由于合作伙伴的属性与客户稍有不同,因此需要两个操作。我想使用contenttype(consumes)进行不同的操作,但swagger似乎只适用于path和http方法。这不是一只虫子吗??有没有办法在Spring Boot Swagger中配置它?

我认为您需要一个方法,并使用Swagger Core 2.x注释,特别是-。最后一个链接还指出,目前不支持使用相同的HTTP path+谓词注释不同的方法,但计划在将来使用。
@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)
{ ... }