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 committed Aug 28, 2024
1 parent bc413a1 commit eb7e09a
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)

Check warning on line 320 in index/rolodex.go

View check run for this annotation

Codecov / codecov/patch

index/rolodex.go#L320

Added line #L320 was not covered by tests
}
r.indexConfig.SpecAbsolutePath = filepath.Join(basePath, rootFile)
}
}

Expand Down

0 comments on commit eb7e09a

Please sign in to comment.