camunda / camunda

Process Orchestration Framework
https://camunda.com/platform/
3.32k stars 604 forks source link

Unified REST API: Replace sortOrder Field with Enum in SearchQuerySortRequest #20512

Open houssain-barouni opened 3 months ago

houssain-barouni commented 3 months ago

Description

We need to update the sortOrder field in the SearchQuerySortRequest from a string type to an enum with possible values asc and desc in our OpenAPI specification. The default value should be asc. Additionally, we need to ensure that the API validation correctly returns a 400 Bad Request with an appropriate ProblemDetail object when an invalid value is provided.

Acceptance Criteria

Implementation proposal

We can use an ExceptionHandler on MethodArgumentNotValidException to identify the invalid input field

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(MethodArgumentNotValidException.class)
    public ResponseEntity<ProblemDetail> handleValidationExceptions(MethodArgumentNotValidException ex) {
        for (FieldError error : ex.getBindingResult().getFieldErrors()) {
            if ("sortOrder".equals(error.getField())) {
                // return the problem Detail with the invalid sortOrder
            }
           ...
        }
tmetzke commented 2 weeks ago

Unassigning @houssain-barouni for now, anyone can tackle this