I’d like to draw the Auth0 product team’s attention to the importance of this feature request which is now 1.5 years old.
As pointed out by David, this would be a huge energy saver for those who, like me, are maintaining backends with REST clients generated from OpenAPI specs.
Also, as David pointed out, this is something competitors have been doing for quite some time already. For instance, I use Keycloak’s spec to call its admin API with generated clients. To declare a REST service, I need no more than this:
@Configuration
public class RestConfig {
@Bean
UsersApi usersApi(RestClient keycloakAdminClient) throws Exception {
return new RestClientHttpExchangeProxyFactoryBean<>(UsersApi.class, keycloakAdminClient).getObject();
}
}
I can then inject that service and use it in my own controllers as follows:
@RestController
@RequestMapping(path = "/skill-tests")
@RequiredArgsConstructor
public class SkillTestController {
private final UsersApi keycloakUsersApi;
...
private List<UserRepresentation> getUsers(final String username) {
return keycloakUsersApi.adminRealmsRealmUsersGet("quiz", Optional.empty(), Optional.empty(),
Optional.empty(), Optional.empty(), Optional.of(true), Optional.empty(), Optional.empty(),
Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(),
Optional.empty(), Optional.of(username)).getBody();
}
}
Note that I wrote absolutely no code for DTOs, REST clients request authorization with OAuth2 access tokens acquired with client credentials, or requests themselves (base-path, path, HTTP verbs to use, request params names and serialization, body (de)serialization, etc.).
UsersApi
interface and UserRepresentation
DTO are generated from the OpenAPI spec. The keycloakAdminClient
is defined and configured by a Boot starter of mine, and the UsersApi
implementation is generated by Spring.
When I upgrade Keycloak version, all I have to do is update the OpenAPI spec, and if there were breaking changes in the endpoints I use, I’d get compilation errors (I never had so far).