Skip to content

Commit

Permalink
fix(scrape-datasource): adds additional deferred parent-child setters
Browse files Browse the repository at this point in the history
  • Loading branch information
alserom committed Jan 30, 2024
1 parent 4c48d7e commit 6bed2a7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
3 changes: 1 addition & 2 deletions cmd/to-repo-data/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -97,7 +96,7 @@ func execute(source, dir string) error {
}

outVersion := out + "/version.json"
err = ioutil.WriteFile(outVersion, []byte(fmt.Sprintf(`{"version":"%s"}`, spec.GetVersion())), 0644)
err = os.WriteFile(outVersion, []byte(fmt.Sprintf(`{"version":"%s"}`, spec.GetVersion())), 0644)
fmt.Println("saving: " + outVersion)
if err != nil {
return err
Expand Down
14 changes: 12 additions & 2 deletions internal/datasource/scrape/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,20 @@ func (s *Scraper) FillApiSpec(as *spec.ApiSpec) error {
}
}

if len(childToParent) > 0 {
for childName, parent := range childToParent {
if child, ok := as.GetType(childName); ok {
child.SetParent(parent)
parent.AddChild(child)
delete(childToParent, childName)
}
}
}

if len(childToParent) > 0 {
msg := "some types were not added to the spec:"
for name := range childToParent {
msg += "\n- " + name
for childName := range childToParent {
msg += "\n- " + childName
}
return errors.New(msg)
}
Expand Down

0 comments on commit 6bed2a7

Please sign in to comment.