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

Commit 3a8840f

Browse files
committed
Removes defaultIncludes
1 parent 7dea688 commit 3a8840f

4 files changed

Lines changed: 28 additions & 68 deletions

File tree

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -477,18 +477,6 @@ public ClientOptInput toClientOptInput() {
477477
// regardless of entrypoint (CLI sets properties on this type, config deserialization sets on generatorSettings).
478478
Generator config = GeneratorLoader.getGenerator(generatorSettings.getGeneratorName(), generatorSettings, workflowSettings);
479479

480-
// TODO: Work toward Generator having a "WorkflowSettings" property, or better a "Workflow" object which itself has a "WorkflowSettings" property.
481-
config.additionalProperties().put(CodegenConstants.TEMPLATING_ENGINE, workflowSettings.getTemplatingEngineName());
482-
483-
// TODO: Work toward Generator having a "GeneratorSettings" property.
484-
config.additionalProperties().putAll(generatorSettings.getAdditionalProperties());
485-
486-
// any other additional properties?
487-
String templateDir = workflowSettings.getTemplateDir();
488-
if (templateDir != null) {
489-
config.additionalProperties().put(CodegenConstants.TEMPLATE_DIR, workflowSettings.getTemplateDir());
490-
}
491-
492480
return new ClientOptInput(
493481
(OpenAPI)context.getSpecDocument(),
494482
config,

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

Lines changed: 13 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -143,25 +143,20 @@ public class DefaultGenerator implements Generator {
143143
"################################################################################"
144144
);
145145

146+
private static Map<String, Object> getInitialAdditionalProperties(GeneratorSettings generatorSettings, CodeGeneratorSettings codeGeneratorSettings) {
147+
Map<String, Object> initialAddProps = new HashMap<>();
148+
initialAddProps.putAll(generatorSettings.getAdditionalProperties());
149+
initialAddProps.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, codeGeneratorSettings.hideGenerationTimestamp);
150+
initialAddProps.put(CodegenConstants.TEMPLATING_ENGINE, codeGeneratorSettings.templateEngineName);
151+
if (codeGeneratorSettings.templateDir != null) {
152+
initialAddProps.put(CodegenConstants.TEMPLATE_DIR, codeGeneratorSettings.templateDir);
153+
}
154+
return initialAddProps;
155+
}
146156

147157
protected DefaultGenerator(GeneratorSettings generatorSettings, WorkflowSettings workflowSettings, String embeddedTemplateDir, String packageNameDefault, String outputFolderDefault) {
148158
this.generatorSettings = CodeGeneratorSettings.of(generatorSettings, workflowSettings, embeddedTemplateDir, packageNameDefault, outputFolderDefault);
149-
defaultIncludes = new HashSet<>(
150-
Arrays.asList("double",
151-
"int",
152-
"long",
153-
"short",
154-
"char",
155-
"float",
156-
"String",
157-
"boolean",
158-
"Boolean",
159-
"Double",
160-
"Void",
161-
"Integer",
162-
"Long",
163-
"Float")
164-
);
159+
additionalProperties = getInitialAdditionalProperties(generatorSettings, this.generatorSettings);
165160

166161
// name formatting options
167162
cliOptions.add(CliOption.newBoolean(CodegenConstants.ALLOW_UNICODE_IDENTIFIERS, CodegenConstants
@@ -182,7 +177,6 @@ public DefaultGenerator(GeneratorSettings generatorSettings, WorkflowSettings wo
182177
"openapiclient",
183178
"generated-code" + File.separator + "java"
184179
);
185-
additionalProperties.put(CodegenConstants.HIDE_GENERATION_TIMESTAMP, this.generatorSettings.hideGenerationTimestamp);
186180
}
187181

188182
private final Logger LOGGER = LoggerFactory.getLogger(DefaultGenerator.class);
@@ -263,7 +257,6 @@ public DefaultGenerator(GeneratorSettings generatorSettings, WorkflowSettings wo
263257
.languageSpecificPrimitives(Set.of())
264258
.build();
265259
protected String inputSpec;
266-
protected Set<String> defaultIncludes;
267260
protected Map<String, String> typeMapping;
268261
protected String modelPackage = "components.schema";
269262
protected String modelNamePrefix = "", modelNameSuffix = "";
@@ -3437,8 +3430,7 @@ protected String getOrGenerateOperationId(Operation operation, String path, Stri
34373430
* @return true if the library/module/package of the corresponding type needs to be imported
34383431
*/
34393432
protected boolean needToImport(String type) {
3440-
return StringUtils.isNotBlank(type) && !defaultIncludes.contains(type)
3441-
&& !generatorMetadata.getLanguageSpecificPrimitives().contains(type);
3433+
return true;
34423434
}
34433435

34443436
protected void addImports(Set<String> importsToBeAddedTo, Set<String> importsToAdd) {
@@ -4227,20 +4219,6 @@ protected EnumInfo getEnumInfo(ArrayList<Object> values, Schema<?> schema, Strin
42274219
return new EnumInfo(enumValueToName, typeToValues, jsonPathPiece);
42284220
}
42294221

4230-
/**
4231-
* reads propertyKey from additionalProperties, converts it to a boolean and
4232-
* writes it back to additionalProperties to be usable as a boolean in
4233-
* mustache files.
4234-
*
4235-
* @param propertyKey property key
4236-
* @return property value as boolean
4237-
*/
4238-
public boolean convertPropertyToBooleanAndWriteBack(String propertyKey) {
4239-
boolean result = convertPropertyToBoolean(propertyKey);
4240-
writePropertyBack(propertyKey, result);
4241-
return result;
4242-
}
4243-
42444222
/**
42454223
* Provides an override location, if any is specified, for the .openapi-generator-ignore.
42464224
* <p>
@@ -4253,24 +4231,7 @@ public String getIgnoreFilePathOverride() {
42534231
return ignoreFilePathOverride;
42544232
}
42554233

4256-
public boolean convertPropertyToBoolean(String propertyKey) {
4257-
final Object booleanValue = additionalProperties.get(propertyKey);
4258-
boolean result = Boolean.FALSE;
4259-
if (booleanValue instanceof Boolean) {
4260-
result = (Boolean) booleanValue;
4261-
} else if (booleanValue instanceof String) {
4262-
result = Boolean.parseBoolean((String) booleanValue);
4263-
} else {
4264-
LOGGER.warn("The value (generator's option) must be either boolean or string. Default to `false`.");
4265-
}
4266-
return result;
4267-
}
4268-
4269-
public void writePropertyBack(String propertyKey, boolean value) {
4270-
additionalProperties.put(propertyKey, value);
4271-
}
4272-
4273-
// private List<Map<String, Object>> getScopes(Scopes scopes) {
4234+
// private List<Map<String, Object>> getScopes(Scopes scopes) {
42744235
// if (scopes != null && !scopes.isEmpty()) {
42754236
// List<Map<String, Object>> newScopes = new ArrayList<>();
42764237
// for (Map.Entry<String, String> scopeEntry : scopes.entrySet()) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public interface Generator extends OpenApiProcessor, Comparable<Generator> {
7070

7171
String escapeQuotationMark(String input);
7272

73-
// todo remove this and move it into new
73+
// todo remove this and move it into the generator constructor
7474
void processOpts();
7575

7676
List<CliOption> cliOptions();
@@ -81,10 +81,10 @@ public interface Generator extends OpenApiProcessor, Comparable<Generator> {
8181

8282
HashMap<CodegenConstants.JSON_PATH_LOCATION_TYPE, HashMap<String, String>> getJsonPathTemplateFiles(GeneratedFileType type);
8383

84-
// todo remove + move this into the new constructor
84+
// todo remove this and move it into the generator constructor
8585
void preprocessOpenAPI(OpenAPI openAPI);
8686

87-
// todo remove and move this into the new constructor
87+
// todo remove this and move it into the generator constructor
8888
void processOpenAPI(OpenAPI openAPI);
8989

9090
String toApiFilename(String name);

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3204,7 +3204,18 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
32043204
}
32053205
// must be sequential after initial setting above
32063206
if (additionalProperties.containsKey(CodegenConstants.SNAPSHOT_VERSION)) {
3207-
if (convertPropertyToBooleanAndWriteBack(CodegenConstants.SNAPSHOT_VERSION)) {
3207+
final Object booleanValue = additionalProperties.get(CodegenConstants.SNAPSHOT_VERSION);
3208+
boolean result1 = Boolean.FALSE;
3209+
if (booleanValue instanceof Boolean) {
3210+
result1 = (Boolean) booleanValue;
3211+
} else if (booleanValue instanceof String) {
3212+
result1 = Boolean.parseBoolean((String) booleanValue);
3213+
} else {
3214+
LOGGER.warn("The value (generator's option) must be either boolean or string. Default to `false`.");
3215+
}
3216+
boolean result = result1;
3217+
additionalProperties.put(CodegenConstants.SNAPSHOT_VERSION, result);
3218+
if (result) {
32083219
this.setArtifactVersion(this.buildSnapshotVersion(this.getArtifactVersion()));
32093220
}
32103221
}

0 commit comments

Comments
 (0)