Skip to content

Commit fc60f97

Browse files
[jaxrs-spec][quarkus] - Add CLI flag (useQuarkusSecurityAnnotations) to enable emitting security annotation (@authenticated, @RolesAllowed, @permitAll) (#23699)
* [jaxrs-spec][quarkus] Add useQuarkusSecurityAnnotations CLI option Registers a new boolean generator option (default false, quarkus library only) that will gate emission of Quarkus security annotations (@authenticated, @RolesAllowed, @permitAll) in subsequent PRs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * [jaxrs-spec][quarkus] Test useQuarkusSecurityAnnotations CLI option registration Covers: option registered with default false, readable as true for quarkus library, and not processed for non-quarkus libraries. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * added quarkus cli flag for security annotations --------- Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 075fada commit fc60f97

4 files changed

Lines changed: 50 additions & 0 deletions

File tree

docs/generators/jaxrs-cxf-cdi.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
8585
|useMicroProfileOpenAPIAnnotations|Whether to generate Microprofile OpenAPI annotations. Only valid when library is set to quarkus.| |false|
8686
|useMutiny|Whether to use Smallrye Mutiny instead of CompletionStage for asynchronous computation. Only valid when library is set to quarkus.| |false|
8787
|useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false|
88+
|useQuarkusSecurityAnnotations|Whether to generate Quarkus security annotations (@Authenticated, @RolesAllowed, @PermitAll). Only valid when library is set to quarkus.| |false|
8889
|useSwaggerAnnotations|Whether to generate Swagger annotations.| |true|
8990
|useSwaggerV3Annotations|Whether to generate Swagger v3 (OpenAPI v3) annotations.| |false|
9091
|useTags|use tags for creating interface and controller classnames| |false|

docs/generators/jaxrs-spec.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
8686
|useMicroProfileOpenAPIAnnotations|Whether to generate Microprofile OpenAPI annotations. Only valid when library is set to quarkus.| |false|
8787
|useMutiny|Whether to use Smallrye Mutiny instead of CompletionStage for asynchronous computation. Only valid when library is set to quarkus.| |false|
8888
|useOneOfInterfaces|whether to use a java interface to describe a set of oneOf options, where each option is a class that implements the interface| |false|
89+
|useQuarkusSecurityAnnotations|Whether to generate Quarkus security annotations (@Authenticated, @RolesAllowed, @PermitAll). Only valid when library is set to quarkus.| |false|
8990
|useSwaggerAnnotations|Whether to generate Swagger annotations.| |true|
9091
|useSwaggerV3Annotations|Whether to generate Swagger v3 (OpenAPI v3) annotations.| |false|
9192
|useTags|use tags for creating interface and controller classnames| |false|

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen {
5353
public static final String USE_MUTINY = "useMutiny";
5454
public static final String OPEN_API_SPEC_FILE_LOCATION = "openApiSpecFileLocation";
5555
public static final String GENERATE_JSON_CREATOR = "generateJsonCreator";
56+
public static final String USE_QUARKUS_SECURITY_ANNOTATIONS = "useQuarkusSecurityAnnotations";
5657

5758
public static final String QUARKUS_LIBRARY = "quarkus";
5859
public static final String THORNTAIL_LIBRARY = "thorntail";
@@ -68,6 +69,7 @@ public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen {
6869
private boolean useSwaggerV3Annotations = false;
6970
private boolean useMicroProfileOpenAPIAnnotations = false;
7071
private boolean useMutiny = false;
72+
private boolean useQuarkusSecurityAnnotations = false;
7173

7274
@Getter @Setter
7375
protected boolean generateJsonCreator = true;
@@ -147,6 +149,7 @@ public JavaJAXRSSpecServerCodegen() {
147149
cliOptions.add(CliOption.newString(OPEN_API_SPEC_FILE_LOCATION, "Location where the file containing the spec will be generated in the output folder. No file generated when set to null or empty string."));
148150
cliOptions.add(CliOption.newBoolean(SUPPORT_ASYNC, "Wrap responses in CompletionStage type, allowing asynchronous computation (requires JAX-RS 2.1).", supportAsync));
149151
cliOptions.add(CliOption.newBoolean(USE_MUTINY, "Whether to use Smallrye Mutiny instead of CompletionStage for asynchronous computation. Only valid when library is set to quarkus.", useMutiny));
152+
cliOptions.add(CliOption.newBoolean(USE_QUARKUS_SECURITY_ANNOTATIONS, "Whether to generate Quarkus security annotations (@Authenticated, @RolesAllowed, @PermitAll). Only valid when library is set to quarkus.", useQuarkusSecurityAnnotations));
150153
cliOptions.add(CliOption.newBoolean(GENERATE_JSON_CREATOR, "Whether to generate @JsonCreator constructor for required properties.", generateJsonCreator));
151154
}
152155

@@ -189,6 +192,10 @@ public void processOpts() {
189192
convertPropertyToBooleanAndWriteBack(USE_MUTINY, value -> useMutiny = value);
190193
}
191194

195+
if (QUARKUS_LIBRARY.equals(library)) {
196+
convertPropertyToBooleanAndWriteBack(USE_QUARKUS_SECURITY_ANNOTATIONS, value -> useQuarkusSecurityAnnotations = value);
197+
}
198+
192199
convertPropertyToBooleanAndWriteBack(GENERATE_JSON_CREATOR, this::setGenerateJsonCreator);
193200

194201
if (additionalProperties.containsKey(OPEN_API_SPEC_FILE_LOCATION)) {

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,4 +1545,45 @@ public void generateQuarkusConcreteClassDoesNotAddResponseStatusAnnotation() thr
15451545
"@ResponseStatus",
15461546
"import org.jboss.resteasy.reactive.ResponseStatus");
15471547
}
1548+
1549+
@Test
1550+
public void useQuarkusSecurityAnnotationsIsRegisteredWithDefaultFalse() {
1551+
final JavaJAXRSSpecServerCodegen codegen = new JavaJAXRSSpecServerCodegen();
1552+
Assert.assertTrue(
1553+
codegen.cliOptions().stream()
1554+
.anyMatch(opt -> USE_QUARKUS_SECURITY_ANNOTATIONS.equals(opt.getOpt()) && "false".equals(opt.getDefault())),
1555+
"useQuarkusSecurityAnnotations should be a registered CLI option defaulting to false"
1556+
);
1557+
}
1558+
1559+
@Test
1560+
public void useQuarkusSecurityAnnotationsDefaultsToFalseForQuarkusLibrary() {
1561+
codegen.setLibrary(QUARKUS_LIBRARY);
1562+
codegen.processOpts();
1563+
1564+
Assert.assertFalse(
1565+
(boolean) codegen.additionalProperties().getOrDefault(USE_QUARKUS_SECURITY_ANNOTATIONS, false)
1566+
);
1567+
}
1568+
1569+
@Test
1570+
public void useQuarkusSecurityAnnotationsCanBeEnabledForQuarkusLibrary() {
1571+
codegen.setLibrary(QUARKUS_LIBRARY);
1572+
codegen.additionalProperties().put(USE_QUARKUS_SECURITY_ANNOTATIONS, true);
1573+
codegen.processOpts();
1574+
1575+
new ConfigAssert(codegen.additionalProperties())
1576+
.assertValue(USE_QUARKUS_SECURITY_ANNOTATIONS, true);
1577+
}
1578+
1579+
@Test
1580+
public void useQuarkusSecurityAnnotationsNotProcessedForNonQuarkusLibrary() {
1581+
// flag is only consumed when library=quarkus; for other libraries the block is skipped
1582+
codegen.additionalProperties().put(USE_QUARKUS_SECURITY_ANNOTATIONS, true);
1583+
codegen.processOpts();
1584+
1585+
// convertPropertyToBooleanAndWriteBack was never called, so the value was never
1586+
// written back as a boolean — the key holds the raw Object we put in, not false
1587+
Assert.assertNotEquals(false, codegen.additionalProperties().get(USE_QUARKUS_SECURITY_ANNOTATIONS));
1588+
}
15481589
}

0 commit comments

Comments
 (0)