0

I have gradle multimodule poject containing:

  1. 'api-spec' module which contains java interfaces of rest controllers to describe API specification with SpringDoc generator

  2. 'wallet' module which contains java classes of rest-controllers implementing api-spec interfaces

Consider I have:

'api-spec' module -> WalletController.java

@RequestMapping(path = "/wallet", produces = MediaType.APPLICATION_JSON_VALUE)
public interface WalletController {

    @Operation(summary = "Create wallet")
    @PostMapping(path = "/create-wallet")
    ApiResponseContainer<WalletDto> createWallet(@Valid @RequestBody ApiRequestContainer<CreateWalletRequestDto> request);
}

'wallet' module -> WalletControllerImpl.java:

@RestController
@Slf4j
public class WalletControllerImpl implements WalletController {
    @Override
    public ApiResponseContainer<WalletDto> createWallet(ApiRequestContainer<CreateWalletRequestDto> request) {
        /* validation does not perform in this case */
    }
}

I expect Spring to validate the controller parameter exactly the same way when I create it in one class:

GoodController.java:

@RequestMapping(path = "/good")
public class GoodController {
    @PostMapping
    public ApiResponseContainer<SomeDto> someMethod(@Valid @RequestBody SomeBodyDto bodyDto) {
        /* request is well validated here */
    }
}
}

Does anybody face this issue?

bvn13
  • 154
  • 11

1 Answers1

1

hm... it seems it was an issue with my generic request body.

check the difference:

validation "does not work":

public class ApiRequestContainer<T> {

    @Schema(description = "Request content")
    @NotNull
    T request;

    @Schema(description = "Signature of request content")
    @NotNull
    String signature;

}

and validation id work:

public class ApiRequestContainer<T> {

    @Schema(description = "Request content")
    @Valid
    @NotNull
    T request;

    @Schema(description = "Signature of request content")
    @NotNull
    String signature;

}

it started to work when I mark @Valid my generic field of container.

bvn13
  • 154
  • 11