Skip to content

Commit

Permalink
gocode: Fix subpath generation in bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
sam boyer committed Jul 14, 2023
1 parent 3ea3e07 commit da9fe56
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
10 changes: 8 additions & 2 deletions cmd/thema/lineage_subgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ import (
"cuelang.org/go/cue/cuecontext"
"cuelang.org/go/pkg/encoding/yaml"
"github.com/dave/dst"
"github.com/spf13/cobra"
"golang.org/x/mod/modfile"

"github.com/grafana/thema"
"github.com/grafana/thema/encoding/gocode"
"github.com/grafana/thema/encoding/jsonschema"
"github.com/grafana/thema/encoding/openapi"
"github.com/spf13/cobra"
"golang.org/x/mod/modfile"
)

type genCommand struct {
Expand Down Expand Up @@ -309,6 +310,11 @@ func (gc *genCommand) runGoBindings(cmd *cobra.Command, args []string) error {
TargetSchemaVersion: gc.sch.Version(),
PackageName: gc.pkgname,
}

if gc.lla.lincuepath != "" {
cfg.CuePath = cue.ParsePath(gc.lla.lincuepath)
}

// emitting on stdout just skips all the complicated conditional gen bits
if !gc.stdout {
if !gc.noembed {
Expand Down
3 changes: 2 additions & 1 deletion encoding/gocode/binding.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import (
"io/fs"
"path/filepath"

"cuelang.org/go/cue/build"
"cuelang.org/go/cue"
"cuelang.org/go/cue/build"
"github.com/grafana/thema"
"github.com/grafana/thema/load"
)
Expand Down
5 changes: 3 additions & 2 deletions encoding/gocode/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ import (
"github.com/dave/dst/decorator"
"github.com/dave/dst/dstutil"
"github.com/getkin/kin-openapi/openapi3"
"golang.org/x/tools/imports"

"github.com/grafana/thema"
"github.com/grafana/thema/encoding/openapi"
"github.com/grafana/thema/internal/deepmap/oapi-codegen/pkg/codegen"
"github.com/grafana/thema/internal/util"
"golang.org/x/tools/imports"
)

// All the parsed templates in the tmpl subdirectory
Expand Down Expand Up @@ -306,7 +307,7 @@ func GenerateLineageBinding(lin thema.Lineage, cfg *BindingConfig) ([]byte, erro
CueModName: cfg.CueModName,
LoadDir: cfg.LoadDir,
EmbedPath: cfg.EmbedPath,
CUEPath: cfg.CuePath.String(),
CUEPath: fmt.Sprintf("%q", cfg.CuePath.String()),
BaseFactoryFuncName: "Lineage",
FactoryFuncName: "Lineage",
IsConvergent: cfg.Assignee != nil,
Expand Down

0 comments on commit da9fe56

Please sign in to comment.