Skip to content

Commit

Permalink
finalize changes
Browse files Browse the repository at this point in the history
Signed-off-by: MUzairS15 <[email protected]>
  • Loading branch information
MUzairS15 committed Sep 30, 2024
1 parent 45521cd commit 98a1e99
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion generators/github/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (gp GitHubPackage) GenerateComponents() ([]_component.ComponentDefinition,

comps, err := component.GenerateFromOpenAPI(string(crd), gp)
if err != nil {
errs = append(errs, err)
errs = append(errs, component.ErrGetSchema(err))
continue
}
components = append(components, comps...)
Expand Down
28 changes: 22 additions & 6 deletions utils/component/openapi_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ func GenerateFromOpenAPI(resource string, pkg models.Package) ([]component.Compo
}
cuectx := cuecontext.New()
cueParsedManExpr, err := cueJson.Extract("", []byte(resource))
if err != nil {
return nil, err
}

parsedManifest := cuectx.BuildExpr(cueParsedManExpr)
definitions := parsedManifest.LookupPath(cue.ParsePath("components.schemas"))
definitions, err := utils.Lookup(parsedManifest, "components.schemas")

if err != nil {
return nil, err
Expand All @@ -46,8 +50,8 @@ func GenerateFromOpenAPI(resource string, pkg models.Package) ([]component.Compo

for fields.Next() {
fieldVal := fields.Value()
kindCue := fieldVal.LookupPath(cue.ParsePath(`"x-kubernetes-group-version-kind"[0].kind`))
if kindCue.Err() != nil {
kindCue, err := utils.Lookup(fieldVal, `"x-kubernetes-group-version-kind"[0].kind`)
if err != nil {
continue
}
kind, err := kindCue.String()
Expand All @@ -62,8 +66,16 @@ func GenerateFromOpenAPI(resource string, pkg models.Package) ([]component.Compo
fmt.Printf("%v", err)
continue
}
versionCue := fieldVal.LookupPath(cue.ParsePath(`"x-kubernetes-group-version-kind"[0].version`))
groupCue := fieldVal.LookupPath(cue.ParsePath(`"x-kubernetes-group-version-kind"[0].group`))
versionCue, err := utils.Lookup(fieldVal, `"x-kubernetes-group-version-kind"[0].version`)
if err != nil {
continue
}

groupCue, err := utils.Lookup(fieldVal, `"x-kubernetes-group-version-kind"[0].group`)
if err != nil {
continue
}

apiVersion, _ := versionCue.String()
if g, _ := groupCue.String(); g != "" {
apiVersion = g + "/" + apiVersion
Expand Down Expand Up @@ -140,8 +152,12 @@ func getResolvedManifest(manifest string) (string, error) {

cuectx := cuecontext.New()
cueParsedManExpr, err := cueJson.Extract("", byt)
if err != nil {
return "", ErrGetSchema(err)
}

parsedManifest := cuectx.BuildExpr(cueParsedManExpr)
definitions := parsedManifest.LookupPath(cue.ParsePath("components.schemas"))
definitions, err := utils.Lookup(parsedManifest, "components.schemas")
if err != nil {
return "", err
}
Expand Down

0 comments on commit 98a1e99

Please sign in to comment.