Skip to content

Commit

Permalink
Set indexConfig.SpecAbsolutePath to "root.yaml" (theoretical root) wh…
Browse files Browse the repository at this point in the history
…en the spec's root does not exist on the filesystem (either read from remote URL or []byte)
  • Loading branch information
Calvin Lobo authored and daveshanley committed Sep 9, 2024
1 parent 546778c commit 2fc6ac8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
1 change: 1 addition & 0 deletions bundler/bundler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
8 changes: 7 additions & 1 deletion index/rolodex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 2fc6ac8

Please sign in to comment.