From 2fc6ac8a84e3e34f1f9c80f568c5e12d61cb8e84 Mon Sep 17 00:00:00 2001 From: Calvin Lobo Date: Wed, 28 Aug 2024 09:15:47 -0400 Subject: [PATCH] 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) --- bundler/bundler_test.go | 1 + index/rolodex.go | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/bundler/bundler_test.go b/bundler/bundler_test.go index c2b366e..56ee4d0 100644 --- a/bundler/bundler_test.go +++ b/bundler/bundler_test.go @@ -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{ diff --git a/index/rolodex.go b/index/rolodex.go index c97d184..512ceb0 100644 --- a/index/rolodex.go +++ b/index/rolodex.go @@ -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) } }