Set indexConfig.SpecAbsolutePath to "root.yaml" (theoretical root) when the spec's root does not exist on the filesystem (either read from remote URL or []byte)

This commit is contained in:
Calvin Lobo
2024-08-28 09:15:47 -04:00
committed by quobix
parent 546778c93e
commit 2fc6ac8a84
2 changed files with 8 additions and 1 deletions

View File

@@ -38,6 +38,7 @@ func TestBundleDocument_DigitalOcean(t *testing.T) {
digi, _ := os.ReadFile(spec)
doc, err := libopenapi.NewDocumentWithConfiguration([]byte(digi), &datamodel.DocumentConfiguration{
SpecFilePath: spec,
BasePath: tmp + "/specification",
ExtractRefsSequentially: true,
Logger: slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{

View File

@@ -313,7 +313,13 @@ func (r *Rolodex) IndexTheRolodex() error {
}
if len(r.localFS) > 0 || len(r.remoteFS) > 0 {
r.indexConfig.SpecAbsolutePath = filepath.Join(basePath, filepath.Base(r.indexConfig.SpecFilePath))
// For specs that are not read from a filesystem (either from remote URL or []byte), we need to
// assign a theoretical root file. Having a root file is necessary when mapping references.
rootFile := "root.yaml"
if r.indexConfig.SpecFilePath != "" {
rootFile = filepath.Base(r.indexConfig.SpecFilePath)
}
r.indexConfig.SpecAbsolutePath = filepath.Join(basePath, rootFile)
}
}