Skip to content

Commit 8c74a48

Browse files
committed
hideGenerationTimestamp: add getter and setter, put value to additionalProperties map
1 parent e238153 commit 8c74a48

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

src/main/java/io/swagger/codegen/languages/DefaultCodegenConfig.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,17 @@ public void processOpts() {
205205
}
206206

207207
if (additionalProperties.containsKey(CodegenConstants.REMOVE_OPERATION_ID_PREFIX)) {
208-
this.setRemoveOperationIdPrefix(Boolean.valueOf(additionalProperties
208+
this.setSortParamsByRequiredFlag(Boolean.valueOf(additionalProperties
209209
.get(CodegenConstants.REMOVE_OPERATION_ID_PREFIX).toString()));
210210
}
211+
212+
if (additionalProperties.containsKey(CodegenConstants.HIDE_GENERATION_TIMESTAMP)) {
213+
this.setHideGenerationTimestamp(Boolean.valueOf(additionalProperties
214+
.get(CodegenConstants.HIDE_GENERATION_TIMESTAMP).toString()));
215+
} else {
216+
//not set, use to be passed to template
217+
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, hideGenerationTimestamp);
218+
}
211219
}
212220

213221
public Map<String, Object> postProcessAllModels(Map<String, Object> processedModels) {
@@ -3182,6 +3190,24 @@ public String getHttpUserAgent() {
31823190
return httpUserAgent;
31833191
}
31843192

3193+
/**
3194+
* Hide generation timestamp
3195+
*
3196+
* @param hideGenerationTimestamp flag to indicates if the generation timestamp should be hidden or not
3197+
*/
3198+
public void setHideGenerationTimestamp(Boolean hideGenerationTimestamp) {
3199+
this.hideGenerationTimestamp = hideGenerationTimestamp;
3200+
}
3201+
3202+
/**
3203+
* Hide generation timestamp
3204+
*
3205+
* @return if the generation timestamp should be hidden or not
3206+
*/
3207+
public Boolean getHideGenerationTimestamp() {
3208+
return hideGenerationTimestamp;
3209+
}
3210+
31853211
@SuppressWarnings("static-method")
31863212
protected CliOption buildLibraryCliOption(Map<String, String> supportedLibraries) {
31873213
StringBuilder sb = new StringBuilder("library template (sub-template) to use:");

src/main/java/io/swagger/codegen/languages/java/AbstractJavaCodegen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public AbstractJavaCodegen() {
143143
cliOptions.add(CliOption.newBoolean(CodegenConstants.SERIALIZE_BIG_DECIMAL_AS_STRING, CodegenConstants
144144
.SERIALIZE_BIG_DECIMAL_AS_STRING_DESC));
145145
cliOptions.add(CliOption.newBoolean(FULL_JAVA_UTIL, "whether to use fully qualified name for classes under java.util. This option only works for Java API client"));
146-
cliOptions.add(new CliOption("hideGenerationTimestamp", "hides the timestamp when files were generated"));
146+
cliOptions.add(new CliOption(CodegenConstants.HIDE_GENERATION_TIMESTAMP, CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC));
147147
cliOptions.add(CliOption.newBoolean(WITH_XML, "whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)"));
148148

149149
CliOption dateLibrary = new CliOption(DATE_LIBRARY, "Option. Date library to use");

src/test/java/io/swagger/codegen/languages/DefaultCodegenConfigTest.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@ public void testInitialValues() throws Exception {
2020
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "");
2121
Assert.assertEquals(codegen.sortParamsByRequiredFlag, Boolean.TRUE);
2222
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG), Boolean.TRUE);
23+
Assert.assertEquals(codegen.hideGenerationTimestamp, Boolean.TRUE);
24+
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.TRUE);
2325
}
2426

2527
@Test
26-
public void testAdditionalProperties() throws Exception {
28+
public void testSetters() throws Exception {
2729
final DefaultCodegenConfig codegen = new P_DefaultCodegenConfig();
2830
codegen.setModelPackage("xxx.yyyyy.zzzzzzz.model");
2931
codegen.setApiPackage("xxx.yyyyy.zzzzzzz.api");
3032
codegen.setSortParamsByRequiredFlag(false);
33+
codegen.setHideGenerationTimestamp(false);
3134
codegen.processOpts();
3235

3336
Assert.assertEquals(codegen.modelPackage, "xxx.yyyyy.zzzzzzz.model");
@@ -36,6 +39,27 @@ public void testAdditionalProperties() throws Exception {
3639
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "xxx.yyyyy.zzzzzzz.api");
3740
Assert.assertEquals(codegen.sortParamsByRequiredFlag, Boolean.FALSE);
3841
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG), Boolean.FALSE);
42+
Assert.assertEquals(codegen.hideGenerationTimestamp, Boolean.FALSE);
43+
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
44+
}
45+
46+
@Test
47+
public void testPutAdditionalProperties() throws Exception {
48+
final DefaultCodegenConfig codegen = new P_DefaultCodegenConfig();
49+
codegen.additionalProperties().put(CodegenConstants.MODEL_PACKAGE, "xx.yyyyy.model");
50+
codegen.additionalProperties().put(CodegenConstants.API_PACKAGE, "xx.yyyyy.api");
51+
codegen.additionalProperties().put(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG, false);
52+
codegen.additionalProperties().put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, false);
53+
codegen.processOpts();
54+
55+
Assert.assertEquals(codegen.modelPackage, "xx.yyyyy.model");
56+
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.MODEL_PACKAGE), "xx.yyyyy.model");
57+
Assert.assertEquals(codegen.apiPackage, "xx.yyyyy.api");
58+
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.API_PACKAGE), "xx.yyyyy.api");
59+
Assert.assertEquals(codegen.sortParamsByRequiredFlag, Boolean.FALSE);
60+
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.SORT_PARAMS_BY_REQUIRED_FLAG), Boolean.FALSE);
61+
Assert.assertEquals(codegen.hideGenerationTimestamp, Boolean.FALSE);
62+
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
3963
}
4064

4165
private static class P_DefaultCodegenConfig extends DefaultCodegenConfig{

0 commit comments

Comments
 (0)