Skip to content
Open
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
3 changes: 1 addition & 2 deletions docs/generators/java-microprofile.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|licenseName|The name of the license| |Unlicense|
|licenseUrl|The URL of the license| |http://unlicense.org|
|microprofileFramework|Framework for microprofile. Possible values "kumuluzee"| |null|
|microprofileGlobalExceptionMapper|Should ApiExceptionMapper be annotated with @Provider making it a global exception mapper| |true|
|microprofileMutiny|Whether to use async types for microprofile (currently only Smallrye Mutiny is supported).| |null|
|microprofileRegisterExceptionMapper|Should generated API Clients be annotated with @RegisterProvider(ApiExceptionMapper.class).| |true|
|microprofileRegisterExceptionMapper|Should generated API Clients be annotated with @RegisterProvider(ApiExceptionMapper.class).| |false|
|microprofileRestClientVersion|Version of MicroProfile Rest Client API.| |null|
|modelPackage|package for generated models| |org.openapitools.client.model|
|openApiNullable|Enable OpenAPI Jackson Nullable library. Not supported by `microprofile` library.| |true|
Expand Down
3 changes: 1 addition & 2 deletions docs/generators/java.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|licenseName|The name of the license| |Unlicense|
|licenseUrl|The URL of the license| |http://unlicense.org|
|microprofileFramework|Framework for microprofile. Possible values "kumuluzee"| |null|
|microprofileGlobalExceptionMapper|Should ApiExceptionMapper be annotated with @Provider making it a global exception mapper| |true|
|microprofileMutiny|Whether to use async types for microprofile (currently only Smallrye Mutiny is supported).| |null|
|microprofileRegisterExceptionMapper|Should generated API Clients be annotated with @RegisterProvider(ApiExceptionMapper.class).| |true|
|microprofileRegisterExceptionMapper|Should generated API Clients be annotated with @RegisterProvider(ApiExceptionMapper.class).| |false|
|microprofileRestClientVersion|Version of MicroProfile Rest Client API.| |null|
|modelPackage|package for generated models| |org.openapitools.client.model|
|openApiNullable|Enable OpenAPI Jackson Nullable library. Not supported by `microprofile` library.| |true|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public class JavaClientCodegen extends AbstractJavaCodegen
public static final String CASE_INSENSITIVE_RESPONSE_HEADERS = "caseInsensitiveResponseHeaders";
public static final String MICROPROFILE_FRAMEWORK = "microprofileFramework";
public static final String MICROPROFILE_MUTINY = "microprofileMutiny";
public static final String MICROPROFILE_GLOBAL_EXCEPTION_MAPPER = "microprofileGlobalExceptionMapper";
public static final String MICROPROFILE_REGISTER_EXCEPTION_MAPPER = "microprofileRegisterExceptionMapper";
public static final String USE_ABSTRACTION_FOR_FILES = "useAbstractionForFiles";
public static final String DYNAMIC_OPERATIONS = "dynamicOperations";
Expand Down Expand Up @@ -128,8 +127,7 @@ public class JavaClientCodegen extends AbstractJavaCodegen
@Setter protected String microprofileFramework = MICROPROFILE_DEFAULT;
@Setter protected String microprofileRestClientVersion = MICROPROFILE_REST_CLIENT_DEFAULT_VERSION;
@Setter protected boolean microprofileMutiny = false;
@Setter protected boolean microProfileGlobalExceptionMapper = true;
@Setter protected boolean microProfileRegisterExceptionMapper = true;
@Setter protected boolean microProfileRegisterExceptionMapper = false;
@Setter protected String configKey = null;
@Setter(AccessLevel.PRIVATE) protected boolean configKeyFromClassName = false;

