Search code examples
spring-bootspringdocspringdoc-openui

How to customized and Override Parameter Values from POJO?


I am working on Spring Boot v2.2.6.RELEASE and Open API Integration example. This example has capability to search using 20 different parameters. So this POJO class holds CustomSearchDto these 20 different values.

In the POJO I used orgName, but @parameter(in = ParameterIn.QUERY, name = "orgizationName", and somehow I wanted to override the variable name. I must do that. Is there any way to do it ?

@Parameter(in = ParameterIn.QUERY, name = "orgizationName", schema = @Schema(type = "string")) 
@Parameter(in = ParameterIn.QUERY, name = "employeeId", schema = @Schema(type = "string")) 
@Parameter(in = ParameterIn.QUERY, name = "emailId", schema = @Schema(type = "string")) 
@Parameter(in=ParameterIn.QUERY, name="page", description="Results page you want to retrieve (0..N)", schema=@Schema(defaultValue = "0"))
    @Parameter(in=ParameterIn.QUERY, name="size", description="Number of records per page.", schema=@Schema(defaultValue = "30"))
@GetMapping(value = "/employees/organizations")
public ResponseEntity<PagedModel<Employees>> search(CustomSearchDto requestparams,
        @Parameter(hidden=true) Pageable pageRequest) {

    ......
    ........

    return new ResponseEntity<>(model, HttpStatus.OK);
}

Here is my custom DTO class

public class CustomSearchDto {
    @Schema(description = "", type = "string", example = " ")
    private String orgName;

    @Schema(description = "", type = "string", example = " ")
    private String empId;

    @Schema(description = "", type = "integer", example = "null")
    private Integer email;

    .........
    ..............
    .............
}

Solution

  • You can pass directly you object CustomSearchDto with the annotation @ParameterObject.

    Here is the link for the documentation: