Skip to content

Commit

Permalink
Instead of using "root.yaml" as a theoretical root, use the real file…
Browse files Browse the repository at this point in the history
…name of the root spec (often openapi.yaml). This fixes issues with resolving references in rules such as unsused-components.
  • Loading branch information
Calvin Lobo committed Aug 16, 2024
1 parent c3eb16d commit 132b01e
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions datamodel/document_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions datamodel/low/v3/create_document.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions index/index_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion index/rolodex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down

0 comments on commit 132b01e

Please sign in to comment.