Skip to content

Commit 2ec246b

Browse files
committed
Fix Windows path
Signed-off-by: Ricardo Zanini <[email protected]>
1 parent 42b4a21 commit 2ec246b

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

client/deployment/src/test/java/io/quarkiverse/openapi/generator/deployment/wrapper/OpenApiClientGeneratorWrapperTest.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,14 @@
99

1010
import java.io.File;
1111
import java.io.FileNotFoundException;
12+
import java.net.URI;
1213
import java.net.URISyntaxException;
14+
import java.net.URL;
1315
import java.nio.file.Path;
1416
import java.nio.file.Paths;
1517
import java.util.List;
1618
import java.util.Map;
19+
import java.util.Objects;
1720
import java.util.Optional;
1821
import java.util.stream.Collectors;
1922

@@ -760,15 +763,34 @@ private OpenApiClientGeneratorWrapper createGeneratorWrapper(String specFileName
760763
}
761764

762765
private Path getOpenApiSpecPath(String specFileName) throws URISyntaxException {
763-
return Path.of(requireNonNull(this.getClass().getResource(String.format("/openapi/%s", specFileName))).toURI());
766+
URL url = this.getClass().getResource("/openapi/" + specFileName);
767+
Objects.requireNonNull(url, "Could not find /openapi/" + specFileName);
768+
769+
URI uri;
770+
try {
771+
uri = url.toURI();
772+
} catch (URISyntaxException e) {
773+
// this should never happen for a well-formed file URL
774+
throw new RuntimeException("Invalid URI for " + url, e);
775+
}
776+
777+
return Paths.get(uri);
764778
}
765779

766780
private Path getOpenApiTargetPath(Path openApiSpec) throws URISyntaxException {
767781
return Paths.get(getTargetDir(), "openapi-gen");
768782
}
769783

770-
private String getTargetDir() throws URISyntaxException {
771-
return Paths.get(requireNonNull(getClass().getResource("/")).toURI()).getParent().toString();
784+
private String getTargetDir() {
785+
URL url = requireNonNull(getClass().getResource("/"),
786+
"Could not locate classpath root");
787+
try {
788+
return Paths.get(url.toURI())
789+
.getParent()
790+
.toString();
791+
} catch (URISyntaxException e) {
792+
throw new RuntimeException("Invalid URI for " + url, e);
793+
}
772794
}
773795

774796
private Optional<VariableDeclarator> findVariableByName(List<FieldDeclaration> fields, String name) {

0 commit comments

Comments
 (0)