Skip to content

Commit eb2299d

Browse files
committed
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 314cb0d commit eb2299d

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +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}
129-
{/for}
130-
{#if is-resteasy-reactive && use-dynamic-url}, {/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}
131129
{/if}
132130
{#if is-resteasy-reactive && use-dynamic-url}
133-
// See https://quarkus.io/version/3.20/guides/rest-client#dynamic-base-urls
134-
@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}
135133
{/if}
136134
{#if op.hasFormParams}
137135
{#if is-resteasy-reactive}

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,31 @@ 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().anyMatch(m ->
651+
m.getParameters().stream().anyMatch(p ->
652+
p.getNameAsString().equals("testHeader") && p.getAnnotationByName("HeaderParam").isPresent()
653+
) &&
654+
m.getParameters().stream().anyMatch(p ->
655+
p.getNameAsString().equals("id") && p.getAnnotationByName("PathParam").isPresent()
656+
)
657+
);
658+
assertTrue(found, "Additional parameters must be generated when additionalRequestArgs.length > 0");
659+
}
660+
636661
@Test
637662
void verifyCookieParams() throws URISyntaxException {
638663
List<File> generatedFiles = createGeneratorWrapper("petstore-openapi.json").generate("org.cookieParams");

0 commit comments

Comments
 (0)