Skip to content

Commit 3b8e4c2

Browse files
committed
revert some changes
1 parent ae35597 commit 3b8e4c2

2 files changed

Lines changed: 32 additions & 26 deletions

File tree

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

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,11 @@ 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 && model.parentModel.allVars.stream().anyMatch(p ->
606+
return model.parentModel == null
607+
? false
608+
: model.parentModel.allVars.stream().anyMatch(p ->
607609
p.name.equals(property.name) &&
608-
(!p.dataType.equals(property.dataType) || !p.datatypeWithEnum.equals(property.datatypeWithEnum)));
610+
(p.dataType.equals(property.dataType) == false || p.datatypeWithEnum.equals(property.datatypeWithEnum) == false));
609611
}
610612

611613
/**
@@ -749,7 +751,7 @@ protected void removeSelfReferenceImports(CodegenModel model) {
749751
for (CodegenProperty cp : model.allVars) {
750752
// detect self import
751753
if (cp.dataType.equalsIgnoreCase(model.classname) ||
752-
(cp.isContainer && cp.items != null && cp.items.dataType.equalsIgnoreCase(model.classname))) {
754+
(cp.isContainer && cp.items != null && cp.items.dataType.equalsIgnoreCase(model.classname))) {
753755
model.imports.remove(model.classname); // remove self import
754756
cp.isSelfReference = true;
755757
}
@@ -791,7 +793,7 @@ private List<CodegenProperty> getModelDependencies(List<CodegenProperty> vars) {
791793
}
792794

793795
private void setCircularReferencesOnProperties(final String root,
794-
final Map<String, List<CodegenProperty>> dependencyMap) {
796+
final Map<String, List<CodegenProperty>> dependencyMap) {
795797
dependencyMap.getOrDefault(root, new ArrayList<>())
796798
.forEach(prop -> {
797799
final List<String> unvisited =
@@ -839,7 +841,7 @@ public ModelsMap postProcessModelsEnum(ModelsMap objs) {
839841
CodegenModel cm = mo.getModel();
840842

841843
// for enum model
842-
if (cm.isEnum && cm.allowableValues != null) {
844+
if (Boolean.TRUE.equals(cm.isEnum) && cm.allowableValues != null) {
843845
Map<String, Object> allowableValues = cm.allowableValues;
844846
List<Object> values = (List<Object>) allowableValues.get("values");
845847
List<Map<String, Object>> enumVars = buildEnumVars(values, cm.dataType);
@@ -1130,7 +1132,7 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
11301132
}
11311133
} else if (ModelUtils.isMapSchema(s)) {
11321134
Schema addProps = ModelUtils.getAdditionalProperties(s);
1133-
if (ModelUtils.isComposedSchema(addProps)) {
1135+
if (addProps != null && ModelUtils.isComposedSchema(addProps)) {
11341136
addOneOfNameExtension(addProps, nOneOf);
11351137
addOneOfInterfaceModel(addProps, nOneOf);
11361138
}
@@ -2993,7 +2995,7 @@ private HashMap<String, SchemaTestCase> extractSchemaTestCases(String refToTestC
29932995
}
29942996
LinkedHashMap<String, LinkedHashMap<String, Object>> testNameToTesCase = (LinkedHashMap<String, LinkedHashMap<String, Object>>) schemaNameToTestCases.get(schemaName);
29952997
for (Entry<String, LinkedHashMap<String, Object>> entry : testNameToTesCase.entrySet()) {
2996-
LinkedHashMap<String, Object> testExample = entry.getValue();
2998+
LinkedHashMap<String, Object> testExample = (LinkedHashMap<String, Object>) entry.getValue();
29972999
String nameInSnakeCase = toTestCaseName(entry.getKey());
29983000
Object data = processTestExampleData(testExample.get("data"));
29993001
SchemaTestCase testCase = new SchemaTestCase(
@@ -3555,15 +3557,15 @@ protected List<MappedModel> getOneOfAnyOfDescendants(String composedSchemaName,
35553557
}
35563558
CodegenProperty df = discriminatorFound(composedSchemaName, sc, discPropName, new TreeSet<String>());
35573559
String modelName = ModelUtils.getSimpleRef(ref);
3558-
if (df == null || !df.isString || !df.required) {
3560+
if (df == null || !df.isString || df.required != true) {
35593561
String msgSuffix = "";
35603562
if (df == null) {
35613563
msgSuffix += discPropName + " is missing from the schema, define it as required and type string";
35623564
} else {
35633565
if (!df.isString) {
35643566
msgSuffix += "invalid type for " + discPropName + ", set it to string";
35653567
}
3566-
if (!df.required) {
3568+
if (df.required != true) {
35673569
String spacer = "";
35683570
if (msgSuffix.length() != 0) {
35693571
spacer = ". ";
@@ -3706,7 +3708,7 @@ protected CodegenDiscriminator createDiscriminator(String schemaName, Schema sch
37063708
}
37073709
}
37083710

3709-
if (!matched) {
3711+
if (matched == false) {
37103712
uniqueDescendants.add(otherDescendant);
37113713
}
37123714
}
@@ -4216,10 +4218,11 @@ public CodegenProperty fromProperty(String name, Schema p, boolean required, boo
42164218
property.isContainer = true;
42174219
if (ModelUtils.isSet(p)) {
42184220
property.containerType = "set";
4221+
property.containerTypeMapped = typeMapping.get(property.containerType);
42194222
} else {
42204223
property.containerType = "array";
4221-
}
42224224
property.containerTypeMapped = typeMapping.get(property.containerType);
4225+
}
42234226
property.baseType = getSchemaType(p);
42244227

42254228
// handle inner property
@@ -4360,7 +4363,7 @@ void updateDefaultToEmptyContainer(CodegenProperty cp, Schema p) {
43604363
* @param input a set of rules separated by `|`
43614364
*/
43624365
void parseDefaultToEmptyContainer(String input) {
4363-
String[] inputs = input.split("[|]");
4366+
String[] inputs = ((String) input).split("[|]");
43644367
String containerType;
43654368
for (String rule : inputs) {
43664369
if (StringUtils.isEmpty(rule)) {
@@ -4378,7 +4381,7 @@ void parseDefaultToEmptyContainer(String input) {
43784381
LOGGER.error("Skipped invalid container type `{}` in `{}`.", containerType, input);
43794382
}
43804383
} else if (rule.startsWith("?")) { // nullable (required)
4381-
containerType = rule.substring(1);
4384+
containerType = rule.substring(1, rule.length());
43824385
if ("array".equalsIgnoreCase(containerType)) {
43834386
arrayNullableDefaultToEmpty = true;
43844387
} else if ("map".equalsIgnoreCase(containerType)) {
@@ -6172,7 +6175,7 @@ protected void addVars(IJsonSchemaValidationProperties m, List<CodegenProperty>
61726175
} else {
61736176
final CodegenProperty cp;
61746177

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

@@ -8009,8 +8012,8 @@ protected LinkedHashMap<String, CodegenMediaType> getContent(Content content, Se
80098012
enc.getContentType(),
80108013
headers,
80118014
enc.getStyle().toString(),
8012-
enc.getExplode() != null && enc.getExplode(),
8013-
enc.getAllowReserved() != null && enc.getAllowReserved()
8015+
enc.getExplode() == null ? false : enc.getExplode().booleanValue(),
8016+
enc.getAllowReserved() == null ? false : enc.getAllowReserved().booleanValue()
80148017
);
80158018

80168019
if (enc.getExtensions() != null) {
@@ -8239,6 +8242,7 @@ protected void addRequiredVarsMap(Schema schema, IJsonSchemaValidationProperties
82398242
}
82408243
if (!found) {
82418244
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;
82428246
}
82438247
} else if (schema.getAdditionalProperties() instanceof Boolean && Boolean.FALSE.equals(schema.getAdditionalProperties())) {
82448248
// TODO add processing for requiredPropertyName
@@ -8583,7 +8587,7 @@ public void setRemoveEnumValuePrefix(final boolean removeEnumValuePrefix) {
85838587
* @param name name of the parent oneOf schema
85848588
*/
85858589
public void addOneOfNameExtension(Schema schema, String name) {
8586-
if (schema.getOneOf() != null && !schema.getOneOf().isEmpty()) {
8590+
if (schema.getOneOf() != null && schema.getOneOf().size() > 0) {
85878591
schema.addExtension(X_ONE_OF_NAME, name);
85888592
}
85898593
}

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

Lines changed: 10 additions & 8 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 final Map<String, String> generatorPropertyDefaults = new HashMap<>();
89+
private 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 final String generatorCheck = "spring";
99-
private final String templateCheck = "apiController.mustache";
98+
private String generatorCheck = "spring";
99+
private 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 = Strings.CS.prependIfMissing(templateExt, ".");
1395+
templateExt = StringUtils.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 = Strings.CS.removeStart(Strings.CS.removeStart(f.toString(), "." + File.separator), File.separator);
1997+
String relativePath = removeStart(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,8 +2004,10 @@ private void generateFilesMetadata(List<File> files) {
20042004
}
20052005
});
20062006

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

20102012
String targetFile = config.outputFolder() + File.separator + METADATA_DIR + File.separator + config.getFilesMetadataFilename();
20112013

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

20222024
private String removeTrailingSlash(String value) {
2023-
return Strings.CS.removeEnd(value, "/");
2025+
return StringUtils.removeEnd(value, "/");
20242026
}
20252027

20262028
}

0 commit comments

Comments
 (0)