Skip to content

Commit 2f30960

Browse files
authored
[JAXRS-CXF] Improve handling of additional properties in JavaCXFClientCodegen (#7866)
1 parent e3121af commit 2f30960

File tree

2 files changed

+88
-10
lines changed

2 files changed

+88
-10
lines changed

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

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -88,33 +88,30 @@ public JavaCXFClientCodegen() {
8888
cliOptions.add(CliOption.newBoolean(USE_GENERIC_RESPONSE, "Use generic response"));
8989
}
9090

91-
9291
@Override
9392
public void processOpts() {
9493
super.processOpts();
9594

9695
if (additionalProperties.containsKey(USE_BEANVALIDATION)) {
97-
boolean useBeanValidationProp = convertPropertyToBooleanAndWriteBack(USE_BEANVALIDATION);
98-
this.setUseBeanValidation(useBeanValidationProp);
96+
this.setUseBeanValidation(convertPropertyToBooleanAndWriteBack(USE_BEANVALIDATION));
9997
}
10098

10199
if (additionalProperties.containsKey(USE_GENERIC_RESPONSE)) {
102-
this.setUseGenericResponse(convertPropertyToBoolean(USE_GENERIC_RESPONSE));
100+
this.setUseGenericResponse(convertPropertyToBooleanAndWriteBack(USE_GENERIC_RESPONSE));
103101
}
104102

105-
if (useGenericResponse) {
106-
writePropertyBack(USE_GENERIC_RESPONSE, useGenericResponse);
103+
if (additionalProperties.containsKey(USE_GZIP_FEATURE_FOR_TESTS)) {
104+
this.setUseGzipFeatureForTests(convertPropertyToBooleanAndWriteBack(USE_GZIP_FEATURE_FOR_TESTS));
107105
}
108106

109-
this.setUseGzipFeatureForTests(convertPropertyToBooleanAndWriteBack(USE_GZIP_FEATURE_FOR_TESTS));
110-
this.setUseLoggingFeatureForTests(convertPropertyToBooleanAndWriteBack(USE_LOGGING_FEATURE_FOR_TESTS));
111-
107+
if (additionalProperties.containsKey(USE_LOGGING_FEATURE_FOR_TESTS)) {
108+
this.setUseLoggingFeatureForTests(convertPropertyToBooleanAndWriteBack(USE_LOGGING_FEATURE_FOR_TESTS));
109+
}
112110

113111
supportingFiles.clear(); // Don't need extra files provided by AbstractJAX-RS & Java Codegen
114112

115113
supportingFiles.add(new SupportingFile("pom.mustache", "", "pom.xml")
116114
.doNotOverwrite());
117-
118115
}
119116

120117
@Override
@@ -154,20 +151,40 @@ public String getHelp() {
154151
return "Generates a Java JAXRS Client based on Apache CXF framework.";
155152
}
156153

154+
@Override
157155
public void setUseBeanValidation(boolean useBeanValidation) {
158156
this.useBeanValidation = useBeanValidation;
159157
}
160158

159+
public boolean isUseBeanValidation() {
160+
return useBeanValidation;
161+
}
162+
163+
@Override
161164
public void setUseGzipFeatureForTests(boolean useGzipFeatureForTests) {
162165
this.useGzipFeatureForTests = useGzipFeatureForTests;
163166
}
164167

168+
public boolean isUseGzipFeatureForTests() {
169+
return useGzipFeatureForTests;
170+
}
171+
172+
@Override
165173
public void setUseLoggingFeatureForTests(boolean useLoggingFeatureForTests) {
166174
this.useLoggingFeatureForTests = useLoggingFeatureForTests;
167175
}
168176

177+
public boolean isUseLoggingFeatureForTests() {
178+
return useLoggingFeatureForTests;
179+
}
180+
181+
@Override
169182
public void setUseGenericResponse(boolean useGenericResponse) {
170183
this.useGenericResponse = useGenericResponse;
171184
}
172185

186+
public boolean isUseGenericResponse() {
187+
return useGenericResponse;
188+
}
189+
173190
}

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@
2727
import org.openapitools.codegen.CodegenResponse;
2828
import org.openapitools.codegen.TestUtils;
2929
import org.openapitools.codegen.languages.JavaCXFClientCodegen;
30+
import org.openapitools.codegen.languages.features.BeanValidationFeatures;
31+
import org.openapitools.codegen.languages.features.GzipTestFeatures;
32+
import org.openapitools.codegen.languages.features.LoggingTestFeatures;
33+
import org.openapitools.codegen.languages.features.UseGenericResponseFeatures;
3034
import org.testng.Assert;
3135
import org.testng.annotations.Test;
3236

@@ -118,4 +122,61 @@ public void testAdditionalPropertiesPutForConfigValues() throws Exception {
118122
Assert.assertEquals(codegen.getInvokerPackage(), "org.openapitools.client.xyz.invoker");
119123
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.INVOKER_PACKAGE), "org.openapitools.client.xyz.invoker");
120124
}
125+
126+
@Test
127+
public void testUseBeanValidationAdditionalProperty() throws Exception {
128+
final JavaCXFClientCodegen codegen = new JavaCXFClientCodegen();
129+
130+
codegen.processOpts();
131+
Assert.assertNull(codegen.additionalProperties().get(BeanValidationFeatures.USE_BEANVALIDATION));
132+
Assert.assertFalse(codegen.isUseBeanValidation());
133+
134+
codegen.additionalProperties().put(BeanValidationFeatures.USE_BEANVALIDATION, true);
135+
codegen.processOpts();
136+
Assert.assertEquals(codegen.additionalProperties().get(BeanValidationFeatures.USE_BEANVALIDATION), Boolean.TRUE);
137+
Assert.assertTrue(codegen.isUseBeanValidation());
138+
}
139+
140+
@Test
141+
public void testUseGenericResponseAdditionalProperty() throws Exception {
142+
final JavaCXFClientCodegen codegen = new JavaCXFClientCodegen();
143+
144+
codegen.processOpts();
145+
Assert.assertNull(codegen.additionalProperties().get(UseGenericResponseFeatures.USE_GENERIC_RESPONSE));
146+
Assert.assertFalse(codegen.isUseGenericResponse());
147+
148+
codegen.additionalProperties().put(UseGenericResponseFeatures.USE_GENERIC_RESPONSE, true);
149+
codegen.processOpts();
150+
Assert.assertEquals(codegen.additionalProperties().get(UseGenericResponseFeatures.USE_GENERIC_RESPONSE), Boolean.TRUE);
151+
Assert.assertTrue(codegen.isUseGenericResponse());
152+
}
153+
154+
@Test
155+
public void testUseLoggingFeatureForTestsAdditionalProperty() throws Exception {
156+
final JavaCXFClientCodegen codegen = new JavaCXFClientCodegen();
157+
158+
codegen.processOpts();
159+
Assert.assertNull(codegen.additionalProperties().get(LoggingTestFeatures.USE_LOGGING_FEATURE_FOR_TESTS));
160+
Assert.assertFalse(codegen.isUseLoggingFeatureForTests());
161+
162+
codegen.additionalProperties().put(LoggingTestFeatures.USE_LOGGING_FEATURE_FOR_TESTS, true);
163+
codegen.processOpts();
164+
Assert.assertEquals(codegen.additionalProperties().get(LoggingTestFeatures.USE_LOGGING_FEATURE_FOR_TESTS), Boolean.TRUE);
165+
Assert.assertTrue(codegen.isUseLoggingFeatureForTests());
166+
}
167+
168+
@Test
169+
public void testUseGzipFeatureForTestsAdditionalProperty() throws Exception {
170+
final JavaCXFClientCodegen codegen = new JavaCXFClientCodegen();
171+
172+
codegen.processOpts();
173+
Assert.assertNull(codegen.additionalProperties().get(GzipTestFeatures.USE_GZIP_FEATURE_FOR_TESTS));
174+
Assert.assertFalse(codegen.isUseLoggingFeatureForTests());
175+
176+
codegen.additionalProperties().put(GzipTestFeatures.USE_GZIP_FEATURE_FOR_TESTS, true);
177+
codegen.processOpts();
178+
Assert.assertEquals(codegen.additionalProperties().get(GzipTestFeatures.USE_GZIP_FEATURE_FOR_TESTS), Boolean.TRUE);
179+
Assert.assertTrue(codegen.isUseGzipFeatureForTests());
180+
}
181+
121182
}

0 commit comments

Comments
 (0)