From 2e69a7be25ec66b923e5afb6c7b2ea5d45c016b6 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:59:44 -0300 Subject: [PATCH] fix Build fails if quarkus-oidc-client is not in the classpath (#829) (#840) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Loïc Hermann --- .../deployment/GeneratorProcessor.java | 16 +- client/integration-tests/pom.xml | 1 + client/integration-tests/without-oidc/pom.xml | 95 ++++++ .../main/openapi/quarkus-simple-openapi.yaml | 282 ++++++++++++++++++ .../src/main/resources/application.properties | 1 + .../it/QuarkusSimpleOpenApiTest.java | 24 ++ 6 files changed, 417 insertions(+), 2 deletions(-) create mode 100644 client/integration-tests/without-oidc/pom.xml create mode 100644 client/integration-tests/without-oidc/src/main/openapi/quarkus-simple-openapi.yaml create mode 100644 client/integration-tests/without-oidc/src/main/resources/application.properties create mode 100644 client/integration-tests/without-oidc/src/test/java/io/quarkiverse/openapi/generator/it/QuarkusSimpleOpenApiTest.java 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 2cc8c3b3..92bff149 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 @@ -1,5 +1,7 @@ package io.quarkiverse.openapi.generator.deployment; +import static io.quarkus.bootstrap.classloading.QuarkusClassLoader.isClassPresentAtRuntime; + import java.util.Collection; import java.util.List; import java.util.Map; @@ -48,9 +50,10 @@ public class GeneratorProcessor { private static final DotName BASIC_AUTHENTICATION_MARKER = DotName.createSimple(BasicAuthenticationMarker.class); private static final DotName BEARER_AUTHENTICATION_MARKER = DotName.createSimple(BearerAuthenticationMarker.class); private static final DotName API_KEY_AUTHENTICATION_MARKER = DotName.createSimple(ApiKeyAuthenticationMarker.class); - private static final DotName OPERATION_MARKER = DotName.createSimple(OperationMarker.class); + private static final String ABSTRACT_TOKEN_PRODUCER = "io.quarkus.oidc.client.runtime.AbstractTokensProducer"; + @BuildStep FeatureBuildItem feature() { return new FeatureBuildItem(FEATURE); @@ -61,6 +64,10 @@ void additionalBean( Capabilities capabilities, BuildProducer producer) { + if (!isClassPresentAtRuntime(ABSTRACT_TOKEN_PRODUCER)) { + return; + } + if (capabilities.isPresent(Capability.REST_CLIENT_REACTIVE)) { producer.produce( AdditionalBeanBuildItem.builder().addBeanClass(ReactiveOidcClientRequestFilterDelegate.class) @@ -103,10 +110,15 @@ void produceCompositeProviders(AuthenticationRecorder recorder, @BuildStep @Record(ExecutionTime.STATIC_INIT) - void produceOauthAuthentication(CombinedIndexBuildItem beanArchiveBuildItem, + void produceOauthAuthentication( + CombinedIndexBuildItem beanArchiveBuildItem, BuildProducer authenticationProviders, BuildProducer beanProducer, AuthenticationRecorder recorder) { + + if (!isClassPresentAtRuntime(ABSTRACT_TOKEN_PRODUCER)) { + return; + } Collection authenticationMarkers = beanArchiveBuildItem.getIndex() .getAnnotationsWithRepeatable(OAUTH_AUTHENTICATION_MARKER, beanArchiveBuildItem.getIndex()); diff --git a/client/integration-tests/pom.xml b/client/integration-tests/pom.xml index 8c2d96ba..ef2670df 100644 --- a/client/integration-tests/pom.xml +++ b/client/integration-tests/pom.xml @@ -40,6 +40,7 @@ type-mapping config-key github + without-oidc diff --git a/client/integration-tests/without-oidc/pom.xml b/client/integration-tests/without-oidc/pom.xml new file mode 100644 index 00000000..18c90438 --- /dev/null +++ b/client/integration-tests/without-oidc/pom.xml @@ -0,0 +1,95 @@ + + + + quarkus-openapi-generator-parent + io.quarkiverse.openapi.generator + 3.0.0-SNAPSHOT + ../../../pom.xml + + 4.0.0 + + quarkus-openapi-generator-it-without-oidc + Quarkus - Openapi Generator - Integration Tests - Client - Without OIDC + Example project for general usage + + + + io.quarkiverse.openapi.generator + quarkus-openapi-generator + + + io.quarkus + quarkus-rest-client-jackson + + + org.assertj + assertj-core + test + + + io.quarkus + quarkus-junit5 + test + + + + + + io.quarkus + quarkus-maven-plugin + true + + + + build + generate-code + generate-code-tests + + + + + + + + + native-image + + + native + + + + + + maven-surefire-plugin + + ${native.surefire.skip} + + + + maven-failsafe-plugin + + + + integration-test + verify + + + + ${project.build.directory}/${project.build.finalName}-runner + org.jboss.logmanager.LogManager + ${maven.home} + + + + + + + + + native + + + + + \ No newline at end of file diff --git a/client/integration-tests/without-oidc/src/main/openapi/quarkus-simple-openapi.yaml b/client/integration-tests/without-oidc/src/main/openapi/quarkus-simple-openapi.yaml new file mode 100644 index 00000000..559d0445 --- /dev/null +++ b/client/integration-tests/without-oidc/src/main/openapi/quarkus-simple-openapi.yaml @@ -0,0 +1,282 @@ +--- +openapi: 3.0.3 +info: + title: greeting-flow API + version: "1.0" +paths: + /: + post: + requestBody: + content: + '*/*': + schema: + $ref: '#/components/schemas/CloudEvent' + responses: + "200": + description: OK + content: + application/json: + schema: + $ref: '#/components/schemas/Response' + /hello: + get: + tags: + - Reactive Greeting Resource + operationId: hello + responses: + "200": + description: OK + content: + text/plain: + schema: + type: string + /messaging/topics: + get: + tags: + - Quarkus Topics Information Resource + responses: + "200": + description: OK +components: + schemas: + Type: + type: object + properties: + tags: + uniqueItems: true + type: array + items: + type: string + CloudEvent: + type: object + properties: + specVersion: + $ref: '#/components/schemas/SpecVersion' + id: + type: string + type: + type: string + source: + format: uri + type: string + dataContentType: + type: string + dataSchema: + format: uri + type: string + subject: + type: string + time: + format: date-time + type: string + attributeNames: + uniqueItems: true + type: array + items: + type: string + extensionNames: + uniqueItems: true + type: array + items: + type: string + data: + $ref: '#/components/schemas/CloudEventData' + CloudEventData: + type: object + EntityTag: + type: object + properties: + value: + type: string + weak: + type: boolean + Family: + enum: + - INFORMATIONAL + - SUCCESSFUL + - REDIRECTION + - CLIENT_ERROR + - SERVER_ERROR + - OTHER + type: string + Link: + type: object + properties: + uri: + format: uri + type: string + uriBuilder: + $ref: '#/components/schemas/UriBuilder' + rel: + type: string + rels: + type: array + items: + type: string + title: + type: string + type: + type: string + params: + type: object + additionalProperties: + type: string + Locale: + type: object + properties: + language: + type: string + script: + type: string + country: + type: string + variant: + type: string + extensionKeys: + uniqueItems: true + type: array + items: + format: byte + type: string + unicodeLocaleAttributes: + uniqueItems: true + type: array + items: + type: string + unicodeLocaleKeys: + uniqueItems: true + type: array + items: + type: string + iSO3Language: + type: string + iSO3Country: + type: string + displayLanguage: + type: string + displayScript: + type: string + displayCountry: + type: string + displayVariant: + type: string + displayName: + type: string + MediaType: + type: object + properties: + type: + type: string + subtype: + type: string + parameters: + type: object + additionalProperties: + type: string + wildcardType: + type: boolean + wildcardSubtype: + type: boolean + MultivaluedMapStringObject: + type: object + additionalProperties: + type: array + items: + type: object + MultivaluedMapStringString: + type: object + additionalProperties: + type: array + items: + type: string + NewCookie: + type: object + properties: + name: + type: string + value: + type: string + version: + format: int32 + type: integer + path: + type: string + domain: + type: string + comment: + type: string + maxAge: + format: int32 + type: integer + expiry: + format: date + type: string + secure: + type: boolean + httpOnly: + type: boolean + Response: + type: object + properties: + status: + format: int32 + type: integer + statusInfo: + $ref: '#/components/schemas/StatusType' + entity: + type: object + mediaType: + $ref: '#/components/schemas/MediaType' + language: + $ref: '#/components/schemas/Locale' + length: + format: int32 + type: integer + allowedMethods: + uniqueItems: true + type: array + items: + type: string + cookies: + type: object + additionalProperties: + $ref: '#/components/schemas/NewCookie' + entityTag: + $ref: '#/components/schemas/EntityTag' + date: + format: date + type: string + lastModified: + format: date + type: string + location: + format: uri + type: string + links: + uniqueItems: true + type: array + items: + $ref: '#/components/schemas/Link' + metadata: + $ref: '#/components/schemas/MultivaluedMapStringObject' + headers: + $ref: '#/components/schemas/MultivaluedMapStringObject' + stringHeaders: + $ref: '#/components/schemas/MultivaluedMapStringString' + SpecVersion: + enum: + - V03 + - V1 + type: string + StatusType: + type: object + properties: + statusCode: + format: int32 + type: integer + family: + $ref: '#/components/schemas/Family' + reasonPhrase: + type: string + UriBuilder: + type: object diff --git a/client/integration-tests/without-oidc/src/main/resources/application.properties b/client/integration-tests/without-oidc/src/main/resources/application.properties new file mode 100644 index 00000000..a2f16a85 --- /dev/null +++ b/client/integration-tests/without-oidc/src/main/resources/application.properties @@ -0,0 +1 @@ +quarkus.rest-client.quarkus_simple_openapi_yaml.url=http://localhost:8080 \ No newline at end of file diff --git a/client/integration-tests/without-oidc/src/test/java/io/quarkiverse/openapi/generator/it/QuarkusSimpleOpenApiTest.java b/client/integration-tests/without-oidc/src/test/java/io/quarkiverse/openapi/generator/it/QuarkusSimpleOpenApiTest.java new file mode 100644 index 00000000..f055063c --- /dev/null +++ b/client/integration-tests/without-oidc/src/test/java/io/quarkiverse/openapi/generator/it/QuarkusSimpleOpenApiTest.java @@ -0,0 +1,24 @@ +package io.quarkiverse.openapi.generator.it; + +import static org.assertj.core.api.Assertions.assertThat; + +import jakarta.inject.Inject; + +import org.eclipse.microprofile.rest.client.inject.RestClient; +import org.junit.jupiter.api.Test; +import org.openapi.quarkus.quarkus_simple_openapi_yaml.api.ReactiveGreetingResourceApi; + +import io.quarkus.test.junit.QuarkusTest; + +@QuarkusTest +class QuarkusSimpleOpenApiTest { + + @RestClient + @Inject + ReactiveGreetingResourceApi api; + + @Test + void apiIsBeingGenerated() { + assertThat(api).isNotNull(); + } +}