Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/generators/jaxrs-cxf-cdi.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,10 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|title|a title describing the application| |OpenAPI Server|
|useBeanValidation|Use BeanValidation API annotations| |true|
|useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false|
|useJakartaSecurityAnnotation|Whether to generate Jakarta security annotations (@RolesAllowed, @PermitAll). Currently only supported when library is set to quarkus.| |false|
|useMicroProfileOpenAPIAnnotations|Whether to generate Microprofile OpenAPI annotations. Only valid when library is set to quarkus.| |false|
|useMutiny|Whether to use Smallrye Mutiny instead of CompletionStage for asynchronous computation. Only valid when library is set to quarkus.| |false|
|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|
|useQuarkusSecurityAnnotations|Whether to generate Quarkus security annotations (@Authenticated, @RolesAllowed, @PermitAll). Only valid when library is set to quarkus.| |false|
|useSwaggerAnnotations|Whether to generate Swagger annotations.| |true|
|useSwaggerV3Annotations|Whether to generate Swagger v3 (OpenAPI v3) annotations.| |false|
|useTags|use tags for creating interface and controller classnames| |false|
Expand Down
2 changes: 1 addition & 1 deletion docs/generators/jaxrs-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|title|a title describing the application| |OpenAPI Server|
|useBeanValidation|Use BeanValidation API annotations| |true|
|useJakartaEe|whether to use Jakarta EE namespace instead of javax| |false|
|useJakartaSecurityAnnotation|Whether to generate Jakarta security annotations (@RolesAllowed, @PermitAll). Currently only supported when library is set to quarkus.| |false|
|useMicroProfileOpenAPIAnnotations|Whether to generate Microprofile OpenAPI annotations. Only valid when library is set to quarkus.| |false|
|useMutiny|Whether to use Smallrye Mutiny instead of CompletionStage for asynchronous computation. Only valid when library is set to quarkus.| |false|
|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|
|useQuarkusSecurityAnnotations|Whether to generate Quarkus security annotations (@Authenticated, @RolesAllowed, @PermitAll). Only valid when library is set to quarkus.| |false|
|useSwaggerAnnotations|Whether to generate Swagger annotations.| |true|
|useSwaggerV3Annotations|Whether to generate Swagger v3 (OpenAPI v3) annotations.| |false|
|useTags|use tags for creating interface and controller classnames| |false|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen {
public static final String USE_MUTINY = "useMutiny";
public static final String OPEN_API_SPEC_FILE_LOCATION = "openApiSpecFileLocation";
public static final String GENERATE_JSON_CREATOR = "generateJsonCreator";
public static final String USE_QUARKUS_SECURITY_ANNOTATIONS = "useQuarkusSecurityAnnotations";
public static final String USE_JAKARTA_SECURITY_ANNOTATION = "useJakartaSecurityAnnotation";

public static final String QUARKUS_LIBRARY = "quarkus";
public static final String THORNTAIL_LIBRARY = "thorntail";
Expand All @@ -69,7 +69,7 @@ public class JavaJAXRSSpecServerCodegen extends AbstractJavaJAXRSServerCodegen {
private boolean useSwaggerV3Annotations = false;
private boolean useMicroProfileOpenAPIAnnotations = false;
private boolean useMutiny = false;
private boolean useQuarkusSecurityAnnotations = false;
private boolean useJakartaSecurity = false;

@Getter @Setter
protected boolean generateJsonCreator = true;
Expand Down Expand Up @@ -149,7 +149,7 @@ public JavaJAXRSSpecServerCodegen() {
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."));
cliOptions.add(CliOption.newBoolean(SUPPORT_ASYNC, "Wrap responses in CompletionStage type, allowing asynchronous computation (requires JAX-RS 2.1).", supportAsync));
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));
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));
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));
cliOptions.add(CliOption.newBoolean(GENERATE_JSON_CREATOR, "Whether to generate @JsonCreator constructor for required properties.", generateJsonCreator));
}

Expand Down Expand Up @@ -193,7 +193,7 @@ public void processOpts() {
}

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

convertPropertyToBooleanAndWriteBack(GENERATE_JSON_CREATOR, this::setGenerateJsonCreator);
Expand Down Expand Up @@ -367,6 +367,13 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
additionalProperties.put("hasResponseStatusAnnotations", true);
}
}
if (QUARKUS_LIBRARY.equals(getLibrary()) && useJakartaSecurity) {
for (CodegenOperation op : objs.getOperations().getOperation()) {
if (shouldAddAuthenticatedAnnotation(op)){
op.vendorExtensions.put("x-jakarta-authenticated", true);
}
}
}
return objs;
}

Expand All @@ -391,4 +398,17 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
}
return result;
}

protected boolean shouldAddAuthenticatedAnnotation(CodegenOperation op) {
if (!op.hasAuthMethods) {
return false;
}
return op.authMethods.stream().anyMatch(m ->
(Boolean.TRUE.equals(m.isOAuth) && (m.scopes == null || m.scopes.isEmpty())) ||
(Boolean.TRUE.equals(m.isOpenId) && (m.scopes == null || m.scopes.isEmpty())) ||
Boolean.TRUE.equals(m.isBasicBasic) ||
Boolean.TRUE.equals(m.isBasicBearer) ||
Boolean.TRUE.equals(m.isApiKey)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@
{{#vendorExtensions.x-java-success-response-code}}
@ResponseStatus({{{vendorExtensions.x-java-success-response-code}}})
{{/vendorExtensions.x-java-success-response-code}}
{{#vendorExtensions.x-jakarta-authenticated}}
@jakarta.annotation.security.RolesAllowed({"**"})
{{/vendorExtensions.x-jakarta-authenticated}}
{{#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}});
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
{{^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}}
}){{^-last}},{{/-last}}{{/responses}}
}){{/hasProduces}}{{/useMicroProfileOpenAPIAnnotations}}
{{#vendorExtensions.x-jakarta-authenticated}}
@jakarta.annotation.security.RolesAllowed({"**"})
{{/vendorExtensions.x-jakarta-authenticated}}
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}}) {
return {{#supportAsync}}{{#useMutiny}}Uni.createFrom().item({{/useMutiny}}{{^useMutiny}}CompletableFuture.supplyAsync(() -> {{/useMutiny}}{{/supportAsync}}Response.ok().entity("magic!").build(){{#supportAsync}}){{/supportAsync}};
}
Loading
Loading