Skip to content

Commit 41851b4

Browse files
authored
[bug] Fix FILES sort and path provider issue (#7729)
The FILES metadata is supplementary, but was logging a warning while generating Ada client that FILES couldn't be written. An exception was being thrown because Path was being reported as two different "types of Path". One would be reported as mac file, while the other was reported as a unix file. The fix here is to disconnect path details from the underlying file system provider by creating a new Path based on the file's absolute path. This change also fixes sorting so it works alphabetically in ascending order.
1 parent e1e38c8 commit 41851b4

File tree

20 files changed

+48
-36
lines changed
  • modules/openapi-generator/src/main/java/org/openapitools/codegen
  • samples
    • client/petstore
      • ada/.openapi-generator
      • typescript-angular-v10-provided-in-root/builds
        • default/.openapi-generator
        • with-npm/.openapi-generator
      • typescript-angular-v6-not-provided-in-root/builds
        • default/.openapi-generator
        • with-npm/.openapi-generator
      • typescript-angular-v6-provided-in-root/builds
        • default/.openapi-generator
        • with-npm/.openapi-generator
      • typescript-angular-v7-not-provided-in-root/builds
        • default/.openapi-generator
        • with-npm/.openapi-generator
      • typescript-angular-v7-provided-in-root/builds
        • default/.openapi-generator
        • with-npm/.openapi-generator
      • typescript-angular-v8-provided-in-root/builds
        • single-request-parameter/.openapi-generator
        • with-npm/.openapi-generator
        • with-prefixed-module-name/.openapi-generator
      • typescript-angular-v9-provided-in-root/builds
        • default/.openapi-generator
        • with-npm/.openapi-generator
      • typescript-node
        • default/.openapi-generator
        • npm/.openapi-generator
    • server/petstore/php-symfony/SymfonyBundle-php/.openapi-generator

20 files changed

+48
-36
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,11 @@ private void generateVersionMetadata(List<File> files) {
14331433
}
14341434
}
14351435

