swagger-parser icon indicating copy to clipboard operation
swagger-parser copied to clipboard

API Spec cannot be read from classpath or JAR on *Windows* file system

Open GlennTeillet opened this issue 3 years ago • 0 comments

Getting Exception on Windows when reading a API spec packaged in the jar file to validate requests.

OpenAPIV3Parser.readContentFromLocation() uses the underlying sun.nio.file.Paths to find the API specs... on unix, this works file.

However, on Windows, the underlying java.nio.file.Path.of () uses the WindowsPathParser that in turn does not accept needed chars like ":" needed to read from a jar subsystem. Causing : j.n.f.InvalidPathException: Illegal char <:> at index 9: classpath:/static/my-api.yaml.

more complete stack:

j.n.f.InvalidPathException: Illegal char <:> at index 9: classpath:/static/my-api.yaml at s.n.f.WindowsPathParser.normalize(WindowsPathParser.java:182) at s.n.f.WindowsPathParser.parse(WindowsPathParser.java:153) at s.n.f.WindowsPathParser.parse(WindowsPathParser.java:77) at s.nio.fs.WindowsPath.parse(WindowsPath.java:92) at s.n.f.WindowsFileSystem.getPath(WindowsFileSystem.java:229) at java.nio.file.Path.of(Path.java:147) at java.nio.file.Paths.get(Paths.java:69) at i.s.v.p.OpenAPIV3Parser.readContentFromLocation(OpenAPIV3Parser.java:225)

Versions use:

swagger-request-validator-core: 2.22.0 swagger-request-validator-springmvc: 2.22.0 io.swagger.parser.v3: 2.0.28 openjdk version "11.0.6" 2020-01-14 OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.6+10)

To sum it up:

As a system developer, I want the OpenAPIV2Parser to read the packaged spec from the jar file on Windows to get same behavior as Unix and to enable me to package my application and ressources as a single jar file.

GlennTeillet avatar Nov 18 '21 18:11 GlennTeillet