Skip to content

Commit d8b3a89

Browse files
authored
Fixes an issue where the generated REST client was missing a comma (#1170)
* Fixes an issue where the generated REST client was missing a comma between `additional-request-args` and `@Url` when both were used, causing a compilation error. Updated the `api.qute` template to handle this safely, without affecting other parameter combinations. * test: add test to ensure additionalRequestArgs are generated when length > 0 fix: adjust api.qute to correctly handle commas when using additionalRequestArgs and dynamic url Updated the `api.qute` template to handle this safely, without affecting other parameter combinations. * test: add test to ensure additionalRequestArgs are generated when length > 0 fix: adjust api.qute to correctly handle commas when using additionalRequestArgs and dynamic url Updated the `api.qute` template to handle this safely, without affecting other parameter combinations.
1 parent bab9bbe commit d8b3a89

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

client/deployment/src/main/resources/templates/libraries/microprofile/api.qute

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,13 @@ public interface {classname} {
123123
{/if}
124124
{/if}
125125
{/if}
126-
{#if additionalRequestArgs}
127-
{#for arg in additionalRequestArgs}{!
128-
!}{arg}{#if arg_hasNext}, {/if}{/for}{!
129-
!}{#if op.allParams || op.hasFormParams},{/if}
126+
{#if additionalRequestArgs && additionalRequestArgs.length > 0}
127+
{#for arg in additionalRequestArgs}{arg}{#if arg_hasNext}, {/if}{/for}
128+
{#if (op.allParams || op.hasFormParams)}, {/if}
130129
{/if}
131130
{#if is-resteasy-reactive && use-dynamic-url}
132-
// See https://quarkus.io/version/3.20/guides/rest-client#dynamic-base-urls
133-
@io.quarkus.rest.client.reactive.Url String dynUrl{#if op.allParams || op.hasFormParams},{/if}
131+
// See https://quarkus.io/version/3.20/guides/rest-client#dynamic-base-urls
132+
@io.quarkus.rest.client.reactive.Url String dynUrl{#if op.allParams || op.hasFormParams},{/if}
134133
{/if}
135134
{#if op.hasFormParams}
136135
{#if is-resteasy-reactive}

client/deployment/src/test/java/io/quarkiverse/openapi/generator/deployment/wrapper/OpenApiClientGeneratorWrapperTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,28 @@ void verifyAdditionalRequestArgs() throws URISyntaxException {
633633
.forEach(this::verifyApiAdditionalHTTPHeaders);
634634
}
635635

636+
@Test
637+
void shouldGenerateAdditionalParametersWhenLengthGreaterThanZero() throws Exception {
638+
List<File> generatedFiles = createGeneratorWrapper("petstore-openapi.json")
639+
.withAdditionalRequestArgs("@HeaderParam(\"X-Test\") String testHeader;@PathParam(\"id\") String id")
640+
.generate("org.test.additionalargs");
641+
642+
Optional<File> file = generatedFiles.stream()
643+
.filter(f -> f.getName().endsWith("PetApi.java"))
644+
.findAny();
645+
assertThat(file).isNotEmpty();
646+
647+
CompilationUnit compilationUnit = StaticJavaParser.parse(file.orElseThrow());
648+
List<MethodDeclaration> methods = compilationUnit.findAll(MethodDeclaration.class);
649+
650+
boolean found = methods.stream()
651+
.anyMatch(m -> m.getParameters().stream().anyMatch(
652+
p -> p.getNameAsString().equals("testHeader") && p.getAnnotationByName("HeaderParam").isPresent()) &&
653+
m.getParameters().stream().anyMatch(
654+
p -> p.getNameAsString().equals("id") && p.getAnnotationByName("PathParam").isPresent()));
655+
assertTrue(found, "Additional parameters must be generated when additionalRequestArgs.length > 0");
656+
}
657+
636658
@Test
637659
void verifyCookieParams() throws URISyntaxException {
638660
List<File> generatedFiles = createGeneratorWrapper("petstore-openapi.json").generate("org.cookieParams");

0 commit comments

Comments
 (0)