Skip to content

[Bug]: RefUtils.readAll(path) method breaks relative $ref resolution for non-default FileSystem (e.g. Spring Boot 4 nested jars) #2298

@sjsachinrj

Description

@sjsachinrj

Description

While using swagger-parser-v3 with Spring Boot 4, relative $ref resolution fails when OpenAPI files are loaded from inside a fat/uber JAR.

This issue appears to be caused by RefUtils.readAll(Path path) method:

private static String readAll(Path path) throws IOException {
    try (InputStream inputStream = new FileInputStream(path.toFile())) {
        return IOUtils.toString(inputStream, UTF_8);
    }
}

Here path.toFile() only works with the default filesystem and fails for paths backed by non-default filesystem providers e.g ZipPath provider

Proposed solution

Replace path.toFile() with Files.newInputStream(path) which is more robust and file system agnostic and will work with local file system as well as zip file system

private static String readAll(Path path) throws IOException {
    try (InputStream inputStream = Files.newInputStream(path)) {
        return IOUtils.toString(inputStream, UTF_8);
    }
}

Affected Version

2.1.39

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions