Skip to content

Commit 0d7481f

Browse files
Migrated the defaults from WorkflowSettings.Builder into WorkflowSettings. Defaults cannot be bypassed and the builder takes the default values from WorkflowSettings as initial values. Every value in WorkflowSettings is defaultable now. Defaults are public so these can be used for consistency and documentation purposes in (e.g.) the flags.
1 parent 27b7130 commit 0d7481f

File tree

1 file changed

+106
-25
lines changed

1 file changed

+106
-25
lines changed

modules/openapi-generator-core/src/main/java/org/openapitools/codegen/config/WorkflowSettings.java

+106-25
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,20 @@
3333
public class WorkflowSettings {
3434

3535
private static final Logger LOGGER = LoggerFactory.getLogger(WorkflowSettings.class);
36+
public static final String DEFAULT_INPUT_SPEC = null;
37+
public static final String DEFAULT_OUTPUT_DIR = ".";
38+
public static final boolean DEFAULT_VERBOSE = false;
39+
public static final boolean DEFAULT_SKIP_OVERWRITE = false;
40+
public static final boolean DEFAULT_REMOVE_OPERATION_ID_PREFIX = false;
41+
public static final boolean DEFAULT_LOG_TO_STDERR = false;
42+
public static final boolean DEFAULT_VALIDATE_SPEC = true;
43+
public static final boolean DEFAULT_ENABLE_POST_PROCESS_FILE = false;
44+
public static final boolean DEFAULT_ENABLE_MINIMAL_UPDATE = false;
45+
public static final boolean DEFAULT_STRICT_SPEC_BEHAVIOR = true;
46+
public static final String DEFAULT_TEMPLATE_DIR = null;
47+
public static final String DEFAULT_TEMPLATING_ENGINE_NAME = null;
48+
public static final String DEFAULT_IGNORE_FILE_OVERRIDE = null;
49+
public static final ImmutableMap<String, String> DEFAULT_SYSTEM_PROPERTIES = ImmutableMap.copyOf(new HashMap<>());
3650

3751
private String inputSpec;
3852
private String outputDir;
@@ -51,20 +65,77 @@ public class WorkflowSettings {
5165

5266
private WorkflowSettings(Builder builder) {
5367
this();
54-
inputSpec = builder.inputSpec;
55-
outputDir = builder.outputDir;
56-
verbose = builder.verbose;
57-
skipOverwrite = builder.skipOverwrite;
58-
removeOperationIdPrefix = builder.removeOperationIdPrefix;
59-
logToStderr = builder.logToStderr;
60-
validateSpec = builder.validateSpec;
61-
enablePostProcessFile = builder.enablePostProcessFile;
62-
enableMinimalUpdate = builder.enableMinimalUpdate;
63-
strictSpecBehavior = builder.strictSpecBehavior;
64-
templateDir = builder.templateDir;
65-
templatingEngineName = builder.templatingEngineName;
66-
ignoreFileOverride = builder.ignoreFileOverride;
67-
systemProperties = ImmutableMap.copyOf(builder.systemProperties);
68+
if (builder.inputSpec == null) {
69+
this.inputSpec = DEFAULT_INPUT_SPEC;
70+
} else {
71+
this.inputSpec = builder.inputSpec;
72+
}
73+
if (builder.outputDir == null) {
74+
this.outputDir = DEFAULT_OUTPUT_DIR;
75+
} else {
76+
this.outputDir = builder.outputDir;
77+
}
78+
if (builder.verbose == null) {
79+
this.verbose = DEFAULT_VERBOSE;
80+
} else {
81+
this.verbose = builder.verbose;
82+
}
83+
if (builder.skipOverwrite == null) {
84+
this.skipOverwrite = DEFAULT_SKIP_OVERWRITE;
85+
} else {
86+
this.skipOverwrite = builder.skipOverwrite;
87+
}
88+
if (builder.removeOperationIdPrefix == null) {
89+
this.removeOperationIdPrefix = DEFAULT_REMOVE_OPERATION_ID_PREFIX;
90+
} else {
91+
this.removeOperationIdPrefix = builder.removeOperationIdPrefix;
92+
}
93+
if (builder.logToStderr == null) {
94+
this.logToStderr = DEFAULT_LOG_TO_STDERR;
95+
} else {
96+
this.logToStderr = builder.logToStderr;
97+
}
98+
if (builder.validateSpec == null) {
99+
this.validateSpec = DEFAULT_VALIDATE_SPEC;
100+
} else {
101+
this.validateSpec = builder.validateSpec;
102+
}
103+
if (builder.enablePostProcessFile == null) {
104+
this.enablePostProcessFile = DEFAULT_ENABLE_POST_PROCESS_FILE;
105+
} else {
106+
this.enablePostProcessFile = builder.enablePostProcessFile;
107+
}
108+
if (builder.enableMinimalUpdate == null) {
109+
this.enableMinimalUpdate = DEFAULT_ENABLE_MINIMAL_UPDATE;
110+
} else {
111+
this.enableMinimalUpdate = builder.enableMinimalUpdate;
112+
}
113+
if (builder.strictSpecBehavior == null) {
114+
this.strictSpecBehavior = DEFAULT_STRICT_SPEC_BEHAVIOR;
115+
} else {
116+
this.strictSpecBehavior = builder.strictSpecBehavior;
117+
}
118+
if (builder.templateDir == null) {
119+
this.templateDir = DEFAULT_TEMPLATE_DIR;
120+
} else {
121+
this.templateDir = builder.templateDir;
122+
}
123+
if (builder.templatingEngineName == null) {
124+
this.templatingEngineName = DEFAULT_TEMPLATING_ENGINE_NAME;
125+
} else {
126+
this.templatingEngineName = builder.templatingEngineName;
127+
}
128+
if (builder.ignoreFileOverride == null) {
129+
this.ignoreFileOverride = DEFAULT_IGNORE_FILE_OVERRIDE;
130+
} else {
131+
this.ignoreFileOverride = builder.ignoreFileOverride;
132+
}
133+
if (builder.systemProperties == null) {
134+
this.systemProperties = DEFAULT_SYSTEM_PROPERTIES;
135+
} else {
136+
this.systemProperties = ImmutableMap.copyOf(builder.systemProperties);
137+
}
138+
68139
}
69140

70141
/**
@@ -251,14 +322,14 @@ public Map<String, String> getSystemProperties() {
251322
public static final class Builder {
252323
private String inputSpec;
253324
private String outputDir;
254-
private boolean verbose;
255-
private boolean skipOverwrite;
256-
private boolean removeOperationIdPrefix;
257-
private boolean logToStderr;
258-
private boolean validateSpec;
259-
private boolean enablePostProcessFile;
260-
private boolean enableMinimalUpdate;
261-
private boolean strictSpecBehavior;
325+
private Boolean verbose;
326+
private Boolean skipOverwrite;
327+
private Boolean removeOperationIdPrefix;
328+
private Boolean logToStderr;
329+
private Boolean validateSpec;
330+
private Boolean enablePostProcessFile;
331+
private Boolean enableMinimalUpdate;
332+
private Boolean strictSpecBehavior;
262333
private String templateDir;
263334
private String templatingEngineName;
264335
private String ignoreFileOverride;
@@ -270,9 +341,19 @@ private Builder() {
270341
}
271342

272343
private void setDefaults(){
273-
validateSpec = true;
274-
strictSpecBehavior = true;
275-
outputDir = ".";
344+
this.inputSpec = WorkflowSettings.DEFAULT_INPUT_SPEC;
345+
this.outputDir = WorkflowSettings.DEFAULT_OUTPUT_DIR;
346+
this.verbose = WorkflowSettings.DEFAULT_VERBOSE;
347+
this.skipOverwrite = WorkflowSettings.DEFAULT_SKIP_OVERWRITE;
348+
this.removeOperationIdPrefix = WorkflowSettings.DEFAULT_REMOVE_OPERATION_ID_PREFIX;
349+
this.logToStderr = WorkflowSettings.DEFAULT_LOG_TO_STDERR;
350+
this.validateSpec = WorkflowSettings.DEFAULT_VALIDATE_SPEC;
351+
this.enablePostProcessFile = WorkflowSettings.DEFAULT_ENABLE_POST_PROCESS_FILE;
352+
this.enableMinimalUpdate = WorkflowSettings.DEFAULT_ENABLE_MINIMAL_UPDATE;
353+
this.strictSpecBehavior = WorkflowSettings.DEFAULT_STRICT_SPEC_BEHAVIOR;
354+
this.templateDir = WorkflowSettings.DEFAULT_TEMPLATE_DIR;
355+
this.templatingEngineName = WorkflowSettings.DEFAULT_TEMPLATING_ENGINE_NAME;
356+
this.ignoreFileOverride = WorkflowSettings.DEFAULT_IGNORE_FILE_OVERRIDE;
276357
}
277358

278359
/**

0 commit comments

Comments
 (0)