mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-09 20:47:44 +00:00
Support for relative links now in place #73
Tests all passing, runs super fast, pulls in every single DigitalOcean spec and parses it. There may be some issues deeper down in the models, but for now high level tests all pass.
This commit is contained in:
@@ -3,16 +3,37 @@
|
||||
|
||||
package index
|
||||
|
||||
func (index *SpecIndex) SearchIndexForReference(ref string) []*Reference {
|
||||
import "gopkg.in/yaml.v3"
|
||||
|
||||
// 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 {
|
||||
if r, ok := index.allMappedRefs[ref]; ok {
|
||||
if r.Node.Kind == yaml.DocumentNode {
|
||||
// the reference is an entire document, so we need to dig down a level and rewire the reference.
|
||||
r.Node = r.Node.Content[0]
|
||||
}
|
||||
return []*Reference{r}
|
||||
}
|
||||
if r, ok := index.externalSpecIndex[ref]; ok {
|
||||
return []*Reference{
|
||||
{
|
||||
Node: r.root.Content[0],
|
||||
Name: ref,
|
||||
Definition: ref,
|
||||
},
|
||||
}
|
||||
}
|
||||
for c := range index.children {
|
||||
found := index.children[c].SearchIndexForReference(ref)
|
||||
found := goFindMeSomething(index.children[c], ref)
|
||||
if found != nil {
|
||||
return found
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func goFindMeSomething(i *SpecIndex, ref string) []*Reference {
|
||||
return i.SearchIndexForReference(ref)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user