Files
libopenapi/index/search_index.go
quobix d5f72a2a2e a first working engine of the new design.
There is a horrible amount of work to be done to clean this up, and wire in remote support. but so far, this is working as expected and is now a much cleaner design, (once everything has been cleaned up that is)

Signed-off-by: quobix <dave@quobix.com>
2023-10-16 13:36:30 -04:00

63 lines
1.5 KiB
Go

// Copyright 2023 Princess B33f Heavy Industries / Dave Shanley
// SPDX-License-Identifier: MIT
package index
import (
"fmt"
"path/filepath"
"strings"
)
// SearchIndexForReference searches the index for a reference, first looking through the mapped references
// and then externalSpecIndex for a match. If no match is found, it will recursively search the child indexes
// extracted when parsing the OpenAPI Spec.
func (index *SpecIndex) SearchIndexForReference(ref string) []*Reference {
absPath := index.specAbsolutePath
var roloLookup string
uri := strings.Split(ref, "#/")
if len(uri) == 2 {
if uri[0] != "" {
roloLookup, _ = filepath.Abs(filepath.Join(absPath, uri[0]))
}
ref = fmt.Sprintf("#/%s", uri[1])
}
if r, ok := index.allMappedRefs[ref]; ok {
return []*Reference{r}
}
// TODO: look in the rolodex.
panic("should not be here")
fmt.Println(roloLookup)
return nil
//if r, ok := index.allMappedRefs[ref]; ok {
// return []*Reference{r}jh
//}
//for c := range index.children {
// found := goFindMeSomething(index.children[c], ref)
// if found != nil {
// return found
// }
//}
//return nil
}
func (index *SpecIndex) SearchAncestryForSeenURI(uri string) *SpecIndex {
//if index.parentIndex == nil {
// return nil
//}
//if index.uri[0] != uri {
// return index.parentIndex.SearchAncestryForSeenURI(uri)
//}
//return index
return nil
}
func goFindMeSomething(i *SpecIndex, ref string) []*Reference {
return i.SearchIndexForReference(ref)
}