Instead of using "root.yaml" as a theoretical root, use the real filename of the root spec (often openapi.yaml). This fixes issues with resolving references in rules such as unsused-components.

This commit is contained in:
Calvin Lobo
2024-08-16 12:44:30 -04:00
committed by quobix
parent 7eb70792a3
commit 9ab482ac9b
4 changed files with 8 additions and 1 deletions

View File

@@ -39,6 +39,9 @@ type DocumentConfiguration struct {
// To avoid sucking in all the files, set the FileFilter to a list of specific files to be included.
BasePath string // set the Base Path for resolving relative references if the spec is exploded.
// SpecFilePath is the name of the root specification file (usually named "openapi.yaml").
SpecFilePath string
// FileFilter is a list of specific files to be included by the rolodex when looking up references. If this value
// is set, then only these specific files will be included. If this value is not set, then all files will be included.
FileFilter []string

View File

@@ -45,6 +45,7 @@ func createDocument(info *datamodel.SpecInfo, config *datamodel.DocumentConfigur
idxConfig.AvoidCircularReferenceCheck = true
idxConfig.BaseURL = config.BaseURL
idxConfig.BasePath = config.BasePath
idxConfig.SpecFilePath = config.SpecFilePath
idxConfig.Logger = config.Logger
extract := config.ExtractRefsSequentially
idxConfig.ExtractRefsSequentially = extract

View File

@@ -87,6 +87,9 @@ type SpecIndexConfig struct {
// If resolving locally, the BasePath will be the root from which relative references will be resolved from
BasePath string // set the Base Path for resolving relative references if the spec is exploded.
// SpecFilePath is the name of the root specification file (usually named "openapi.yaml").
SpecFilePath string
// In an earlier version of libopenapi (pre 0.6.0) the index would automatically resolve all references
// They could have been local, or they could have been remote. This was a problem because it meant
// There was a potential for a remote exploit if a remote reference was malicious. There aren't any known

View File

@@ -312,7 +312,7 @@ func (r *Rolodex) IndexTheRolodex() error {
}
if len(r.localFS) > 0 || len(r.remoteFS) > 0 {
r.indexConfig.SpecAbsolutePath = filepath.Join(basePath, "root.yaml")
r.indexConfig.SpecAbsolutePath = filepath.Join(basePath, filepath.Base(r.indexConfig.SpecFilePath))
}
}