mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-07 12:37:48 +00:00
Bumping coverage on schema to 100%
I think it should be pretty much bullet proof at the moment (until the next failure). Also added external index lookups from main index for external docs. found this bug after refining lookups in schemas.
This commit is contained in:
@@ -43,6 +43,31 @@ func LocateRefNode(root *yaml.Node, idx *index.SpecIndex) *yaml.Node {
|
||||
idx.GetAllResponses,
|
||||
idx.GetAllSecuritySchemes,
|
||||
}
|
||||
|
||||
// if there are any external indexes being used by remote
|
||||
// documents, then we need to search through them also.
|
||||
externalIndexes := idx.GetAllExternalIndexes()
|
||||
if len(externalIndexes) > 0 {
|
||||
var extCollection []func() map[string]*index.Reference
|
||||
for _, extIndex := range externalIndexes {
|
||||
extCollection = []func() map[string]*index.Reference{
|
||||
extIndex.GetAllSchemas,
|
||||
extIndex.GetMappedReferences,
|
||||
extIndex.GetAllExternalDocuments,
|
||||
extIndex.GetAllParameters,
|
||||
extIndex.GetAllHeaders,
|
||||
extIndex.GetAllCallbacks,
|
||||
extIndex.GetAllLinks,
|
||||
extIndex.GetAllExternalDocuments,
|
||||
extIndex.GetAllExamples,
|
||||
extIndex.GetAllRequestBodies,
|
||||
extIndex.GetAllResponses,
|
||||
extIndex.GetAllSecuritySchemes,
|
||||
}
|
||||
collections = append(collections, extCollection...)
|
||||
}
|
||||
}
|
||||
|
||||
var found map[string]*index.Reference
|
||||
for _, collection := range collections {
|
||||
found = collection()
|
||||
@@ -69,6 +94,16 @@ func LocateRefNode(root *yaml.Node, idx *index.SpecIndex) *yaml.Node {
|
||||
}
|
||||
|
||||
func ExtractObjectRaw[T Buildable[N], N any](root *yaml.Node, idx *index.SpecIndex) (T, error) {
|
||||
|
||||
if h, _, _ := utils.IsNodeRefValue(root); h {
|
||||
ref := LocateRefNode(root, idx)
|
||||
if ref != nil {
|
||||
root = ref
|
||||
} else {
|
||||
return nil, fmt.Errorf("object extraction failed: reference cannot be found: %s, line %d, col %d",
|
||||
root.Content[1].Value, root.Content[1].Line, root.Content[1].Column)
|
||||
}
|
||||
}
|
||||
var n T = new(N)
|
||||
err := BuildModel(root, n)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user