Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit 7dea688

Browse files
committed
Adds hide genration timestamp option
1 parent 914c257 commit 7dea688

9 files changed

Lines changed: 50 additions & 38 deletions

File tree

src/main/java/org/openapijsonschematools/codegen/clicommands/Generate.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ public class Generate extends AbstractCommand {
192192
description = "Only write output files that have changed.")
193193
private Boolean minimalUpdate;
194194

195+
@Option(name = {"--hide-generation-timestamp"}, title = "hides the generation timestamp in the generated files",
196+
description = CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC)
197+
private Boolean hideGenerationTimestamp;
198+
195199
@Override
196200
public void execute() {
197201
// this initial check allows for field-level package private injection (for unit testing)
@@ -320,7 +324,11 @@ public void execute() {
320324
}
321325

322326
if (removeEnumValuePrefix != null) {
323-
configurator.setRemoveOperationIdPrefix(removeOperationIdPrefix);
327+
configurator.setRemoveEnumValuePrefix(removeEnumValuePrefix);
328+
}
329+
330+
if (hideGenerationTimestamp != null) {
331+
configurator.setHideGenerationTimestamp(hideGenerationTimestamp);
324332
}
325333

326334
if (skipOperationExample != null) {

src/main/java/org/openapijsonschematools/codegen/config/CodegenConfigurator.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,11 @@ public CodegenConfigurator setRemoveEnumValuePrefix(boolean removeEnumValuePrefi
324324
return this;
325325
}
326326

327+
public CodegenConfigurator setHideGenerationTimestamp(boolean hideGenerationTimestamp) {
328+
workflowSettingsBuilder.withHideGenerationTimestamp(hideGenerationTimestamp);
329+
return this;
330+
}
331+
327332
public CodegenConfigurator setSkipOperationExample(boolean skipOperationExample) {
328333
workflowSettingsBuilder.withSkipOperationExample(skipOperationExample);
329334
return this;

src/main/java/org/openapijsonschematools/codegen/config/WorkflowSettings.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ public class WorkflowSettings {
4747
public static final boolean DEFAULT_ENABLE_MINIMAL_UPDATE = false;
4848
public static final boolean DEFAULT_STRICT_SPEC_BEHAVIOR = true;
4949
public static final String DEFAULT_TEMPLATING_ENGINE_NAME = "handlebars";
50+
51+
public static final boolean DEFAULT_HIDE_GENERATION_TIMESTAMP = true;
5052
public static final Map<String, String> DEFAULT_GLOBAL_PROPERTIES = Collections.unmodifiableMap(new HashMap<>());
5153

5254
private String inputSpec;
@@ -65,6 +67,7 @@ public class WorkflowSettings {
6567
private String ignoreFileOverride;
6668
private Map<String, ?> globalProperties = DEFAULT_GLOBAL_PROPERTIES;
6769
private boolean removeEnumValuePrefix = DEFAULT_REMOVE_ENUM_VALUE_PREFIX;
70+
private boolean hideGenerationTimestamp = DEFAULT_HIDE_GENERATION_TIMESTAMP;
6871

6972
private WorkflowSettings(Builder builder) {
7073
this.inputSpec = builder.inputSpec;
@@ -83,6 +86,7 @@ private WorkflowSettings(Builder builder) {
8386
this.ignoreFileOverride = builder.ignoreFileOverride;
8487
this.globalProperties = Collections.unmodifiableMap(builder.globalProperties);
8588
this.removeEnumValuePrefix = builder.removeEnumValuePrefix;
89+
this.hideGenerationTimestamp = builder.hideGenerationTimestamp;
8690
}
8791

8892
/**
@@ -116,6 +120,7 @@ public static Builder newBuilder(WorkflowSettings copy) {
116120
// this, and any other collections, must be mutable in the builder.
117121
builder.globalProperties = new HashMap<>(copy.getGlobalProperties());
118122
builder.removeEnumValuePrefix = copy.isRemoveEnumValuePrefix();
123+
builder.hideGenerationTimestamp = copy.isHideGenerationTimestamp();
119124

120125
// force builder "with" methods to invoke side effects
121126
builder.withTemplateDir(copy.getTemplateDir());
@@ -173,6 +178,8 @@ public boolean isRemoveOperationIdPrefix() {
173178
public boolean isRemoveEnumValuePrefix() {
174179
return removeEnumValuePrefix;
175180
}
181+
182+
public boolean isHideGenerationTimestamp() { return hideGenerationTimestamp; }
176183
/**
177184
* Indicates whether or not to skip examples defined in the operation.
178185
*
@@ -307,6 +314,7 @@ public static final class Builder {
307314
private String templateDir;
308315
private String templatingEngineName = DEFAULT_TEMPLATING_ENGINE_NAME;
309316
private String ignoreFileOverride;
317+
private boolean hideGenerationTimestamp = DEFAULT_HIDE_GENERATION_TIMESTAMP;
310318

311319
// NOTE: All collections must be mutable in the builder, and copied to a new immutable collection in .build()
312320
private Map<String, String> globalProperties = new HashMap<>();
@@ -380,6 +388,7 @@ public Builder withRemoveEnumValuePrefix(Boolean removeEnumValuePrefix) {
380388
this.removeEnumValuePrefix = removeEnumValuePrefix != null ? removeEnumValuePrefix : Boolean.valueOf(DEFAULT_REMOVE_ENUM_VALUE_PREFIX);
381389
return this;
382390
}
391+
383392
/**
384393
* Sets the {@code skipOperationExample} and returns a reference to this Builder so that the methods can be chained together.
385394
*
@@ -514,6 +523,11 @@ public Builder withIgnoreFileOverride(String ignoreFileOverride) {
514523
return this;
515524
}
516525

526+
public Builder withHideGenerationTimestamp(boolean hideGenerationTimestamp) {
527+
this.hideGenerationTimestamp = hideGenerationTimestamp;
528+
return this;
529+
}
530+
517531
/**
518532
* Sets the {@code globalProperties} and returns a reference to this Builder so that the methods can be chained together.
519533
*

src/main/java/org/openapijsonschematools/codegen/generators/DefaultGenerator.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ public DefaultGenerator(GeneratorSettings generatorSettings, WorkflowSettings wo
182182
"openapiclient",
183183
"generated-code" + File.separator + "java"
184184
);
185+
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, this.generatorSettings.hideGenerationTimestamp);
185186
}
186187

187188
private final Logger LOGGER = LoggerFactory.getLogger(DefaultGenerator.class);
@@ -312,7 +313,6 @@ public DefaultGenerator(GeneratorSettings generatorSettings, WorkflowSettings wo
312313
*/
313314
protected boolean supportsAdditionalPropertiesWithComposedSchema = true;
314315
protected Boolean allowUnicodeIdentifiers = false;
315-
protected Boolean hideGenerationTimestamp = true;
316316
// How to encode special characters like $
317317
// They are translated to words like "Dollar" and prefixed with '
318318
// Then translated back during JSON encoding and decoding
@@ -355,12 +355,6 @@ public List<CliOption> cliOptions() {
355355

356356
@Override
357357
public void processOpts() {
358-
if (additionalProperties.containsKey(CodegenConstants.HIDE_GENERATION_TIMESTAMP)) {
359-
setHideGenerationTimestamp(convertPropertyToBooleanAndWriteBack(CodegenConstants.HIDE_GENERATION_TIMESTAMP));
360-
} else {
361-
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, hideGenerationTimestamp);
362-
}
363-
364358
if (additionalProperties.containsKey(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS)) {
365359
this.setAllowUnicodeIdentifiers(Boolean.valueOf(additionalProperties
366360
.get(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS).toString()));
@@ -4013,16 +4007,6 @@ public void setRemoveOperationIdPrefixCount(int removeOperationIdPrefixCount) {
40134007
this.removeOperationIdPrefixCount = removeOperationIdPrefixCount;
40144008
}
40154009

4016-
@Override
4017-
public boolean isHideGenerationTimestamp() {
4018-
return hideGenerationTimestamp;
4019-
}
4020-
4021-
@Override
4022-
public void setHideGenerationTimestamp(boolean hideGenerationTimestamp) {
4023-
this.hideGenerationTimestamp = hideGenerationTimestamp;
4024-
}
4025-
40264010
/**
40274011
* Set Documentation files extension
40284012
*

src/main/java/org/openapijsonschematools/codegen/generators/Generator.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,6 @@ public interface Generator extends OpenApiProcessor, Comparable<Generator> {
107107

108108
String getFilePath(GeneratedFileType type, String jsonPath);
109109

110-
boolean isHideGenerationTimestamp();
111-
112-
void setHideGenerationTimestamp(boolean hideGenerationTimestamp);
113-
114110
void setDocExtension(String docExtension);
115111

116112
String sanitizeName(String name);
@@ -362,5 +358,10 @@ default Map<String, String> instantiationTypes() {
362358
default Set<String> languageSpecificPrimitives() {
363359
return getGeneratorMetadata().getLanguageSpecificPrimitives();
364360
}
365-
// 93 - 42 -> 51
361+
362+
@Deprecated
363+
default boolean isHideGenerationTimestamp() {
364+
return generatorSettings().hideGenerationTimestamp;
365+
}
366+
// 93 - 45 -> 48
366367
}

src/main/java/org/openapijsonschematools/codegen/generators/JavaClientGenerator.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ public JavaClientGenerator(GeneratorSettings generatorSettings, WorkflowSettings
9797
}
9898
headersSchemaFragment = "HeadersSchema";
9999
supportsInheritance = true;
100-
hideGenerationTimestamp = false;
101100

102101

103102
cliOptions.add(new CliOption(CodegenConstants.API_PACKAGE, CodegenConstants.API_PACKAGE_DESC));
@@ -117,7 +116,6 @@ public JavaClientGenerator(GeneratorSettings generatorSettings, WorkflowSettings
117116
cliOptions.add(new CliOption(CodegenConstants.LICENSE_NAME, CodegenConstants.LICENSE_NAME_DESC).defaultValue(this.getLicenseName()));
118117
cliOptions.add(new CliOption(CodegenConstants.LICENSE_URL, CodegenConstants.LICENSE_URL_DESC).defaultValue(this.getLicenseUrl()));
119118
cliOptions.add(new CliOption(CodegenConstants.SOURCE_FOLDER, CodegenConstants.SOURCE_FOLDER_DESC).defaultValue(this.getSourceFolder()));
120-
cliOptions.add(CliOption.newBoolean(CodegenConstants.HIDE_GENERATION_TIMESTAMP, CodegenConstants.HIDE_GENERATION_TIMESTAMP_DESC, this.isHideGenerationTimestamp()));
121119

122120
cliOptions.add(CliOption.newString(CodegenConstants.PARENT_GROUP_ID, CodegenConstants.PARENT_GROUP_ID_DESC));
123121
cliOptions.add(CliOption.newString(CodegenConstants.PARENT_ARTIFACT_ID, CodegenConstants.PARENT_ARTIFACT_ID_DESC));

src/main/java/org/openapijsonschematools/codegen/generators/PythonClientGenerator.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,6 @@ public PythonClientGenerator(GeneratorSettings generatorSettings, WorkflowSettin
326326

327327
modelPackage = "components.schema";
328328

329-
// default HIDE_GENERATION_TIMESTAMP to true
330-
hideGenerationTimestamp = Boolean.TRUE;
331-
332329
regexModifiers = new HashMap<>();
333330
regexModifiers.put('i', "IGNORECASE");
334331
regexModifiers.put('l', "LOCALE");

src/main/java/org/openapijsonschematools/codegen/generators/models/CodeGeneratorSettings.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class CodeGeneratorSettings {
2121
public final String templateEngineName;
2222
public final String inputSpecLocation; // input spec's location, as URL or file
2323
public final boolean removeEnumValuePrefix;
24+
public final boolean hideGenerationTimestamp;
2425
public CodeGeneratorSettings(
2526
String apiPackage,
2627
String outputFolder,
@@ -36,7 +37,8 @@ public CodeGeneratorSettings(
3637
boolean enablePostProcessFile,
3738
String templateEngineName,
3839
String inputSpecLocation,
39-
boolean removeEnumValuePrefix
40+
boolean removeEnumValuePrefix,
41+
boolean hideGenerationTimestamp
4042
) {
4143
this.apiPackage = apiPackage;
4244
this.outputFolder = outputFolder;
@@ -53,6 +55,7 @@ public CodeGeneratorSettings(
5355
this.templateEngineName = templateEngineName;
5456
this.inputSpecLocation = inputSpecLocation;
5557
this.removeEnumValuePrefix = removeEnumValuePrefix;
58+
this.hideGenerationTimestamp = hideGenerationTimestamp;
5659
}
5760

5861
public static CodeGeneratorSettings of(GeneratorSettings generatorSettings, WorkflowSettings workflowSettings, String embeddedTemplateDir, String packageNameDefault, String outputFolderDefault) {
@@ -71,6 +74,7 @@ public static CodeGeneratorSettings of(GeneratorSettings generatorSettings, Work
7174
String templateEnginName = workflowSettings != null ? workflowSettings.getTemplatingEngineName() : WorkflowSettings.DEFAULT_TEMPLATING_ENGINE_NAME;
7275
String inputSpecLocation = workflowSettings != null ? workflowSettings.getInputSpec() : null;
7376
boolean removeEnumValuePrefix = workflowSettings != null ? workflowSettings.isRemoveEnumValuePrefix() : WorkflowSettings.DEFAULT_REMOVE_ENUM_VALUE_PREFIX;
77+
boolean hideGenerationTimestamp = workflowSettings != null ? workflowSettings.isHideGenerationTimestamp() : WorkflowSettings.DEFAULT_HIDE_GENERATION_TIMESTAMP;
7478
return new CodeGeneratorSettings(
7579
apiPackage,
7680
outputDir,
@@ -86,7 +90,8 @@ public static CodeGeneratorSettings of(GeneratorSettings generatorSettings, Work
8690
enablePostProcessingFile,
8791
templateEnginName,
8892
inputSpecLocation,
89-
removeEnumValuePrefix
93+
removeEnumValuePrefix,
94+
hideGenerationTimestamp
9095
);
9196
}
9297
}

src/test/java/org/openapijsonschematools/codegen/generators/DefaultGeneratorTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,27 +250,27 @@ public void testInitialConfigValues() throws Exception {
250250
codegen.processOpts();
251251

252252
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.TRUE);
253-
Assert.assertTrue(codegen.isHideGenerationTimestamp());
253+
Assert.assertTrue(codegen.generatorSettings.hideGenerationTimestamp);
254254
}
255255

256256
@Test
257257
public void testSettersForConfigValues() throws Exception {
258-
final DefaultGenerator codegen = new ThisDefaultGenerator();
259-
codegen.setHideGenerationTimestamp(false);
258+
WorkflowSettings ws = WorkflowSettings.newBuilder().withHideGenerationTimestamp(false).build();
259+
final DefaultGenerator codegen = new ThisDefaultGenerator(ws);
260260
codegen.processOpts();
261261

262262
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
263-
Assert.assertFalse(codegen.isHideGenerationTimestamp());
263+
Assert.assertFalse(codegen.generatorSettings.hideGenerationTimestamp);
264264
}
265265

266266
@Test
267-
public void testAdditionalPropertiesPutForConfigValues() throws Exception {
268-
final DefaultGenerator codegen = new ThisDefaultGenerator();
269-
codegen.additionalProperties().put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, false);
267+
public void testAdditionalPropertiesPutForConfigValues() {
268+
WorkflowSettings ws = WorkflowSettings.newBuilder().withHideGenerationTimestamp(false).build();
269+
final DefaultGenerator codegen = new ThisDefaultGenerator(ws);
270270
codegen.processOpts();
271271

272272
Assert.assertEquals(codegen.additionalProperties().get(CodegenConstants.HIDE_GENERATION_TIMESTAMP), Boolean.FALSE);
273-
Assert.assertFalse(codegen.isHideGenerationTimestamp());
273+
Assert.assertFalse(codegen.generatorSettings.hideGenerationTimestamp);
274274
}
275275

276276
@Test

0 commit comments

Comments
 (0)