1436+
private Path absPath(File input) {
1437+
// intentionally creates a new absolute path instance, disconnected from underlying FileSystem provider of File
1438+
return java.nio.file.Paths.get(input.getAbsolutePath());
1439+
}
1440+
14361441
/**
14371442
* Generates a file at .openapi-generator/FILES to track the files created by the user's latest run.
14381443
* This is ideal for CI and regeneration of code without stale/unused files from older generations.
@@ -1443,7 +1448,7 @@ private void generateFilesMetadata(List<File> files) {
14431448
if (generateMetadata) {
14441449
try {
14451450
StringBuilder sb = new StringBuilder();
1446-
File outDir = new File(this.config.getOutputDir());
1451+
Path outDir = absPath(new File(this.config.getOutputDir()));
14471452

14481453
List<File> filesToSort = new ArrayList<>();
14491454

@@ -1452,7 +1457,7 @@ private void generateFilesMetadata(List<File> files) {
14521457
// We have seen NPE on CI for getPath() returning null, so guard against this (to be fixed in 5.0 template management refactor)
14531458
//noinspection ConstantConditions
14541459
if (f != null && f.getPath() != null) {
1455-
filesToSort.add(f);
1460+
filesToSort.add(outDir.relativize(absPath(f)).normalize().toFile());
14561461
}
14571462
});
14581463

@@ -1461,13 +1466,12 @@ private void generateFilesMetadata(List<File> files) {
14611466
String relativeMeta = METADATA_DIR + "/VERSION";
14621467
filesToSort.sort(PathFileComparator.PATH_COMPARATOR);
14631468
filesToSort.forEach(f -> {
1464-
String tmp = outDir.toPath().relativize(f.toPath()).normalize().toString();
14651469
// some Java implementations don't honor .relativize documentation fully.
14661470
// When outDir is /a/b and the input is /a/b/c/d, the result should be c/d.
14671471
// Some implementations make the output ./c/d which seems to mix the logic
14681472
// as documented for symlinks. So we need to trim any / or ./ from the start,
14691473
// as nobody should be generating into system root and our expectation is no ./
1470-
String relativePath = removeStart(removeStart(tmp, "." + File.separator), File.separator);
1474+
String relativePath = removeStart(removeStart(f.toString(), "." + File.separator), File.separator);
14711475
if (File.separator.equals("\\")) {
14721476
// ensure that windows outputs same FILES format
14731477
relativePath = relativePath.replace(File.separator, "/");
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
config.gpr
2+
src/client/samples-petstore-clients.adb
3+
src/client/samples-petstore-clients.ads
4+
src/model/samples-petstore-models.adb
5+
src/model/samples-petstore-models.ads
6+
src/samples-petstore-client.adb
7+
src/samples-petstore.ads
8+
src/samples.ads

samples/client/petstore/typescript-angular-v10-provided-in-root/builds/default/.openapi-generator/FILES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ git_push.sh
1111
index.ts
1212
model/apiResponse.ts
1313
model/category.ts
14+
model/models.ts
1415
model/order.ts
1516
model/pet.ts
1617
model/tag.ts
1718
model/user.ts
18-
model/models.ts
1919
variables.ts

samples/client/petstore/typescript-angular-v10-provided-in-root/builds/with-npm/.openapi-generator/FILES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ git_push.sh
1111
index.ts
1212
model/apiResponse.ts
1313
model/category.ts
14+
model/models.ts
1415
model/order.ts
1516
model/pet.ts
1617
model/tag.ts
1718
model/user.ts
18-
model/models.ts
1919
ng-package.json
2020
package.json
2121
tsconfig.json

samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/default/.openapi-generator/FILES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ git_push.sh
1111
index.ts
1212
model/apiResponse.ts
1313
model/category.ts
14+
model/models.ts
1415
model/order.ts
1516
model/pet.ts
1617
model/tag.ts
1718
model/user.ts
18-
model/models.ts
1919
variables.ts

samples/client/petstore/typescript-angular-v6-not-provided-in-root/builds/with-npm/.openapi-generator/FILES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ git_push.sh
1111
index.ts
1212
model/apiResponse.ts
1313
model/category.ts
14+
model/models.ts
1415
model/order.ts
1516
model/pet.ts
1617
model/tag.ts
1718
model/user.ts
18-
model/models.ts
1919
ng-package.json
2020
package.json
2121
tsconfig.json

samples/client/petstore/typescript-angular-v6-provided-in-root/builds/default/.openapi-generator/FILES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ git_push.sh
1111
index.ts
1212
model/apiResponse.ts
1313
model/category.ts
14+
model/models.ts
1415
model/order.ts
1516
model/pet.ts
1617
model/tag.ts
1718
model/user.ts
18-
model/models.ts
1919
variables.ts

samples/client/petstore/typescript-angular-v6-provided-in-root/builds/with-npm/.openapi-generator/FILES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ git_push.sh
1111
index.ts
1212
model/apiResponse.ts
1313
model/category.ts
14+
model/models.ts
1415
model/order.ts
1516
model/pet.ts
1617
model/tag.ts
1718
model/user.ts
18-
model/models.ts
1919
ng-package.json
2020
package.json
2121
tsconfig.json

samples/client/petstore/typescript-angular-v7-not-provided-in-root/builds/default/.openapi-generator/FILES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ git_push.sh
1111
index.ts
1212
model/apiResponse.ts
1313
model/category.ts
14+
model/models.ts
1415
model/order.ts
1516
model/pet.ts
1617
model/tag.ts
1718
model/user.ts
18-
model/models.ts
1919
variables.ts

samples/client/petstore/typescript-angular-v7-not-provided-in-root/builds/with-npm/.openapi-generator/FILES

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ git_push.sh
1111
index.ts
1212
model/apiResponse.ts
1313
model/category.ts
14+
model/models.ts
1415
model/order.ts
1516
model/pet.ts
1617
model/tag.ts
1718
model/user.ts
18-
model/models.ts
1919
ng-package.json
2020
package.json
2121
tsconfig.json

0 commit comments

Comments
 (0)