Skip to content

Commit 17a4d96

Browse files
authored
fix: add missing swagger2 tags import in rest-assured api.mustache (#23285) (#23946)
1 parent bfe4c11 commit 17a4d96

3 files changed

Lines changed: 39 additions & 0 deletions

File tree

modules/openapi-generator/src/main/resources/Java/libraries/rest-assured/api.mustache

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import io.swagger.v3.oas.annotations.enums.*;
3030
import io.swagger.v3.oas.annotations.media.*;
3131
import io.swagger.v3.oas.annotations.responses.*;
3232
import io.swagger.v3.oas.annotations.security.*;
33+
import io.swagger.v3.oas.annotations.tags.*;
3334
{{/swagger2AnnotationLibrary}}
3435

3536
{{#useBeanValidation}}

modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaClientCodegenTest.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4536,5 +4536,26 @@ public void testUseDeductionForOneInterfaces() {
45364536

45374537
}
45384538

4539+
@Test
4540+
public void testSwagger2TagImportRestAssured() throws IOException {
4541+
final Map<String, File> files = generateFromContract(
4542+
"src/test/resources/3_0/petstore.yaml",
4543+
JavaClientCodegen.REST_ASSURED,
4544+
Map.of(ANNOTATION_LIBRARY, "swagger2")
4545+
);
4546+
4547+
// find the generated API file
4548+
File apiFile = files.values().stream()
4549+
.filter(f -> f.getName().endsWith("Api.java"))
4550+
.findFirst()
4551+
.orElseThrow(() -> new AssertionError("No API file generated"));
4552+
4553+
String content = Files.readString(apiFile.toPath());
4554+
4555+
// verify tags import is present when swagger2 is used with rest-assured
4556+
assertThat(content)
4557+
.contains("import io.swagger.v3.oas.annotations.tags.*;")
4558+
.contains("@Tag(");
4559+
}
45394560

45404561
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
openapi: 3.0.3
2+
info:
3+
title: Test API
4+
version: 1.0.0
5+
tags:
6+
- name: pets
7+
description: Pet operations
8+
paths:
9+
/pets:
10+
get:
11+
tags:
12+
- pets
13+
operationId: listPets
14+
summary: List all pets
15+
responses:
16+
'200':
17+
description: OK

0 commit comments

Comments
 (0)