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

ResolveFully fails on internal references when the initial spec is read from a file URL

Open klease opened this issue 1 year ago • 1 comments

Hi, While testing the new 3.1.0 feature of a pathItem in components, I found that resolveFully is not replacing internal references such as $ref: "#/components/pathItems/getPet" when the initial URL to the spec is a file:// URL. There is an exception in the log like this:

java.io.FileNotFoundException: file:/...../target/test-classes/petstore-3.1.yaml (Aucun fichier ou dossier de ce type)
        at java.io.FileInputStream.open0(Native Method) ~[?:?]
        at java.io.FileInputStream.open(FileInputStream.java:216) ~[?:?]
        at java.io.FileInputStream.<init>(FileInputStream.java:157) ~[?:?]
        at java.io.FileInputStream.<init>(FileInputStream.java:111) ~[?:?]
        at io.swagger.v3.parser.reference.Visitor.readFile(Visitor.java:66) ~[swagger-parser-v3-2.1.13.jar:2.1.13]
        at io.swagger.v3.parser.reference.Visitor.readURI(Visitor.java:84) ~[swagger-parser-v3-2.1.13.jar:2.1.13]
        at io.swagger.v3.parser.reference.ReferenceVisitor.parse(ReferenceVisitor.java:279) ~[swagger-parser-v3-2.1.13.jar:2.1.13]

This is true for any internal reference from the initial specification. The Visitor.readFile() method needs to transform the file URL to a valid path. I've never contributed to swagger before but I could create a test case and PR for this issue.

klease avatar May 07 '23 16:05 klease