Skip to content
GitLab
    • Explore Projects Groups Snippets
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Merge requests
  • !6409

[bug] Fix path provider bug on CI

  • Review changes

  • Download
  • Email patches
  • Plain diff
Merged Jim Schubert requested to merge fix-path-provider-bug into master 5 years ago
  • Overview 0
  • Commits 3
  • Pipelines 0
  • Changes 1

Previous path sorting logic failed on CI due to one or more files in the cpp-qt5 script being associated with different path providers. This caused a ClassCastException from Path#compareTo

This change uses Apache Commons PathFileComparator to sort by full path.

PR checklist

  • Read the contribution guidelines.
  • If contributing template-only or documentation-only changes which will change sample output, build the project before.
  • Run the shell script(s) under ./bin/ (or Windows batch scripts under.\bin\windows) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run ./bin/{LANG}-petstore.sh, ./bin/openapi3/{LANG}-petstore.sh if updating the code or mustache templates for a language ({LANG}) (e.g. php, ruby, python, etc).
  • File the PR against the correct branch: master, 4.3.x, 5.0.x. Default: master.
  • Copy the technical committee to review the pull request if your PR is targeting a particular programming language.

@OpenAPITools/generator-core-team

Compare
  • master (base)

and
  • latest version
    372109be
    3 commits, 2 years ago

1 file
+ 25
- 18

    Preferences

    File browser
    Compare changes
modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java
+ 25
- 18
  • View file @ 372109be

  • Edit in single-file editor

  • Open in Web IDE


@@ -30,6 +30,7 @@ import io.swagger.v3.oas.models.parameters.Parameter;
import io.swagger.v3.oas.models.security.*;
import io.swagger.v3.oas.models.tags.Tag;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.comparator.PathFileComparator;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.openapitools.codegen.config.GlobalSettings;
@@ -53,7 +54,6 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.time.ZonedDateTime;
import java.util.*;
import java.util.stream.Stream;
import static org.openapitools.codegen.utils.OnceLogger.once;
@@ -1061,26 +1061,33 @@ public class DefaultGenerator extends AbstractGenerator implements Generator {
System.err.println(sb.toString());
} else {
if (generateMetadata) {
StringBuilder sb = new StringBuilder();
File outDir = new File(this.config.getOutputDir());
Optional.of(files)
.map(Collection::stream)
.orElseGet(Stream::empty)
.filter(Objects::nonNull)
.map(File::toPath)
.sorted(Path::compareTo)
.forEach(f -> {
String relativePath = java.nio.file.Paths.get(outDir.toURI()).relativize(f).toString();
if (!relativePath.equals(METADATA_DIR + File.separator + "VERSION")) {
sb.append(relativePath).append(System.lineSeparator());
}
});
String targetFile = config.outputFolder() + File.separator + METADATA_DIR + File.separator + "FILES";
try {
StringBuilder sb = new StringBuilder();
File outDir = new File(this.config.getOutputDir());
List<File> filesToSort = new ArrayList<>();
// Avoid side-effecting sort in this path when generateMetadata=true
files.forEach(f -> {
// We have seen NPE on CI for getPath() returning null, so guard against this (to be fixed in 5.0 template management refactor)
//noinspection ConstantConditions
if (f != null && f.getPath() != null) {
filesToSort.add(f);
}
});
filesToSort.sort(PathFileComparator.PATH_COMPARATOR);
filesToSort.forEach(f -> {
String relativePath = outDir.toPath().relativize(f.toPath()).toString();
if (!relativePath.equals(METADATA_DIR + File.separator + "VERSION")) {
sb.append(relativePath).append(System.lineSeparator());
}
});
String targetFile = config.outputFolder() + File.separator + METADATA_DIR + File.separator + "FILES";
File filesFile = writeToFile(targetFile, sb.toString().getBytes(StandardCharsets.UTF_8));
files.add(filesFile);
} catch (IOException e) {
} catch (Exception e) {
LOGGER.warn("Failed to write FILES metadata to track generated files.");
}
}
0 Assignees
None
Assign to
0 Reviewers
None
Request review from
Labels
1
Issue: Bug
1
Issue: Bug
    Assign labels
  • Manage project labels

Milestone
5.0.0
5.0.0 (expired)
None
Time tracking
No estimate or time spent
Lock merge request
Unlocked
1
1 participant
Jim Schubert
Reference: OpenAPITools/openapi-generator!6409
Source branch: fix-path-provider-bug

Menu

Explore Projects Groups Snippets