Tufin / oasdiff

OpenAPI Diff and Breaking Changes

Home Page:https://www.oasdiff.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error is thrown when using diff cmd with absolute windows path

ruvyas opened this issue · comments

Describe the bug
While running diff cmd on windows if we provide absolute path for spec file, we get following error
Error: failed to load base spec from "C:\\dev\\OpenApi\\spec1.yaml" with unsupported URI

To Reproduce
Steps to reproduce the behavior:

  1. Run oasdiff diff C:\dev\OpenApi\spec1.yaml C:\dev\OpenApi\spec2.yaml

  2. Spec 1 & Spec 2: using same file for both comparison, from local directory.
    base-spec

  3. Output
    Error is thrown.
    Error: failed to load base spec from "C:\\dev\\OpenApi\\spec1.yaml" with unsupported URI

Expected behavior
No error should be thrown and should successfully compare specs

Desktop (please complete the following information):

  • OS: [Windows 11 Pro Build 22631.2506]

Did a quick analysis and looks like the problem is in load.go. Specifically below code

// From is a convenience function that opens an OpenAPI spec from a URL or a local path based on the format of the path parameter
func From(loader Loader, source Source) (*openapi3.T, error) {

	if source.Stdin {
		return loader.LoadFromStdin()
	}

	uri, err := url.ParseRequestURI(source.Path)
	if err == nil {
		return loadFromURI(loader, uri)
	}

	return loader.LoadFromFile(source.Path)
}

ParseRequestURI returns with err nil and the subsequent code loadFromURI fails as it is not a valid URI.