From d0ff97b2e0a693001718628dc1eb526b2f9766ae Mon Sep 17 00:00:00 2001 From: Ricardo Zanini Date: Tue, 20 May 2025 17:32:56 -0400 Subject: [PATCH 1/2] Fix #1151 - Fail on scenarios where OAuth2 is required and OIDC is not in the classpath Signed-off-by: Ricardo Zanini --- .../deployment/GeneratorProcessor.java | 26 ++++++++++++++----- .../generation-tests/pom.xml | 8 ++++++ 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/GeneratorProcessor.java b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/GeneratorProcessor.java index 397e43974..1d48b9849 100644 --- a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/GeneratorProcessor.java +++ b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/GeneratorProcessor.java @@ -128,14 +128,10 @@ void produceCompositeProviders(AuthenticationRecorder recorder, List authenticationProviders, BuildProducer beanProducer, + BuildProducer authenticationProviders, + BuildProducer beanProducer, OidcAuthenticationRecorder oidcRecorder) { - if (!isClassPresentAtRuntime(ABSTRACT_TOKEN_PRODUCER)) { - LOGGER.debug("{} class not found in runtime, skipping OAuth bean generation", ABSTRACT_TOKEN_PRODUCER); - return; - } - LOGGER.debug("{} class found in runtime, producing OAuth bean generation", ABSTRACT_TOKEN_PRODUCER); Collection authenticationMarkers = beanArchiveBuildItem.getIndex() .getAnnotationsWithRepeatable(OAUTH_AUTHENTICATION_MARKER, beanArchiveBuildItem.getIndex()) .stream() @@ -145,6 +141,24 @@ void produceOauthAuthentication(CombinedIndexBuildItem beanArchiveBuildItem, (existing, duplicate) -> existing)) .values(); + if (!isClassPresentAtRuntime(ABSTRACT_TOKEN_PRODUCER)) { + if (!authenticationMarkers.isEmpty()) { + throw new IllegalStateException( + "OAuth2 flows detected in spec(s) " + + authenticationMarkers.stream() + .map(m -> m.value("openApiSpecId").asString()) + .distinct() + .collect(Collectors.joining(", ")) + + + " but quarkus-openapi-generator-oidc and quarkus-rest-client-oidc-filter or quarkus-oidc-client-reactive-filter are not on the classpath. " + + + "Please add those dependencies to your project. See https://docs.quarkiverse.io/quarkus-openapi-generator/dev/client.html#_oauth2_authentication"); + } + LOGGER.debug("{} class not found in runtime, skipping OAuth bean generation", ABSTRACT_TOKEN_PRODUCER); + return; + } + LOGGER.debug("{} class found in runtime, producing OAuth bean generation", ABSTRACT_TOKEN_PRODUCER); + Map> operationsBySpec = getOperationsBySpec(beanArchiveBuildItem); for (AnnotationInstance authenticationMarker : authenticationMarkers) { diff --git a/client/integration-tests/generation-tests/pom.xml b/client/integration-tests/generation-tests/pom.xml index 2d699f578..c7e0bab87 100644 --- a/client/integration-tests/generation-tests/pom.xml +++ b/client/integration-tests/generation-tests/pom.xml @@ -15,6 +15,14 @@ io.quarkiverse.openapi.generator quarkus-openapi-generator + + io.quarkiverse.openapi.generator + quarkus-openapi-generator-oidc + + + io.quarkus + quarkus-resteasy-client-oidc-filter + io.quarkiverse.openapi.generator quarkus-openapi-generator-it-generation-input From 8216b0e4f06b6b76e938bf593f61d9bbc3a126d7 Mon Sep 17 00:00:00 2001 From: Ricardo Zanini Date: Tue, 20 May 2025 17:58:40 -0400 Subject: [PATCH 2/2] Added missing dependencies to mvn profile Signed-off-by: Ricardo Zanini --- .../generation-tests/pom.xml | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/client/integration-tests/generation-tests/pom.xml b/client/integration-tests/generation-tests/pom.xml index c7e0bab87..605dd880f 100644 --- a/client/integration-tests/generation-tests/pom.xml +++ b/client/integration-tests/generation-tests/pom.xml @@ -19,10 +19,6 @@ io.quarkiverse.openapi.generator quarkus-openapi-generator-oidc - - io.quarkus - quarkus-resteasy-client-oidc-filter - io.quarkiverse.openapi.generator quarkus-openapi-generator-it-generation-input @@ -100,5 +96,26 @@ native + + resteasy-classic + + true + + + + io.quarkus + quarkus-resteasy-client-oidc-filter + + + + + resteasy-reactive + + + io.quarkus + quarkus-rest-client-oidc-filter + + +