Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwaggerHammer.filesFromDir fails on Windows filesystem #48

Open
johnmgithub opened this issue Dec 29, 2022 · 0 comments
Open

SwaggerHammer.filesFromDir fails on Windows filesystem #48

johnmgithub opened this issue Dec 29, 2022 · 0 comments
Labels
bug Something isn't working

Comments

@johnmgithub
Copy link

When running from a Windows file system (e.g. IDE running from source) filesFromDir fails to locate any ui or ui/template files. The cause is rootPath has / as the separator whereas Files.walk returns a list with \ as the separator, so the map(path -> path.toString().replace(rootPath, "")) doesn't make any replacements. I worked around it by adding a preceding replace("\\", "/")), not sure if that is the best way to deal with it though :)

Here is my workaround:

    public List<String> filesFromDir(String prefix, String dir) throws IOException {
        String rootPath = dir.replace("file:/", "");
        List<String> result;
        try (Stream<Path> stream = Files.walk(Paths.get(rootPath).toAbsolutePath())) {
            result = stream
                    .filter(path -> !Files.isDirectory(path))
                    .map(path -> path.toString().replace("\\", "/").replace(rootPath, ""))
                    .filter(name -> !name.equals(prefix) && name.startsWith(prefix))
                    .collect(Collectors.toList());
        }
        return result;
    }
@johnmgithub johnmgithub added the bug Something isn't working label Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant