Skip to content

Commit e92ab2e

Browse files
committed
added more tests to cover edge cases
1 parent 0e19ebe commit e92ab2e

6 files changed

Lines changed: 73 additions & 67 deletions

File tree

docs/generators/jaxrs-cxf-cdi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ These options may be applied as additional-properties (cli) or configOptions (pl
8282
|title|a title describing the application| |OpenAPI Server|
8383
|useBeanValidation|Use BeanValidation API annotations| |true|
8484
|useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false|
85+
|useJakartaSecurityAnnotation|Whether to generate Jakarta security annotations (@RolesAllowed, @PermitAll). Currently only supported when library is set to quarkus.| |false|
8586
|useMicroProfileOpenAPIAnnotations|Whether to generate Microprofile OpenAPI annotations. Only valid when library is set to quarkus.| |false|
8687
|useMutiny|Whether to use Smallrye Mutiny instead of CompletionStage for asynchronous computation. Only valid when library is set to quarkus.| |false|
8788
|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|
8989
|useSwaggerAnnotations|Whether to generate Swagger annotations.| |true|
9090
|useSwaggerV3Annotations|Whether to generate Swagger v3 (OpenAPI v3) annotations.| |false|
9191
|useTags|use tags for creating interface and controller classnames| |false|

docs/generators/jaxrs-spec.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ These options may be applied as additional-properties (cli) or configOptions (pl
8383
|title|a title describing the application| |OpenAPI Server|
8484
|useBeanValidation|Use BeanValidation API annotations| |true|
8585
|useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false|
86+
|useJakartaSecurityAnnotation|Whether to generate Jakarta security annotations (@RolesAllowed, @PermitAll). Currently only supported when library is set to quarkus.| |false|
8687
|useMicroProfileOpenAPIAnnotations|Whether to generate Microprofile OpenAPI annotations. Only valid when library is set to quarkus.| |false|
8788
|useMutiny|Whether to use Smallrye Mutiny instead of CompletionStage for asynchronous computation. Only valid when library is set to quarkus.| |false|
8889
|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|
9090
|useSwaggerAnnotations|Whether to generate Swagger annotations.| |true|
9191
|useSwaggerV3Annotations|Whether to generate Swagger v3 (OpenAPI v3) annotations.| |false|
9292
|useTags|use tags for creating interface and controller classnames| |false|

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +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";
56+
public static final String USE_JAKARTA_SECURITY_ANNOTATION = "useJakartaSecurityAnnotation";
5757

5858
public static final String QUARKUS_LIBRARY = "quarkus";
5959
public static final String THORNTAIL_LIBRARY = "thorntail";
@@ -69,7 +69,7 @@ public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen {
6969
private boolean useSwaggerV3Annotations = false;
7070
private boolean useMicroProfileOpenAPIAnnotations = false;
7171
private boolean useMutiny = false;
72-
private boolean useQuarkusSecurityAnnotations = false;
72+
private boolean useJakartaSecurity = false;
7373

7474
@Getter @Setter
7575
protected boolean generateJsonCreator = true;
@@ -149,7 +149,7 @@ public JavaJAXRSSpecServerCodegen() {
149149
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."));
150150
cliOptions.add(CliOption.newBoolean(SUPPORT_ASYNC, "Wrap responses in CompletionStage type, allowing asynchronous computation (requires JAX-RS 2.1).", supportAsync));
151151
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));
152+
cliOptions.add(CliOption.newBoolean(USE_JAKARTA_SECURITY_ANNOTATION, "Whether to generate Jakarta security annotations (@RolesAllowed, @PermitAll). Currently only supported when library is set to quarkus.", useJakartaSecurity));
153153
cliOptions.add(CliOption.newBoolean(GENERATE_JSON_CREATOR, "Whether to generate @JsonCreator constructor for required properties.", generateJsonCreator));
154154
}
155155

@@ -193,7 +193,7 @@ public void processOpts() {
193193
}
194194

195195
if (QUARKUS_LIBRARY.equals(library)) {
196-
convertPropertyToBooleanAndWriteBack(USE_QUARKUS_SECURITY_ANNOTATIONS, value -> useQuarkusSecurityAnnotations = value);
196+
convertPropertyToBooleanAndWriteBack(USE_JAKARTA_SECURITY_ANNOTATION, value -> useJakartaSecurity = value);
197197
}
198198

199199
convertPropertyToBooleanAndWriteBack(GENERATE_JSON_CREATOR, this::setGenerateJsonCreator);
@@ -367,10 +367,10 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
367367
additionalProperties.put("hasResponseStatusAnnotations", true);
368368
}
369369
}
370-
if (QUARKUS_LIBRARY.equals(getLibrary()) && useQuarkusSecurityAnnotations) {
370+
if (QUARKUS_LIBRARY.equals(getLibrary()) && useJakartaSecurity) {
371371
for (CodegenOperation op : objs.getOperations().getOperation()) {
372372
if (shouldAddAuthenticatedAnnotation(op)){
373-
op.vendorExtensions.put("x-quarkus-authenticated", true);
373+
op.vendorExtensions.put("x-jakarta-authenticated", true);
374374
}
375375
}
376376
}

modules/openapi-generator/src/main/resources/JavaJaxRS/spec/libraries/quarkus/apiInterface.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
{{#vendorExtensions.x-java-success-response-code}}
5454
@ResponseStatus({{{vendorExtensions.x-java-success-response-code}}})
5555
{{/vendorExtensions.x-java-success-response-code}}
56-
{{#vendorExtensions.x-quarkus-authenticated}}
57-
@io.quarkus.security.Authenticated
58-
{{/vendorExtensions.x-quarkus-authenticated}}
56+
{{#vendorExtensions.x-jakarta-authenticated}}
57+
@jakarta.annotation.security.RolesAllowed({"**"})
58+
{{/vendorExtensions.x-jakarta-authenticated}}
5959
{{#supportAsync}}{{>returnAsyncTypeInterface}}{{/supportAsync}}{{^supportAsync}}{{#returnJBossResponse}}{{>returnResponseTypeInterface}}{{/returnJBossResponse}}{{^returnJBossResponse}}{{#returnResponse}}Response{{/returnResponse}}{{^returnResponse}}{{>returnTypeInterface}}{{/returnResponse}}{{/returnJBossResponse}}{{/supportAsync}} {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>cookieParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}});

modules/openapi-generator/src/main/resources/JavaJaxRS/spec/libraries/quarkus/apiMethod.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@
4747
{{^vendorExtensions.x-java-is-response-void}}@org.eclipse.microprofile.openapi.annotations.media.Content(schema = @org.eclipse.microprofile.openapi.annotations.media.Schema(implementation = {{{baseType}}}.class{{#vendorExtensions.x-microprofile-open-api-return-schema-container}}, type = {{{.}}} {{/vendorExtensions.x-microprofile-open-api-return-schema-container}}{{#vendorExtensions.x-microprofile-open-api-return-unique-items}}, uniqueItems = true {{/vendorExtensions.x-microprofile-open-api-return-unique-items}})){{/vendorExtensions.x-java-is-response-void}}
4848
}){{^-last}},{{/-last}}{{/responses}}
4949
}){{/hasProduces}}{{/useMicroProfileOpenAPIAnnotations}}
50-
{{#vendorExtensions.x-quarkus-authenticated}}
51-
@io.quarkus.security.Authenticated
52-
{{/vendorExtensions.x-quarkus-authenticated}}
50+
{{#vendorExtensions.x-jakarta-authenticated}}
51+
@jakarta.annotation.security.RolesAllowed({"**"})
52+
{{/vendorExtensions.x-jakarta-authenticated}}
5353
public {{#supportAsync}}{{#useMutiny}}Uni{{/useMutiny}}{{^useMutiny}}CompletionStage{{/useMutiny}}<{{/supportAsync}}{{#returnJBossResponse}}{{>returnResponseTypeInterface}}{{/returnJBossResponse}}{{^returnJBossResponse}}Response{{/returnJBossResponse}}{{#supportAsync}}>{{/supportAsync}} {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>cookieParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{^-last}},{{/-last}}{{/allParams}}) {
5454
return {{#supportAsync}}{{#useMutiny}}Uni.createFrom().item({{/useMutiny}}{{^useMutiny}}CompletableFuture.supplyAsync(() -> {{/useMutiny}}{{/supportAsync}}Response.ok().entity("magic!").build(){{#supportAsync}}){{/supportAsync}};
5555
}

0 commit comments

Comments
 (0)