diff --git a/index/index_model.go b/index/index_model.go index 5dec6bb2..02c87071 100644 --- a/index/index_model.go +++ b/index/index_model.go @@ -155,7 +155,8 @@ type SpecIndexConfig struct { uri []string } -// SetTheoreticalRoot sets the spec file paths to a theoretical file path +// SetTheoreticalRoot sets the spec file paths to point to a theoretical spec file, which does not exist but is required +// in order to formulate the absolute path to root references correctly. func (s *SpecIndexConfig) SetTheoreticalRoot() { s.SpecFilePath = filepath.Join(s.BasePath, theoreticalRoot) diff --git a/index/spec_index.go b/index/spec_index.go index 56861b37..ad146f6b 100644 --- a/index/spec_index.go +++ b/index/spec_index.go @@ -16,6 +16,7 @@ import ( "fmt" "log/slog" "os" + "path/filepath" "sort" "strings" "sync" @@ -26,6 +27,7 @@ import ( ) const ( + // theoreticalRoot is the name of the theoretical spec file used when a root spec file does not exist theoreticalRoot = "root.yaml" ) @@ -156,11 +158,12 @@ func (index *SpecIndex) GetRolodex() *Rolodex { return index.rolodex } +// GetSpecFileName returns the root spec filename, if it exists, otherwise returns the theoretical root spec func (index *SpecIndex) GetSpecFileName() string { - if index == nil || index.rolodex == nil || index.rolodex.indexConfig == nil { + if index == nil || index.rolodex == nil || index.rolodex.indexConfig == nil || index.rolodex.indexConfig.SpecFilePath == "" { return theoreticalRoot } - return index.rolodex.indexConfig.SpecFilePath + return filepath.Base(index.rolodex.indexConfig.SpecFilePath) } // GetGlobalTagsNode returns document root tags node.