cleanup: add sync version of ExtractSpecInfoWithDocumentCheck

This commit is contained in:
Tristan Cartledge
2023-12-07 12:57:46 +00:00
parent fac9a4b3b1
commit 41557cebcb
4 changed files with 12 additions and 6 deletions

View File

@@ -51,6 +51,15 @@ func ExtractSpecInfoWithConfig(spec []byte, config *DocumentConfiguration) (*Spe
return ExtractSpecInfoWithDocumentCheck(spec, config.BypassDocumentCheck)
}
func ExtractSpecInfoWithDocumentCheckSync(spec []byte, bypass bool) (*SpecInfo, error) {
i, err := ExtractSpecInfoWithDocumentCheck(spec, bypass)
if err != nil {
return nil, err
}
<-i.GetJSONParsingChannel()
return i, nil
}
func ExtractSpecInfoWithDocumentCheck(spec []byte, bypass bool) (*SpecInfo, error) {
var parsedSpec yaml.Node

View File

@@ -52,14 +52,13 @@ func (rf *rolodexFile) Index(config *SpecIndexConfig) (*SpecIndex, error) {
}
// first, we must parse the content of the file
info, err := datamodel.ExtractSpecInfoWithDocumentCheck(content, config.SkipDocumentCheck)
info, err := datamodel.ExtractSpecInfoWithDocumentCheckSync(content, config.SkipDocumentCheck)
if err != nil {
return nil, err
}
// create a new index for this file and link it to this rolodex.
config.Rolodex = rf.rolodex
<-info.GetJSONParsingChannel() // TODO this almost makes the async parsing pointless, is there a later point to do this?
index := NewSpecIndexWithConfig(info.RootNode, config)
rf.index = index
return index, nil

View File

@@ -182,12 +182,11 @@ func (l *LocalFile) Index(config *SpecIndexConfig) (*SpecIndex, error) {
content := l.data
// first, we must parse the content of the file
info, err := datamodel.ExtractSpecInfoWithDocumentCheck(content, true)
info, err := datamodel.ExtractSpecInfoWithDocumentCheckSync(content, true)
if err != nil {
return nil, err
}
<-info.GetJSONParsingChannel() // TODO this almost makes the async parsing pointless, is there a later point to do this?
index := NewSpecIndexWithConfig(info.RootNode, config)
index.specAbsolutePath = l.fullPath

View File

@@ -180,12 +180,11 @@ func (f *RemoteFile) Index(config *SpecIndexConfig) (*SpecIndex, error) {
content := f.data
// first, we must parse the content of the file
info, err := datamodel.ExtractSpecInfoWithDocumentCheck(content, true)
info, err := datamodel.ExtractSpecInfoWithDocumentCheckSync(content, true)
if err != nil {
return nil, err
}
<-info.GetJSONParsingChannel() // TODO this almost makes the async parsing pointless, is there a later point to do this?
index := NewSpecIndexWithConfig(info.RootNode, config)
index.specAbsolutePath = config.SpecAbsolutePath
f.index = index