swagger-core icon indicating copy to clipboard operation
swagger-core copied to clipboard

Springboot + Jersey 3 + Swagger-core - Nested @Beanparam not rendering correctly

Open leolimas opened this issue 2 years ago • 1 comments

I'm in a journey to upgrade swagger-jaxrs2-jakarta 1.6.8 to 2.2.7, I got almost everything working except some object parameters that should be exploded as inputs in the Swagger-ui and them still be interpreted as JSON input... and not as 2 distinct inputs

  • Java: 17
  • Springboot: 3.0.0
  • Jersey: 3.1.0
  • swagger-jaxrs2-jakarta: 2.2.7

Resource Interface

@Tag(name = "MyResource", description = "MyResource enpoint")
@Path("/")
@RequestMapping
public interface MyResourceAPI {

  @GET
  @Path("/get/{name}/something")
  @Produces(MediaType.APPLICATION_JSON)
  @Operation(summary = "MyResource")
  @GetMapping(value = "/get/{name}/something")
  @ApiResponses(value = {
      @ApiResponse(responseCode = "404", description = "Not found"),
      @ApiResponse(responseCode = "400", description = "Bad request"),
      @ApiResponse(responseCode = "200", description = "Sucesso", content = @Content(schema = @Schema(implementation = MyResourcehResponse.class)))
  })
  Response search(@Context HttpServletRequest servletRequest, @BeanParam MyCustomRequest myRequest);
}

Resource Implementation

@Component
public class MyResourceAPIImpl extends implements MyResourceAPI {

  @Override
  public Response search(HttpServletRequest servletRequest, MyCustomRequest myRequest) {
    #hidden logic
    return Response.ok().entity(myResponse).build();
  }
}

Request classes

public class MyCustomRequest extends Request {

}

public class Request {
  @BeanParam
  @Builder.Default
  private Pagination pagination = new Pagination();
}

public class Pagination {

  @QueryParam("limit")
  @DefaultValue("200")
  @Schema(defaultValue = "200", type = "integer", format = "int32")
  private Integer limit = 200;

  @QueryParam("offset")
  @DefaultValue("0")
  @Schema(defaultValue = "0", type = "integer", format = "int32")
  private Integer offset = 0;
}

Swagger-ui using 1.6.8 image

Swagger-ui using 2.2.7 image

If I remove @QueryParam from Pagination items, they disappear, and if I remove @BeanParam from Pagination declaration, it works as a single JSON input.

I'm without any clue to fix this... anyone already got this issue or something similar and can help me?

leolimas avatar Dec 21 '22 18:12 leolimas

can you share please which imports did you bring and your configuration class? @leolimas

alina-boruchov avatar Jan 27 '24 10:01 alina-boruchov