首页 > 解决方案 > 我可以使用自定义类作为 api 端点正文输入吗

问题描述

我正在使用 swagger 设置一个 api 端点,并且需要 body 类与 swagger 模型类相同,但是这样做会阻止端点工作。

@Operation(description = "body example is in model tab", 
responses = {@ApiResponse(responseCode = "200", description = 
"description") }, summary = "summary", tags = "Courier APIs")
@POST
@Secured
@Path("test")
@Consumes(MediaType.APPLICATION_XML)
@Produces(MediaType.APPLICATION_JSON)
public Response foo(
        @RequestBody(required = true, content = 
        @Content(schema = @Schema(implementation = SwaggerMessages.class),
         mediaType = "application/xml")) SwaggerMessages body) {

    //do work with body
}

我希望能够将类的一些编码(即 json 的 xml)作为 resquest 主体发送,但是当我尝试向该端点发送请求时,它总是返回错误 500,甚至没有进入该方法

标签: javaswaggerswagger-2.0

解决方案


推荐阅读