diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java index fe4d15461ffe..7ef205eab4ec 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java @@ -31,7 +31,7 @@ import io.swagger.v3.oas.models.tags.Tag; import lombok.Getter; import org.apache.commons.io.FilenameUtils; -import org.apache.commons.io.comparator.PathFileComparator; +import org.apache.commons.io.IOCase; import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.StringUtils; import org.openapitools.codegen.api.TemplateDefinition; @@ -1981,7 +1981,8 @@ private void generateFilesMetadata(List files) { // NOTE: Don't use File.separator here as we write linux-style paths to FILES, and File.separator will // result in incorrect match on Windows machines. String relativeMeta = METADATA_DIR + "/VERSION"; - filesToSort.sort(PathFileComparator.PATH_COMPARATOR); + + final List relativePaths = new ArrayList<>(filesToSort.size()); filesToSort.forEach(f -> { // some Java implementations don't honor .relativize documentation fully. // When outDir is /a/b and the input is /a/b/c/d, the result should be c/d. @@ -1994,10 +1995,15 @@ private void generateFilesMetadata(List files) { relativePath = relativePath.replace(File.separator, "/"); } if (!relativePath.equals(relativeMeta)) { - sb.append(relativePath).append(System.lineSeparator()); + relativePaths.add(relativePath); } }); + Collections.sort(relativePaths, (a, b) -> IOCase.SENSITIVE.checkCompareTo(a,b)); + relativePaths.forEach(relativePath -> { + sb.append(relativePath).append(System.lineSeparator()); + }); + String targetFile = config.outputFolder() + File.separator + METADATA_DIR + File.separator + config.getFilesMetadataFilename(); File filesFile = this.templateProcessor.writeToFile(targetFile, sb.toString().getBytes(StandardCharsets.UTF_8));