Skip to content

Commit eac9db9

Browse files
committed
feat: add ResponseStatus annotation for non-200 success codes in Quarkus library
1 parent 9a1952b commit eac9db9

2 files changed

Lines changed: 23 additions & 23 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/JavaJAXRSSpecServerCodegen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
346346
if (QUARKUS_LIBRARY.equals(library) && !returnResponse && !returnJbossResponse) {
347347
for (CodegenOperation op : objs.getOperations().getOperation()) {
348348
op.responses.stream()
349-
.filter(r -> (r.is2xx || r.is3xx) && !"200".equals(r.code))
349+
.filter(r -> r.is2xx || r.is3xx)
350350
.findFirst()
351351
.ifPresent(r -> op.vendorExtensions.put("x-java-success-response-code", r.code));
352352
}

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

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,13 +1308,13 @@ public void testGenerateJsonNullableListFieldsHelperMethodReferences_issue23251(
13081308
}
13091309

13101310
/**
1311-
* Verify that when using the quarkus library with interfaceOnly=true and a non-200 success response,
1312-
* the generated interface method is annotated with
1313-
* {@code @org.jboss.resteasy.reactive.ResponseStatus(<code>)}.
1314-
* ping.yaml has a 201 response, so the annotation must appear.
1311+
* Verify that when using the quarkus library with interfaceOnly=true, the generated interface
1312+
* method is always annotated with {@code @ResponseStatus(<code>)} for any 2xx or 3xx response,
1313+
* including 200, for explicit documentation purposes.
1314+
* ping.yaml has a 201 response.
13151315
*/
13161316
@Test
1317-
public void generateQuarkusInterfaceAddsResponseStatusAnnotationForNon200SuccessCode() throws Exception {
1317+
public void generateQuarkusInterfaceAddsResponseStatusAnnotationForSuccessCode() throws Exception {
13181318
final File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
13191319
output.deleteOnExit();
13201320

@@ -1343,21 +1343,20 @@ public void generateQuarkusInterfaceAddsResponseStatusAnnotationForNon200Success
13431343
}
13441344

13451345
/**
1346-
* Verify that the {@code @ResponseStatus} annotation is NOT emitted when returnResponse=true,
1347-
* because the user controls the status code via the {@code Response} builder in that mode.
1346+
* Verify that {@code @ResponseStatus(200)} IS emitted even for the default 200 status code,
1347+
* for explicit documentation purposes.
13481348
*/
13491349
@Test
1350-
public void generateQuarkusInterfaceDoesNotAddResponseStatusAnnotationWhenReturnResponse() throws Exception {
1350+
public void generateQuarkusInterfaceAddsResponseStatusAnnotationFor200Response() throws Exception {
13511351
final File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
13521352
output.deleteOnExit();
13531353

13541354
final OpenAPI openAPI = new OpenAPIParser()
1355-
.readLocation("src/test/resources/3_0/ping.yaml", null, new ParseOptions()).getOpenAPI();
1355+
.readLocation("src/test/resources/3_0/petstore.yaml", null, new ParseOptions()).getOpenAPI();
13561356

13571357
codegen.setOutputDir(output.getAbsolutePath());
13581358
codegen.setLibrary(QUARKUS_LIBRARY);
13591359
codegen.additionalProperties().put(INTERFACE_ONLY, true);
1360-
codegen.additionalProperties().put(RETURN_RESPONSE, true); //Given returnResponse is true
13611360

13621361
final ClientOptInput input = new ClientOptInput()
13631362
.openAPI(openAPI)
@@ -1368,28 +1367,29 @@ public void generateQuarkusInterfaceDoesNotAddResponseStatusAnnotationWhenReturn
13681367

13691368
validateJavaSourceFiles(files);
13701369

1371-
//Then the annotation must NOT appear
1372-
TestUtils.ensureContainsFile(files, output, "src/gen/java/org/openapitools/api/PingApi.java");
1373-
assertFileNotContains(output.toPath().resolve("src/gen/java/org/openapitools/api/PingApi.java"),
1374-
"@ResponseStatus",
1375-
"import org.jboss.resteasy.reactive.ResponseStatus");
1370+
//Then @ResponseStatus(200) IS present for explicit documentation
1371+
TestUtils.ensureContainsFile(files, output, "src/gen/java/org/openapitools/api/PetApi.java");
1372+
assertFileContains(output.toPath().resolve("src/gen/java/org/openapitools/api/PetApi.java"),
1373+
"import org.jboss.resteasy.reactive.ResponseStatus;",
1374+
"@ResponseStatus(200)");
13761375
}
13771376

13781377
/**
1379-
* Verify that the {@code @ResponseStatus} annotation is NOT emitted when the sole success
1380-
* response code is 200, since that is the RESTEasy Reactive default.
1378+
* Verify that the {@code @ResponseStatus} annotation is NOT emitted when returnResponse=true,
1379+
* because the user controls the status code via the {@code Response} builder in that mode.
13811380
*/
13821381
@Test
1383-
public void generateQuarkusInterfaceDoesNotAddResponseStatusAnnotationFor200Response() throws Exception {
1382+
public void generateQuarkusInterfaceDoesNotAddResponseStatusAnnotationWhenReturnResponse() throws Exception {
13841383
final File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
13851384
output.deleteOnExit();
13861385

13871386
final OpenAPI openAPI = new OpenAPIParser()
1388-
.readLocation("src/test/resources/3_0/petstore.yaml", null, new ParseOptions()).getOpenAPI();
1387+
.readLocation("src/test/resources/3_0/ping.yaml", null, new ParseOptions()).getOpenAPI();
13891388

13901389
codegen.setOutputDir(output.getAbsolutePath());
13911390
codegen.setLibrary(QUARKUS_LIBRARY);
13921391
codegen.additionalProperties().put(INTERFACE_ONLY, true);
1392+
codegen.additionalProperties().put(RETURN_RESPONSE, true); //Given returnResponse is true
13931393

13941394
final ClientOptInput input = new ClientOptInput()
13951395
.openAPI(openAPI)
@@ -1400,9 +1400,9 @@ public void generateQuarkusInterfaceDoesNotAddResponseStatusAnnotationFor200Resp
14001400

14011401
validateJavaSourceFiles(files);
14021402

1403-
//Then the annotation must NOT appear (petstore only uses 200 for success)
1404-
TestUtils.ensureContainsFile(files, output, "src/gen/java/org/openapitools/api/PetApi.java");
1405-
assertFileNotContains(output.toPath().resolve("src/gen/java/org/openapitools/api/PetApi.java"),
1403+
//Then the annotation must NOT appear
1404+
TestUtils.ensureContainsFile(files, output, "src/gen/java/org/openapitools/api/PingApi.java");
1405+
assertFileNotContains(output.toPath().resolve("src/gen/java/org/openapitools/api/PingApi.java"),
14061406
"@ResponseStatus",
14071407
"import org.jboss.resteasy.reactive.ResponseStatus");
14081408
}

0 commit comments

Comments
 (0)