Skip to content

Commit 2d00db2

Browse files
committed
Revert "revert some changes"
This reverts commit 3b8e4c2.
1 parent 8297e27 commit 2d00db2

2 files changed

Lines changed: 26 additions & 32 deletions

File tree

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

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -603,11 +603,9 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
603603
* @return
604604
*/
605605
private boolean codegenPropertyIsNew(CodegenModel model, CodegenProperty property) {
606-
return model.parentModel == null
607-
? false
608-
: model.parentModel.allVars.stream().anyMatch(p ->
606+
return model.parentModel != null && model.parentModel.allVars.stream().anyMatch(p ->
609607
p.name.equals(property.name) &&
610-
(p.dataType.equals(property.dataType) == false || p.datatypeWithEnum.equals(property.datatypeWithEnum) == false));
608+
(!p.dataType.equals(property.dataType) || !p.datatypeWithEnum.equals(property.datatypeWithEnum)));
611609
}
612610

613611
/**
@@ -751,7 +749,7 @@ protected void removeSelfReferenceImports(CodegenModel model) {
751749
for (CodegenProperty cp : model.allVars) {
752750
// detect self import
753751
if (cp.dataType.equalsIgnoreCase(model.classname) ||
754-
(cp.isContainer && cp.items != null && cp.items.dataType.equalsIgnoreCase(model.classname))) {
752+
(cp.isContainer && cp.items != null && cp.items.dataType.equalsIgnoreCase(model.classname))) {
755753
model.imports.remove(model.classname); // remove self import
756754
cp.isSelfReference = true;
757755
}
@@ -793,7 +791,7 @@ private List<CodegenProperty> getModelDependencies(List<CodegenProperty> vars) {
793791
}
794792

795793
private void setCircularReferencesOnProperties(final String root,
796-
final Map<String, List<CodegenProperty>> dependencyMap) {
794+
final Map<String, List<CodegenProperty>> dependencyMap) {
797795
dependencyMap.getOrDefault(root, new ArrayList<>())
798796
.forEach(prop -> {
799797
final List<String> unvisited =
@@ -841,7 +839,7 @@ public ModelsMap postProcessModelsEnum(ModelsMap objs) {
841839
CodegenModel cm = mo.getModel();
842840

843841
// for enum model
844-
if (Boolean.TRUE.equals(cm.isEnum) && cm.allowableValues != null) {
842+
if (cm.isEnum && cm.allowableValues != null) {
845843
Map<String, Object> allowableValues = cm.allowableValues;
846844
List<Object> values = (List<Object>) allowableValues.get("values");
847845
List<Map<String, Object>> enumVars = buildEnumVars(values, cm.dataType);
@@ -1132,7 +1130,7 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
11321130
}
11331131
} else if (ModelUtils.isMapSchema(s)) {
11341132
Schema addProps = ModelUtils.getAdditionalProperties(s);
1135-
if (addProps != null && ModelUtils.isComposedSchema(addProps)) {
1133+
if (ModelUtils.isComposedSchema(addProps)) {
11361134
addOneOfNameExtension(addProps, nOneOf);
11371135
addOneOfInterfaceModel(addProps, nOneOf);
11381136
}
@@ -2995,7 +2993,7 @@ private HashMap<String, SchemaTestCase> extractSchemaTestCases(String refToTestC
29952993
}
29962994
LinkedHashMap<String, LinkedHashMap<String, Object>> testNameToTesCase = (LinkedHashMap<String, LinkedHashMap<String, Object>>) schemaNameToTestCases.get(schemaName);
29972995
for (Entry<String, LinkedHashMap<String, Object>> entry : testNameToTesCase.entrySet()) {
2998-
LinkedHashMap<String, Object> testExample = (LinkedHashMap<String, Object>) entry.getValue();
2996+
LinkedHashMap<String, Object> testExample = entry.getValue();
29992997
String nameInSnakeCase = toTestCaseName(entry.getKey());
30002998
Object data = processTestExampleData(testExample.get("data"));
30012999
SchemaTestCase testCase = new SchemaTestCase(
@@ -3557,15 +3555,15 @@ protected List<MappedModel> getOneOfAnyOfDescendants(String composedSchemaName,
35573555
}
35583556
CodegenProperty df = discriminatorFound(composedSchemaName, sc, discPropName, new TreeSet<String>());
35593557
String modelName = ModelUtils.getSimpleRef(ref);
3560-
if (df == null || !df.isString || df.required != true) {
3558+
if (df == null || !df.isString || !df.required) {
35613559
String msgSuffix = "";
35623560
if (df == null) {
35633561
msgSuffix += discPropName + " is missing from the schema, define it as required and type string";
35643562
} else {
35653563
if (!df.isString) {
35663564
msgSuffix += "invalid type for " + discPropName + ", set it to string";
35673565
}
3568-
if (df.required != true) {
3566+
if (!df.required) {
35693567
String spacer = "";
35703568
if (msgSuffix.length() != 0) {
35713569
spacer = ". ";
@@ -3708,7 +3706,7 @@ protected CodegenDiscriminator createDiscriminator(String schemaName, Schema sch
37083706
}
37093707
}
37103708

3711-
if (matched == false) {
3709+
if (!matched) {
37123710
uniqueDescendants.add(otherDescendant);
37133711
}
37143712
}
@@ -4218,11 +4216,10 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo
42184216
property.isContainer = true;
42194217
if (ModelUtils.isSet(p)) {
42204218
property.containerType = "set";
4221-
property.containerTypeMapped = typeMapping.get(property.containerType);
42224219
} else {
42234220
property.containerType = "array";
4224-
property.containerTypeMapped = typeMapping.get(property.containerType);
42254221
}
4222+
property.containerTypeMapped = typeMapping.get(property.containerType);
42264223
property.baseType = getSchemaType(p);
42274224

42284225
// handle inner property
@@ -4363,7 +4360,7 @@ void updateDefaultToEmptyContainer(CodegenProperty cp, Schema p) {
43634360
* @param input a set of rules separated by `|`
43644361
*/
43654362
void parseDefaultToEmptyContainer(String input) {
4366-
String[] inputs = ((String) input).split("[|]");
4363+
String[] inputs = input.split("[|]");
43674364
String containerType;
43684365
for (String rule : inputs) {
43694366
if (StringUtils.isEmpty(rule)) {
@@ -4381,7 +4378,7 @@ void parseDefaultToEmptyContainer(String input) {
43814378
LOGGER.error("Skipped invalid container type `{}` in `{}`.", containerType, input);
43824379
}
43834380
} else if (rule.startsWith("?")) { // nullable (required)
4384-
containerType = rule.substring(1, rule.length());
4381+
containerType = rule.substring(1);
43854382
if ("array".equalsIgnoreCase(containerType)) {
43864383
arrayNullableDefaultToEmpty = true;
43874384
} else if ("map".equalsIgnoreCase(containerType)) {
@@ -6175,7 +6172,7 @@ protected void addVars(IJsonSchemaValidationProperties m, List<CodegenProperty>
61756172
} else {
61766173
final CodegenProperty cp;
61776174

6178-
if (cm != null && cm.allVars == vars && varsMap.keySet().contains(key)) {
6175+
if (cm != null && cm.allVars == vars && varsMap.containsKey(key)) {
61796176
// when updating allVars, reuse the codegen property from the child model if it's already present
61806177
// the goal is to avoid issues when the property is defined in both child, parent but the
61816178
// definition is not identical, e.g. required vs optional, integer vs string
@@ -6342,7 +6339,7 @@ protected String removeNonNameElementToCamelCase(final String name, final String
63426339
* Not all operating systems support case-sensitive paths
63436340
*/
63446341
private String uniqueCaseInsensitiveString(String value, Map<String, String> seenValues) {
6345-
if (seenValues.keySet().contains(value)) {
6342+
if (seenValues.containsKey(value)) {
63466343
return seenValues.get(value);
63476344
}
63486345

@@ -8012,8 +8009,8 @@ protected LinkedHashMap<String, CodegenMediaType> getContent(Content content, Se
80128009
enc.getContentType(),
80138010
headers,
80148011
enc.getStyle().toString(),
8015-
enc.getExplode() == null ? false : enc.getExplode().booleanValue(),
8016-
enc.getAllowReserved() == null ? false : enc.getAllowReserved().booleanValue()
8012+
enc.getExplode() != null && enc.getExplode(),
8013+
enc.getAllowReserved() != null && enc.getAllowReserved()
80178014
);
80188015

80198016
if (enc.getExtensions() != null) {
@@ -8242,7 +8239,6 @@ protected void addRequiredVarsMap(Schema schema, IJsonSchemaValidationProperties
82428239
}
82438240
if (!found) {
82448241
LOGGER.warn("Property {} is not processed correctly (missing from getVars). Maybe it's a const (not yet supported) in openapi v3.1 spec.", requiredPropertyName);
8245-
continue;
82468242
}
82478243
} else if (schema.getAdditionalProperties() instanceof Boolean && Boolean.FALSE.equals(schema.getAdditionalProperties())) {
82488244
// TODO add processing for requiredPropertyName
@@ -8587,7 +8583,7 @@ public void setRemoveEnumValuePrefix(final boolean removeEnumValuePrefix) {
85878583
* @param name name of the parent oneOf schema
85888584
*/
85898585
public void addOneOfNameExtension(Schema schema, String name) {
8590-
if (schema.getOneOf() != null && schema.getOneOf().size() > 0) {
8586+
if (schema.getOneOf() != null && !schema.getOneOf().isEmpty()) {
85918587
schema.addExtension(X_ONE_OF_NAME, name);
85928588
}
85938589
}

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public class DefaultGenerator implements Generator {
8686
private String basePath;
8787
private String basePathWithoutHost;
8888
private String contextPath;
89-
private Map<String, String> generatorPropertyDefaults = new HashMap<>();
89+
private final Map<String, String> generatorPropertyDefaults = new HashMap<>();
9090
/**
9191
* Retrieves an instance to the configured template processor, available after user-defined options are
9292
* applied via
@@ -95,8 +95,8 @@ public class DefaultGenerator implements Generator {
9595
protected TemplateProcessor templateProcessor = null;
9696

9797
private List<TemplateDefinition> userDefinedTemplates = new ArrayList<>();
98-
private String generatorCheck = "spring";
99-
private String templateCheck = "apiController.mustache";
98+
private final String generatorCheck = "spring";
99+
private final String templateCheck = "apiController.mustache";
100100

101101

102102
public DefaultGenerator() {
@@ -1392,7 +1392,7 @@ private void processUserDefinedTemplates() {
13921392
// hack: destination filename in this scenario might be a suffix like Impl.java
13931393
templateExt = userDefinedTemplate.getDestinationFilename();
13941394
} else {
1395-
templateExt = StringUtils.prependIfMissing(templateExt, ".");
1395+
templateExt = Strings.CS.prependIfMissing(templateExt, ".");
13961396
}
13971397
String templateOutputFolder = userDefinedTemplate.getFolder();
13981398
if (!templateOutputFolder.isEmpty()) {
@@ -1994,7 +1994,7 @@ private void generateFilesMetadata(List<File> files) {
19941994
// Some implementations make the output ./c/d which seems to mix the logic
19951995
// as documented for symlinks. So we need to trim any / or ./ from the start,
19961996
// as nobody should be generating into system root and our expectation is no ./
1997-
String relativePath = removeStart(removeStart(f.toString(), "." + File.separator), File.separator);
1997+
String relativePath = Strings.CS.removeStart(Strings.CS.removeStart(f.toString(), "." + File.separator), File.separator);
19981998
if (File.separator.equals("\\")) {
19991999
// ensure that windows outputs same FILES format
20002000
relativePath = relativePath.replace(File.separator, "/");
@@ -2004,10 +2004,8 @@ private void generateFilesMetadata(List<File> files) {
20042004
}
20052005
});
20062006

2007-
Collections.sort(relativePaths, (a, b) -> IOCase.SENSITIVE.checkCompareTo(a, b));
2008-
relativePaths.forEach(relativePath -> {
2009-
sb.append(relativePath).append(System.lineSeparator());
2010-
});
2007+
relativePaths.sort(IOCase.SENSITIVE::checkCompareTo);
2008+
relativePaths.forEach(relativePath -> sb.append(relativePath).append(System.lineSeparator()));
20112009

20122010
String targetFile = config.outputFolder() + File.separator + METADATA_DIR + File.separator + config.getFilesMetadataFilename();
20132011

@@ -2022,7 +2020,7 @@ private void generateFilesMetadata(List<File> files) {
20222020
}
20232021

20242022
private String removeTrailingSlash(String value) {
2025-
return StringUtils.removeEnd(value, "/");
2023+
return Strings.CS.removeEnd(value, "/");
20262024
}
20272025

20282026
}

0 commit comments

Comments
 (0)