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

[bug] remote specs with local references #292

Open
matoous opened this issue May 14, 2024 · 0 comments
Open

[bug] remote specs with local references #292

matoous opened this issue May 14, 2024 · 0 comments
Labels
requires investigation This needs to be looked at in more detail

Comments

@matoous
Copy link

matoous commented May 14, 2024

Hi! Working with libopenapi locally recently I hit an issue when working with a remote specs (e.g. using https://raw.githubusercontent.com/org/repo/main/specs/openapi.yaml) if the specs contain local references. I first load the file using URL, then pass it to NewDocumentWithConfiguration with BaseURL configured to the URL of the file I used minus the filename itself:

doc, err := libopenapi.NewDocumentWithConfiguration(specBytes, &datamodel.DocumentConfiguration{
	BaseURL:          baseURL(*specURL),
	RemoteURLHandler: handler, // GitHub auth, nothing more happening here
})
if err != nil {
	return nil, fmt.Errorf("create document: %v", err)
}

func baseURL(u url.URL) *url.URL {
	dir, _ := path.Split(u.Path)
	u.Path = dir
	u.RawQuery = ""
	return &u
}

When calling:

spec, errs := doc.BuildV3Model()

though I get an error:

cannot resolve reference `../../../schemas/components.yaml#/components/schemas/Device`, it's missing: $schemas['components.yaml$'].components.schemas.Device [827:11]

suggesting that it can't resolve locally referenced file in the remote specs.

I am not sure what exactly is going wrong, but I am happy to contribute if given a few pointers.

Happens at [my org] so I don't have sharable files for replicating this readily available but if necessary, I can try and craft some.

@daveshanley daveshanley added the requires investigation This needs to be looked at in more detail label May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
requires investigation This needs to be looked at in more detail
Projects
None yet
Development

No branches or pull requests

2 participants