forked from loafle/openapi-generator-original
fix(core): relative path sorting (#19726)
This commit is contained in:
parent
2111713117
commit
0371799857
@ -32,7 +32,7 @@ import io.swagger.v3.oas.models.security.*;
|
||||
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;
|
||||
@ -1988,7 +1988,8 @@ public class DefaultGenerator implements Generator {
|
||||
// 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<String> 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.
|
||||
@ -2001,10 +2002,15 @@ public class DefaultGenerator implements Generator {
|
||||
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));
|
||||
|
Loading…
x
Reference in New Issue
Block a user