Expand Down Expand Up @@ -240,8 +238,7 @@ public JavaClientCodegen() {
cliOptions.add(CliOption.newBoolean(CASE_INSENSITIVE_RESPONSE_HEADERS, "Make API response's headers case-insensitive. Available on " + OKHTTP_GSON + ", " + JERSEY2 + " libraries"));
cliOptions.add(CliOption.newString(MICROPROFILE_FRAMEWORK, "Framework for microprofile. Possible values \"kumuluzee\""));
cliOptions.add(CliOption.newString(MICROPROFILE_MUTINY, "Whether to use async types for microprofile (currently only Smallrye Mutiny is supported)."));
cliOptions.add(CliOption.newString(MICROPROFILE_REGISTER_EXCEPTION_MAPPER, "Should generated API Clients be annotated with @RegisterProvider(ApiExceptionMapper.class).").defaultValue("true"));
cliOptions.add(CliOption.newString(MICROPROFILE_GLOBAL_EXCEPTION_MAPPER, "Should ApiExceptionMapper be annotated with @Provider making it a global exception mapper").defaultValue("true"));
cliOptions.add(CliOption.newBoolean(MICROPROFILE_REGISTER_EXCEPTION_MAPPER, "Should generated API Clients be annotated with @RegisterProvider(ApiExceptionMapper.class).", this.microProfileRegisterExceptionMapper));
cliOptions.add(CliOption.newBoolean(USE_ABSTRACTION_FOR_FILES, "Use alternative types instead of java.io.File to allow passing bytes without a file on disk. Available on resttemplate, webclient, restclient, libraries"));
cliOptions.add(CliOption.newBoolean(DYNAMIC_OPERATIONS, "Generate operations dynamically at runtime from an OAS", this.dynamicOperations));
cliOptions.add(CliOption.newBoolean(SUPPORT_STREAMING, "Support streaming endpoint (beta)", this.supportStreaming));
Expand Down Expand Up @@ -363,6 +360,11 @@ public void processOpts() {
this.jackson = !additionalProperties.containsKey(CodegenConstants.SERIALIZATION_LIBRARY) ||
SERIALIZATION_LIBRARY_JACKSON.equals(additionalProperties.get(CodegenConstants.SERIALIZATION_LIBRARY));

// use runtime exceptions for microprofile
if (libMicroprofile) {
useRuntimeException = true;
}

convertPropertyToBooleanAndWriteBack(CodegenConstants.USE_ONEOF_DISCRIMINATOR_LOOKUP, this::setUseOneOfDiscriminatorLookup);

// RxJava
Expand Down Expand Up @@ -399,11 +401,9 @@ public void processOpts() {
}
convertPropertyToStringAndWriteBack(MICROPROFILE_FRAMEWORK, this::setMicroprofileFramework);

convertPropertyToBooleanAndWriteBack(MICROPROFILE_GLOBAL_EXCEPTION_MAPPER, this::setMicroProfileGlobalExceptionMapper);
convertPropertyToBooleanAndWriteBack(MICROPROFILE_REGISTER_EXCEPTION_MAPPER, this::setMicroProfileRegisterExceptionMapper);

additionalProperties.put(MICROPROFILE_REGISTER_EXCEPTION_MAPPER, microProfileRegisterExceptionMapper);
additionalProperties.put(MICROPROFILE_GLOBAL_EXCEPTION_MAPPER, microProfileGlobalExceptionMapper);

convertPropertyToBooleanAndWriteBack(MICROPROFILE_MUTINY, this::setMicroprofileMutiny);

Expand Down Expand Up @@ -709,8 +709,19 @@ public void processOpts() {
String pomTemplate = mpRestClientVersions.get(microprofileRestClientVersion).pomTemplate;
supportingFiles.add(new SupportingFile(pomTemplate, "", "pom.xml"));
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
supportingFiles.add(new SupportingFile("api_exception.mustache", apiExceptionFolder, "ApiException.java"));
supportingFiles.add(new SupportingFile("api_exception_mapper.mustache", apiExceptionFolder, "ApiExceptionMapper.java"));

if (useRuntimeException) {
if (microProfileRegisterExceptionMapper) {
supportingFiles.add(new SupportingFile("api_exception.mustache", apiExceptionFolder, "ApiException.java"));
supportingFiles.add(new SupportingFile("api_exception_mapper.mustache", apiExceptionFolder, "ApiExceptionMapper.java"));
}
} else {
supportingFiles.add(new SupportingFile("api_exception.mustache", apiExceptionFolder, "ApiException.java"));
if (microProfileRegisterExceptionMapper) {
supportingFiles.add(new SupportingFile("api_exception_mapper.mustache", apiExceptionFolder, "ApiExceptionMapper.java"));
}
}

if (getSerializationLibrary() == null) {
LOGGER.info("No serializationLibrary configured, using '{}' as fallback", SERIALIZATION_LIBRARY_JSONB);
setSerializationLibrary(SERIALIZATION_LIBRARY_JSONB);
Expand Down Expand Up @@ -803,7 +814,7 @@ public void processOpts() {
additionalProperties.remove(SERIALIZATION_LIBRARY_JSONB);
break;
}

if (isLibrary(FEIGN)) {
additionalProperties.put("feign-okhttp", "true");
} else if (isLibrary(FEIGN_HC5)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import {{rootJavaEEPackage}}.validation.Valid;
{{#microprofileRegisterExceptionMapper}}
import org.eclipse.microprofile.rest.client.annotation.RegisterProvider;
{{/microprofileRegisterExceptionMapper}}
{{^microprofileServer}}
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
{{/microprofileServer}}

{{#appName}}
/**
Expand Down Expand Up @@ -76,10 +78,10 @@ public interface {{classname}} {
@Produces({ {{#produces}}"{{{mediaType}}}"{{^-last}}, {{/-last}}{{/produces}} })
{{/hasProduces}}
{{^singleRequestParameter}}
{{^vendorExtensions.x-java-is-response-void}}{{#microprofileServer}}{{> server_operation}}{{/microprofileServer}}{{^microprofileServer}}{{> client_operation}}{{/microprofileServer}}{{/vendorExtensions.x-java-is-response-void}}{{#vendorExtensions.x-java-is-response-void}}{{#microprofileMutiny}}Uni<Void>{{/microprofileMutiny}}{{^microprofileMutiny}}void{{/microprofileMutiny}}{{/vendorExtensions.x-java-is-response-void}} {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{>cookieParams}}{{^-last}}, {{/-last}}{{/allParams}}) throws ApiException, ProcessingException;
{{^vendorExtensions.x-java-is-response-void}}{{#microprofileServer}}{{> server_operation}}{{/microprofileServer}}{{^microprofileServer}}{{> client_operation}}{{/microprofileServer}}{{/vendorExtensions.x-java-is-response-void}}{{#vendorExtensions.x-java-is-response-void}}{{#microprofileMutiny}}Uni<Void>{{/microprofileMutiny}}{{^microprofileMutiny}}void{{/microprofileMutiny}}{{/vendorExtensions.x-java-is-response-void}} {{nickname}}({{#allParams}}{{>queryParams}}{{>pathParams}}{{>headerParams}}{{>bodyParams}}{{>formParams}}{{>cookieParams}}{{^-last}}, {{/-last}}{{/allParams}}) throws {{#useRuntimeException}}WebApplicationException{{/useRuntimeException}}{{^useRuntimeException}}ApiException{{/useRuntimeException}}, ProcessingException;
{{/singleRequestParameter}}
{{#singleRequestParameter}}
{{^vendorExtensions.x-java-is-response-void}}{{#microprofileMutiny}}Uni<{{{returnType}}}>{{/microprofileMutiny}}{{^microprofileMutiny}}{{{returnType}}}{{/microprofileMutiny}}{{/vendorExtensions.x-java-is-response-void}}{{#vendorExtensions.x-java-is-response-void}}{{#microprofileMutiny}}Uni<Void>{{/microprofileMutiny}}{{^microprofileMutiny}}void{{/microprofileMutiny}}{{/vendorExtensions.x-java-is-response-void}} {{nickname}}({{#hasNonBodyParams}}@BeanParam {{operationIdCamelCase}}Request request{{/hasNonBodyParams}}{{#bodyParams}}{{#hasNonBodyParams}}, {{/hasNonBodyParams}}{{>bodyParams}}{{/bodyParams}}) throws ApiException, ProcessingException;
{{^vendorExtensions.x-java-is-response-void}}{{#microprofileMutiny}}Uni<{{{returnType}}}>{{/microprofileMutiny}}{{^microprofileMutiny}}{{{returnType}}}{{/microprofileMutiny}}{{/vendorExtensions.x-java-is-response-void}}{{#vendorExtensions.x-java-is-response-void}}{{#microprofileMutiny}}Uni<Void>{{/microprofileMutiny}}{{^microprofileMutiny}}void{{/microprofileMutiny}}{{/vendorExtensions.x-java-is-response-void}} {{nickname}}({{#hasNonBodyParams}}@BeanParam {{operationIdCamelCase}}Request request{{/hasNonBodyParams}}{{#bodyParams}}{{#hasNonBodyParams}}, {{/hasNonBodyParams}}{{>bodyParams}}{{/bodyParams}}) throws {{#useRuntimeException}}WebApplicationException{{/useRuntimeException}}{{^useRuntimeException}}ApiException{{/useRuntimeException}}, ProcessingException;
{{#hasNonBodyParams}}
public class {{operationIdCamelCase}}Request {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@
package {{apiPackage}};

import {{rootJavaEEPackage}}.ws.rs.core.Response;
{{#useRuntimeException}}
import {{rootJavaEEPackage}}.ws.rs.WebApplicationException;
{{/useRuntimeException}}

public class ApiException extends{{#useRuntimeException}} RuntimeException {{/useRuntimeException}}{{^useRuntimeException}} Exception {{/useRuntimeException}}{
public class ApiException extends{{#useRuntimeException}} WebApplicationException {{/useRuntimeException}}{{^useRuntimeException}} Exception {{/useRuntimeException}}{

private static final long serialVersionUID = 1L;
{{#useRuntimeException}}

public ApiException(Response response) {
super(response);
}
{{/useRuntimeException}}
{{^useRuntimeException}}
private Response response;

public ApiException() {
Expand All @@ -20,4 +30,5 @@ public class ApiException extends{{#useRuntimeException}} RuntimeException {{/us
public Response getResponse() {
return this.response;
}
{{/useRuntimeException}}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@ package {{apiPackage}};

import {{rootJavaEEPackage}}.ws.rs.core.MultivaluedMap;
import {{rootJavaEEPackage}}.ws.rs.core.Response;
{{#microprofileGlobalExceptionMapper}}
import {{rootJavaEEPackage}}.ws.rs.ext.Provider;
{{/microprofileGlobalExceptionMapper}}
import org.eclipse.microprofile.rest.client.ext.ResponseExceptionMapper;

{{#microprofileGlobalExceptionMapper}}
@Provider
{{/microprofileGlobalExceptionMapper}}
public class ApiExceptionMapper
implements ResponseExceptionMapper<ApiException> {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1488,8 +1488,13 @@ public void testDefaultMicroprofileRestClientVersion() {

validateJavaSourceFiles(files);
assertThat(files).contains(output.resolve("pom.xml").toFile());
assertThat(output.resolve("src/main/java/org/openapitools/client/api/ApiException.java")).doesNotExist();
assertThat(output.resolve("src/main/java/org/openapitools/client/api/ApiExceptionMapper.java")).doesNotExist();
assertThat(output.resolve("src/main/java/org/openapitools/client/api/PetApi.java")).content()
.contains("import javax.");
.contains("import javax.")
.doesNotContain("ApiException")
.contains("WebApplicationException");
;
assertThat(output.resolve("pom.xml")).content()
.contains(
"<microprofile.rest.client.api.version>2.0</microprofile.rest.client.api.version>",
Expand All @@ -1502,7 +1507,11 @@ public void testDefaultMicroprofileRestClientVersion() {
public void testMicroprofileRestClientVersion_1_4_1() {
final Path output = newTempFolder();
final CodegenConfigurator configurator = new CodegenConfigurator()
.setAdditionalProperties(Map.of(JavaClientCodegen.MICROPROFILE_REST_CLIENT_VERSION, "1.4.1"))
.setAdditionalProperties(Map.of(
JavaClientCodegen.MICROPROFILE_REST_CLIENT_VERSION, "1.4.1",
JavaClientCodegen.MICROPROFILE_REGISTER_EXCEPTION_MAPPER, "true",
USE_RUNTIME_EXCEPTION,"false"
))
.setGeneratorName(JAVA_GENERATOR)
.setLibrary(JavaClientCodegen.MICROPROFILE)
.setInputSpec("src/test/resources/3_0/petstore.yaml")
Expand All @@ -1512,8 +1521,12 @@ public void testMicroprofileRestClientVersion_1_4_1() {

validateJavaSourceFiles(files);
assertThat(files).contains(output.resolve("pom.xml").toFile());
assertThat(output.resolve("src/main/java/org/openapitools/client/api/ApiException.java")).exists();
assertThat(output.resolve("src/main/java/org/openapitools/client/api/ApiExceptionMapper.java")).exists();
assertThat(output.resolve("src/main/java/org/openapitools/client/api/PetApi.java")).content()
.contains("import javax.");
.contains("import javax.")
.contains("ApiException")
.doesNotContain("WebApplicationException");
assertThat(output.resolve("pom.xml")).content()
.contains(
"<microprofile.rest.client.api.version>1.4.1</microprofile.rest.client.api.version>",
Expand Down Expand Up @@ -1546,7 +1559,10 @@ public void testMicroprofileRestClientIncorrectVersion() {
public void testMicroprofileRestClientVersion_3_0() {
final Path output = newTempFolder();
final CodegenConfigurator configurator = new CodegenConfigurator()
.setAdditionalProperties(Map.of(JavaClientCodegen.MICROPROFILE_REST_CLIENT_VERSION, "3.0"))
.setAdditionalProperties(Map.of(
JavaClientCodegen.MICROPROFILE_REST_CLIENT_VERSION, "3.0",
JavaClientCodegen.USE_RUNTIME_EXCEPTION, "false"
))
.setGeneratorName(JAVA_GENERATOR)
.setLibrary(JavaClientCodegen.MICROPROFILE)
.setInputSpec("src/test/resources/3_0/petstore.yaml")
Expand All @@ -1556,8 +1572,12 @@ public void testMicroprofileRestClientVersion_3_0() {

validateJavaSourceFiles(files);
assertThat(files).contains(output.resolve("pom.xml").toFile());
assertThat(output.resolve("src/main/java/org/openapitools/client/api/ApiException.java")).exists();
assertThat(output.resolve("src/main/java/org/openapitools/client/api/ApiExceptionMapper.java")).doesNotExist();
assertThat(output.resolve("src/main/java/org/openapitools/client/api/PetApi.java")).content()
.contains("import jakarta.");
.contains("import jakarta.")
.contains("ApiException")
.doesNotContain("WebApplicationException");
assertThat(output.resolve("pom.xml")).content()
.contains(
"<microprofile.rest.client.api.version>3.0</microprofile.rest.client.api.version>",
Expand Down
Loading