Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module github.com/grafana/cog

go 1.23.0
go 1.24.0

toolchain go1.23.6
toolchain go1.24.4

require (
cuelang.org/go v0.11.0
github.com/expr-lang/expr v1.17.6
github.com/getkin/kin-openapi v0.128.0
github.com/getkin/kin-openapi v0.133.0
github.com/google/go-cmp v0.7.0
github.com/grafana/codejen v0.0.4-0.20230321061741-77f656893a3d
github.com/huandu/xstrings v1.5.0
Expand All @@ -16,9 +16,9 @@ require (
github.com/spf13/cobra v1.10.1
github.com/stretchr/testify v1.11.1
github.com/yalue/merged_fs v1.3.0
golang.org/x/mod v0.27.0
golang.org/x/text v0.28.0
golang.org/x/tools v0.36.0
golang.org/x/mod v0.28.0
golang.org/x/text v0.29.0
golang.org/x/tools v0.37.0
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -35,11 +35,12 @@ require (
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/invopop/yaml v0.3.1 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037 // indirect
github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
Expand All @@ -49,7 +50,8 @@ require (
github.com/rogpeppe/go-internal v1.13.1 // indirect
github.com/spf13/pflag v1.0.9 // indirect
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
golang.org/x/net v0.43.0 // indirect
golang.org/x/oauth2 v0.24.0 // indirect
golang.org/x/sync v0.16.0 // indirect
github.com/woodsbury/decimal128 v1.3.0 // indirect
golang.org/x/net v0.44.0 // indirect
golang.org/x/oauth2 v0.27.0 // indirect
golang.org/x/sync v0.17.0 // indirect
)
38 changes: 22 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ github.com/emicklei/proto v1.13.2 h1:z/etSFO3uyXeuEsVPzfl56WNgzcvIr42aQazXaQmFZY
github.com/emicklei/proto v1.13.2/go.mod h1:rn1FgRS/FANiZdD2djyH7TMA9jdRDcYQ9IEN9yvjX0A=
github.com/expr-lang/expr v1.17.6 h1:1h6i8ONk9cexhDmowO/A64VPxHScu7qfSl2k8OlINec=
github.com/expr-lang/expr v1.17.6/go.mod h1:8/vRC7+7HBzESEqt5kKpYXxrxkr31SaO8r40VO/1IT4=
github.com/getkin/kin-openapi v0.128.0 h1:jqq3D9vC9pPq1dGcOCv7yOp1DaEe7c/T1vzcLbITSp4=
github.com/getkin/kin-openapi v0.128.0/go.mod h1:OZrfXzUfGrNbsKj+xmFBx6E5c6yH3At/tAKSc2UszXM=
github.com/getkin/kin-openapi v0.133.0 h1:pJdmNohVIJ97r4AUFtEXRXwESr8b0bD721u/Tz6k8PQ=
github.com/getkin/kin-openapi v0.133.0/go.mod h1:boAciF6cXk5FhPqe/NQeBTeenbjqU4LhWBf09ILVvWE=
github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ=
github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY=
github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE=
Expand All @@ -42,8 +42,6 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/invopop/jsonschema v0.13.0 h1:KvpoAJWEjR3uD9Kbm2HWJmqsEaHt8lBUpd0qHcIi21E=
github.com/invopop/jsonschema v0.13.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uON45H2qjYt+0=
github.com/invopop/yaml v0.3.1 h1:f0+ZpmhfBSS4MhG+4HYseMdJhoeeopbSKbq5Rpeelso=
github.com/invopop/yaml v0.3.1/go.mod h1:PMOp3nn4/12yEZUFfmOuNHJsZToEEOwoWsT+D81KkeA=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
Expand All @@ -60,6 +58,10 @@ github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQ
github.com/mitchellh/go-wordwrap v1.0.1/go.mod h1:R62XHJLzvMFRBbcrT7m7WgmE1eOyTSsCt+hzestvNj0=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037 h1:G7ERwszslrBzRxj//JalHPu/3yz+De2J+4aLtSRlHiY=
github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037/go.mod h1:2bpvgLBZEtENV5scfDFEtB/5+1M4hkQhDQrccEJ/qGw=
github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90 h1:bQx3WeLcUWy+RletIKwUIt4x3t8n2SxavmoclizMb8c=
github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90/go.mod h1:y5+oSEHCPT/DGrS++Wc/479ERge0zTFxaF8PbGKcg2o=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0 h1:8SG7/vwALn54lVB/0yZ/MMwhFrPYtpEHQb2IpWsCzug=
Expand Down Expand Up @@ -87,22 +89,26 @@ github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
github.com/wk8/go-ordered-map/v2 v2.1.8 h1:5h/BUHu93oj4gIdvHHHGsScSTMijfx5PeYkE/fJgbpc=
github.com/wk8/go-ordered-map/v2 v2.1.8/go.mod h1:5nJHM5DyteebpVlHnWMV0rPz6Zp7+xBAnxjb1X5vnTw=
github.com/woodsbury/decimal128 v1.3.0 h1:8pffMNWIlC0O5vbyHWFZAt5yWvWcrHA+3ovIIjVWss0=
github.com/woodsbury/decimal128 v1.3.0/go.mod h1:C5UTmyTjW3JftjUFzOVhC20BEQa2a4ZKOB5I6Zjb+ds=
github.com/yalue/merged_fs v1.3.0 h1:qCeh9tMPNy/i8cwDsQTJ5bLr6IRxbs6meakNE5O+wyY=
github.com/yalue/merged_fs v1.3.0/go.mod h1:WqqchfVYQyclV2tnR7wtRhBddzBvLVR83Cjw9BKQw0M=
golang.org/x/mod v0.27.0 h1:kb+q2PyFnEADO2IEF935ehFUXlWiNjJWtRNgBLSfbxQ=
golang.org/x/mod v0.27.0/go.mod h1:rWI627Fq0DEoudcK+MBkNkCe0EetEaDSwJJkCcjpazc=
golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg=
golang.org/x/mod v0.28.0 h1:gQBtGhjxykdjY9YhZpSlZIsbnaE2+PgjfLWUQTnoZ1U=
golang.org/x/mod v0.28.0/go.mod h1:yfB/L0NOf/kmEbXjzCPOx1iK1fRutOydrCMsqRhEBxI=
golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I=
golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY=
golang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE=
golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
golang.org/x/tools v0.36.0 h1:kWS0uv/zsvHEle1LbV5LE8QujrxB3wfQyxHfhOk0Qkg=
golang.org/x/tools v0.36.0/go.mod h1:WBDiHKJK8YgLHlcQPYQzNCkUxUypCaa5ZegCVutKm+s=
golang.org/x/oauth2 v0.27.0 h1:da9Vo7/tDv5RH/7nZDz1eMGS/q1Vv1N/7FCrBhI9I3M=
golang.org/x/oauth2 v0.27.0/go.mod h1:onh5ek6nERTohokkhCD/y2cV4Do3fxFHFuAejCkRWT8=
golang.org/x/sync v0.17.0 h1:l60nONMj9l5drqw6jlhIELNv9I0A4OFgRsG9k2oT9Ug=
golang.org/x/sync v0.17.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
golang.org/x/tools v0.37.0 h1:DVSRzp7FwePZW356yEAChSdNcQo6Nsp+fex1SUW09lE=
golang.org/x/tools v0.37.0/go.mod h1:MBN5QPQtLMHVdvsbtarmTNukZDdgwdwlO5qGacAzF0w=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
4 changes: 2 additions & 2 deletions internal/codegen/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/grafana/cog/internal/languages"
"github.com/grafana/cog/internal/veneers/rewrite"
cogyaml "github.com/grafana/cog/internal/yaml"
"gopkg.in/yaml.v3"
yamlv3 "gopkg.in/yaml.v3"
)

type ParametersInterpolator func(input string) string
Expand Down Expand Up @@ -48,7 +48,7 @@ func PipelineFromFile(file string, opts ...PipelineOption) (*Pipeline, error) {
}
defer func() { _ = fileHandle.Close() }()

decoder := yaml.NewDecoder(fileHandle)
decoder := yamlv3.NewDecoder(fileHandle)
decoder.KnownFields(true)

pipeline, err := NewPipeline()
Expand Down
4 changes: 1 addition & 3 deletions internal/jennies/common/codejen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ func (jenny fakeNamedJenny) JennyName() string {
func TestPrefixer(t *testing.T) {
req := require.New(t)
fileContent := []byte("with content")
inputFile := codejen.NewFile("some.file", fileContent)

resultFile, err := PathPrefixer("/the/prefix")(*inputFile)
resultFile, err := PathPrefixer("/the/prefix")(*codejen.NewFile("some.file", fileContent))
req.NoError(err)

req.Equal("/the/prefix/some.file", resultFile.RelativePath)
Expand Down
2 changes: 1 addition & 1 deletion internal/jennies/golang/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestBuilder_Generate(t *testing.T) {

test.Run(t, func(tc *testutils.Test[languages.Context]) {
var err error
req := require.New(tc)
req := require.New(tc.T)

context := tc.UnmarshalJSONInput(testutils.BuildersContextInputFile)
context, err = languages.GenerateBuilderNilChecks(language, context)
Expand Down
2 changes: 1 addition & 1 deletion internal/jennies/golang/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestConverter_Generate(t *testing.T) {

test.Run(t, func(tc *testutils.Test[languages.Context]) {
var err error
req := require.New(tc)
req := require.New(tc.T)

context := tc.UnmarshalJSONInput(testutils.BuildersContextInputFile)
context, err = languages.GenerateBuilderNilChecks(language, context)
Expand Down
2 changes: 1 addition & 1 deletion internal/jennies/golang/rawtypes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestRawTypes_Generate(t *testing.T) {
compilerPasses := New(config).CompilerPasses()

test.Run(t, func(tc *testutils.Test[ast.Schema]) {
req := require.New(tc)
req := require.New(tc.T)

// We run the compiler passes defined fo Go since without them, we
// might not be able to translate some of the IR's semantics into Go.
Expand Down
2 changes: 1 addition & 1 deletion internal/jennies/java/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestBuilder_Generate(t *testing.T) {

test.Run(t, func(tc *testutils.Test[languages.Context]) {
var err error
req := require.New(tc)
req := require.New(tc.T)

context := tc.UnmarshalJSONInput(testutils.BuildersContextInputFile)
context, err = languages.GenerateBuilderNilChecks(language, context)
Expand Down
2 changes: 1 addition & 1 deletion internal/jennies/java/deserializers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestDeserializers_Generate(t *testing.T) {
compilerPasses := New(cfg).CompilerPasses()

test.Run(t, func(tc *testutils.Test[ast.Schema]) {
req := require.New(tc)
req := require.New(tc.T)

// We run the compiler passes defined fo Java since without them, we
// might not be able to translate some of the IR's semantics into Java.
Expand Down
2 changes: 1 addition & 1 deletion internal/jennies/java/rawtypes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestRawTypes_Generate(t *testing.T) {
compilerPasses := New(cfg).CompilerPasses()

test.Run(t, func(tc *testutils.Test[ast.Schema]) {
req := require.New(tc)
req := require.New(tc.T)

// We run the compiler passes defined fo Java since without them, we
// might not be able to translate some of the IR's semantics into Java.
Expand Down
2 changes: 1 addition & 1 deletion internal/jennies/java/serializers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestSerializers_Generate(t *testing.T) {
compilerPasses := New(cfg).CompilerPasses()

test.Run(t, func(tc *testutils.Test[ast.Schema]) {
req := require.New(tc)
req := require.New(tc.T)

// We run the compiler passes defined fo Java since without them, we
// might not be able to translate some of the IR's semantics into Java.
Expand Down
2 changes: 1 addition & 1 deletion internal/jennies/jsonschema/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestSchema_Generate(t *testing.T) {
compilerPasses := New(config).CompilerPasses()

test.Run(t, func(tc *testutils.Test[ast.Schema]) {
req := require.New(tc)
req := require.New(tc.T)

// We run the compiler passes defined fo JSONSchema since without them, we
// might not be able to translate some of the IR's semantics.
Expand Down
2 changes: 1 addition & 1 deletion internal/jennies/openapi/schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestSchema_Generate(t *testing.T) {
compilerPasses := New(config).CompilerPasses()

test.Run(t, func(tc *testutils.Test[ast.Schema]) {
req := require.New(tc)
req := require.New(tc.T)

// We run the compiler passes defined fo OpenAPI since without them, we
// might not be able to translate some of the IR's semantics.
Expand Down
2 changes: 1 addition & 1 deletion internal/jennies/php/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestBuilder_Generate(t *testing.T) {

test.Run(t, func(tc *testutils.Test[languages.Context]) {
var err error
req := require.New(tc)
req := require.New(tc.T)

context := tc.UnmarshalJSONInput(testutils.BuildersContextInputFile)
context, err = languages.GenerateBuilderNilChecks(language, context)
Expand Down
2 changes: 1 addition & 1 deletion internal/jennies/php/converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestConverter_Generate(t *testing.T) {

test.Run(t, func(tc *testutils.Test[languages.Context]) {
var err error
req := require.New(tc)
req := require.New(tc.T)

context := tc.UnmarshalJSONInput(testutils.BuildersContextInputFile)
context, err = languages.GenerateBuilderNilChecks(language, context)
Expand Down
2 changes: 1 addition & 1 deletion internal/jennies/php/rawtypes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestRawTypes_Generate(t *testing.T) {
compilerPasses := New(config).CompilerPasses()

test.Run(t, func(tc *testutils.Test[ast.Schema]) {
req := require.New(tc)
req := require.New(tc.T)

// We run the compiler passes defined fo Go since without them, we
// might not be able to translate some of the IR's semantics into Go.
Expand Down
2 changes: 1 addition & 1 deletion internal/jennies/python/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestBuilder_Generate(t *testing.T) {

test.Run(t, func(tc *testutils.Test[languages.Context]) {
var err error
req := require.New(tc)
req := require.New(tc.T)

context := tc.UnmarshalJSONInput(testutils.BuildersContextInputFile)
context, err = languages.GenerateBuilderNilChecks(language, context)
Expand Down
2 changes: 1 addition & 1 deletion internal/jennies/python/rawtypes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestRawTypes_Generate(t *testing.T) {
compilerPasses := New(config).CompilerPasses()

test.Run(t, func(tc *testutils.Test[ast.Schema]) {
req := require.New(tc)
req := require.New(tc.T)

// We run the compiler passes defined fo Python since without them, we
// might not be able to translate some of the IR's semantics into Python.
Expand Down
11 changes: 8 additions & 3 deletions internal/jennies/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ const recursionMaxNums = 1000
type FuncMap gotemplate.FuncMap

func (funcMap FuncMap) MergeWith(other FuncMap) FuncMap {
for k, v := range other {
funcMap[k] = v
fm := gotemplate.FuncMap(funcMap)
for k, v := range gotemplate.FuncMap(other) {
fm[k] = v
}

return funcMap
return FuncMap(fm)
}

type Option func(*Template) error
Expand Down Expand Up @@ -246,6 +247,8 @@ func (template *Template) builtins() FuncMap {
default:
panic(fmt.Sprintf("Cannot find first on type %s", tp))
}

return nil
},
"last": func(list any) any {
tp := reflect.TypeOf(list).Kind()
Expand All @@ -259,6 +262,8 @@ func (template *Template) builtins() FuncMap {
default:
panic(fmt.Sprintf("Cannot find first on type %s", tp))
}

return nil
},

"slice": func(arr interface{}, start int) interface{} {
Expand Down
2 changes: 1 addition & 1 deletion internal/jennies/typescript/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestBuilder_Generate(t *testing.T) {

test.Run(t, func(tc *testutils.Test[languages.Context]) {
var err error
req := require.New(tc)
req := require.New(tc.T)

context := tc.UnmarshalJSONInput(testutils.BuildersContextInputFile)
context, err = languages.GenerateBuilderNilChecks(language, context)
Expand Down
2 changes: 1 addition & 1 deletion internal/jennies/typescript/rawtypes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestRawTypes_Generate(t *testing.T) {
compilerPasses := New(config).CompilerPasses()

test.Run(t, func(tc *testutils.Test[ast.Schema]) {
req := require.New(tc)
req := require.New(tc.T)

// We run the compiler passes defined fo Go since without them, we
// might not be able to translate some of the IR's semantics into TS.
Expand Down
2 changes: 1 addition & 1 deletion internal/jsonschema/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestGenerateAST(t *testing.T) {
}

test.Run(t, func(tc *testutils.Test[string]) {
req := require.New(tc)
req := require.New(tc.T)

schemaAst, err := GenerateAST(tc.OpenInput("schema.json"), Config{Package: "grafanatest"})
req.NoError(err)
Expand Down
12 changes: 6 additions & 6 deletions internal/languages/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ type Converter struct {

func (converter Converter) inputRootPath() ast.Path {
return ast.Path{
{
ast.PathItem{
Identifier: converter.Input.ArgName,
Type: converter.Input.TypeRef.AsType(),
Root: true,
Expand Down Expand Up @@ -283,20 +283,20 @@ func (generator *ConverterGenerator) mappingForOption(context Context, converter
if mapping.RepeatFor != nil && valueType.IsArray() {
valueType = valueType.AsArray().ValueType
valuePath = ast.Path{
{Identifier: mapping.RepeatAs, Type: valueType, Root: true},
ast.PathItem{Identifier: mapping.RepeatAs, Type: valueType, Root: true},
}
} else if mapping.RepeatFor != nil && assignment.Method == ast.IndexAssignment {
// index
indexPath := ast.Path{
{Identifier: mapping.RepeatIndex, Type: valueType, Root: true},
ast.PathItem{Identifier: mapping.RepeatIndex, Type: valueType, Root: true},
}
indexType := assignment.Path.Last().Index.Argument.Type
argument := generator.argumentForType(context, converter, mapping.RepeatIndex, indexPath, indexType)
optMapping.Args = append(optMapping.Args, argument)
// If it isn't a disjunction, we have to put the value in the second argument
// value
valuePath = ast.Path{
{Identifier: mapping.RepeatAs, Type: valueType, Root: true},
ast.PathItem{Identifier: mapping.RepeatAs, Type: valueType, Root: true},
}
if !generator.isAssignmentFromDisjunctionStruct(context, assignment) {
argument = generator.argumentForType(context, converter, argName, valuePath, valueType)
Expand Down Expand Up @@ -366,7 +366,7 @@ func (generator *ConverterGenerator) argumentForType(context Context, converter

if typeDef.IsArray() {
valueAs := ast.Path{
{Identifier: argName, Type: typeDef.Array.ValueType, Root: true},
ast.PathItem{Identifier: argName, Type: typeDef.Array.ValueType, Root: true},
}

forArg := generator.argumentForType(context, converter, argName+"Value", valueAs, typeDef.Array.ValueType)
Expand All @@ -384,7 +384,7 @@ func (generator *ConverterGenerator) argumentForType(context Context, converter

if typeDef.IsMap() {
valueAs := ast.Path{
{Identifier: argName, Type: typeDef.Map.ValueType, Root: true},
ast.PathItem{Identifier: argName, Type: typeDef.Map.ValueType, Root: true},
}

forArg := generator.argumentForType(context, converter, argName+"Value", valueAs, typeDef.Map.ValueType)
Expand Down
Loading
Loading