diff --git a/lang/lang.go b/lang/lang.go index 1706765..90a1a33 100644 --- a/lang/lang.go +++ b/lang/lang.go @@ -14,6 +14,22 @@ package lang +// Ptr returns a pointer to the value passed in. func Ptr[T any](t T) *T { return &t } + +// ValOrZero returns the value of the pointer passed in or the zero value of the +// type if the pointer is nil. +func ValOrZero[T any](t *T) T { + if t == nil { + return Zero[T]() + } + return *t +} + +// Zero returns the zero value of the type passed in. +func Zero[T any]() T { + var t T + return t +} diff --git a/paramgen/main.go b/paramgen/main.go index b0053a9..f9c3f41 100644 --- a/paramgen/main.go +++ b/paramgen/main.go @@ -21,7 +21,7 @@ import ( "os" "strings" - "github.com/conduitio/conduit-commons/paramgen/internal" + "github.com/conduitio/conduit-commons/paramgen/paramgen" ) func main() { @@ -32,12 +32,12 @@ func main() { args := parseFlags() // parse the sdk parameters - params, pkg, err := internal.ParseParameters(args.path, args.structName) + params, pkg, err := paramgen.ParseParameters(args.path, args.structName) if err != nil { log.Fatalf("error: failed to parse parameters: %v", err) } - code := internal.GenerateCode(params, pkg, args.structName) + code := paramgen.GenerateCode(params, pkg, args.structName) path := strings.TrimSuffix(args.path, "/") + "/" + args.output err = os.WriteFile(path, []byte(code), 0o600) diff --git a/paramgen/internal/integration_test.go b/paramgen/paramgen/integration_test.go similarity index 91% rename from paramgen/internal/integration_test.go rename to paramgen/paramgen/integration_test.go index c3d906e..443128b 100644 --- a/paramgen/internal/integration_test.go +++ b/paramgen/paramgen/integration_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package internal +package paramgen import ( "os" @@ -39,6 +39,10 @@ func TestIntegration(t *testing.T) { havePath: "./testdata/tags", structName: "Config", wantPath: "./testdata/tags/want.go", + }, { + havePath: "./testdata/dependencies", + structName: "Config", + wantPath: "./testdata/dependencies/want.go", }} for _, tc := range testCases { diff --git a/paramgen/internal/paramgen.go b/paramgen/paramgen/paramgen.go similarity index 82% rename from paramgen/internal/paramgen.go rename to paramgen/paramgen/paramgen.go index a5fd573..796d737 100644 --- a/paramgen/internal/paramgen.go +++ b/paramgen/paramgen/paramgen.go @@ -13,7 +13,7 @@ // limitations under the License. //nolint:err113,wrapcheck,staticcheck // we don't care about wrapping errors here, also ignore usage of ast.Package (deprecated) -package internal +package paramgen import ( "encoding/json" @@ -21,6 +21,7 @@ import ( "go/ast" "go/parser" "go/token" + "io" "io/fs" "os/exec" "reflect" @@ -115,31 +116,34 @@ func parsePackage(path string) (*ast.Package, error) { filterTests := func(info fs.FileInfo) bool { return !strings.HasSuffix(info.Name(), "_test.go") } - pkgs, err := parser.ParseDir(fset, path, filterTests, parser.ParseComments) + pkgs, err := parser.ParseDir(fset, path, filterTests, parser.ParseComments|parser.SkipObjectResolution) if err != nil { return nil, fmt.Errorf("couldn't parse directory %s: %w", path, err) } - // Make sure they are all in one package. - if len(pkgs) == 0 { - return nil, fmt.Errorf("no source-code package in directory %s", path) - } - // Ignore files with go:build constraint set to "tools" (common pattern in - // Conduit connectors). for pkgName, pkg := range pkgs { + // Ignore files with go:build constraint set to "tools" (common pattern in + // Conduit connectors). maps.DeleteFunc(pkg.Files, func(_ string, f *ast.File) bool { return hasBuildConstraint(f, "tools") }) - if len(pkg.Files) == 0 { + // Remove empty packages or the main package (can't be imported). + if len(pkg.Files) == 0 || pkgName == "main" { delete(pkgs, pkgName) } } - if len(pkgs) > 1 { + + // Make sure there is only 1 package. + switch len(pkgs) { + case 0: + return nil, fmt.Errorf("no source-code package in directory %s", path) + case 1: + for _, pkg := range pkgs { + return pkg, nil + } + panic("unreachable") + default: return nil, fmt.Errorf("multiple packages %v in directory %s", maps.Keys(pkgs), path) } - for _, v := range pkgs { - return v, nil // return first package - } - panic("unreachable") } // hasBuildConstraint is a very naive way to check if a file has a build @@ -205,6 +209,10 @@ func (p *parameterParser) Parse(structType *ast.StructType) (map[string]config.P } func (p *parameterParser) parseIdent(ident *ast.Ident, field *ast.Field) (params map[string]config.Parameter, err error) { + if field != nil && p.shouldSkipField(field) { + return nil, nil //nolint:nilnil // ignore this validation + } + defer func() { if err != nil { err = fmt.Errorf("[parseIdent] %w", err) @@ -252,6 +260,10 @@ func (p *parameterParser) parseIdent(ident *ast.Ident, field *ast.Field) (params } func (p *parameterParser) parseTypeSpec(ts *ast.TypeSpec, f *ast.Field) (params map[string]config.Parameter, err error) { + if f != nil && p.shouldSkipField(f) { + return nil, nil //nolint:nilnil // ignore this validation + } + defer func() { if err != nil { err = fmt.Errorf("[parseTypeSpec] %w", err) @@ -267,12 +279,18 @@ func (p *parameterParser) parseTypeSpec(ts *ast.TypeSpec, f *ast.Field) (params return p.parseIdent(v, f) case *ast.MapType: return p.parseMapType(v, f) + case *ast.InterfaceType: + return nil, fmt.Errorf("error parsing type spec for %s.%s.%s: interface types not supported", p.pkg.Name, ts.Name.Name, p.getFieldNameOrUnknown(f)) default: return nil, fmt.Errorf("unexpected type: %T", ts.Type) } } func (p *parameterParser) parseStructType(st *ast.StructType, f *ast.Field) (params map[string]config.Parameter, err error) { + if f != nil && p.shouldSkipField(f) { + return nil, nil //nolint:nilnil // ignore this validation + } + defer func() { if err != nil { err = fmt.Errorf("[parseStructType] %w", err) @@ -303,6 +321,10 @@ func (p *parameterParser) parseStructType(st *ast.StructType, f *ast.Field) (par } func (p *parameterParser) parseField(f *ast.Field) (params map[string]config.Parameter, err error) { + if f != nil && p.shouldSkipField(f) { + return nil, nil //nolint:nilnil // ignore this validation + } + defer func() { if err != nil { err = fmt.Errorf("[parseField] %w", err) @@ -313,34 +335,45 @@ func (p *parameterParser) parseField(f *ast.Field) (params map[string]config.Par return nil, nil //nolint:nilnil // ignore unexported fields } - switch v := f.Type.(type) { - case *ast.Ident: - // identifier (builtin type or type in same package) - return p.parseIdent(v, f) - case *ast.StructType: - // nested type - return p.parseStructType(v, f) - case *ast.SelectorExpr: - return p.parseSelectorExpr(v, f) - case *ast.MapType: - return p.parseMapType(v, f) - case *ast.ArrayType: - strType := fmt.Sprintf("%s", v.Elt) - if !p.isBuiltinType(strType) && !strings.Contains(strType, "time Duration") { - return nil, fmt.Errorf("unsupported slice type: %s", strType) - } + expr := f.Type + for { + switch v := expr.(type) { + case *ast.StarExpr: + // dereference pointer + expr = v.X + continue + case *ast.Ident: + // identifier (builtin type or type in same package) + return p.parseIdent(v, f) + case *ast.StructType: + // nested type + return p.parseStructType(v, f) + case *ast.SelectorExpr: + return p.parseSelectorExpr(v, f) + case *ast.MapType: + return p.parseMapType(v, f) + case *ast.ArrayType: + strType := fmt.Sprintf("%s", v.Elt) + if !p.isBuiltinType(strType) && !strings.Contains(strType, "time Duration") { + return nil, fmt.Errorf("unsupported slice type: %s", strType) + } - name, param, err := p.parseSingleParameter(f, config.ParameterTypeString) - if err != nil { - return nil, err + name, param, err := p.parseSingleParameter(f, config.ParameterTypeString) + if err != nil { + return nil, err + } + return map[string]config.Parameter{name: param}, nil + default: + return nil, fmt.Errorf("unknown type: %T", f.Type) } - return map[string]config.Parameter{name: param}, nil - default: - return nil, fmt.Errorf("unknown type: %T", f.Type) } } func (p *parameterParser) parseMapType(mt *ast.MapType, f *ast.Field) (params map[string]config.Parameter, err error) { + if f != nil && p.shouldSkipField(f) { + return nil, nil //nolint:nilnil // ignore this validation + } + if fmt.Sprintf("%s", mt.Key) != "string" { return nil, fmt.Errorf("unsupported map key type: %s", mt.Key) } @@ -378,6 +411,10 @@ func (p *parameterParser) parseMapType(mt *ast.MapType, f *ast.Field) (params ma } func (p *parameterParser) parseSelectorExpr(se *ast.SelectorExpr, f *ast.Field) (params map[string]config.Parameter, err error) { + if f != nil && p.shouldSkipField(f) { + return nil, nil //nolint:nilnil // ignore this validation + } + defer func() { if err != nil { err = fmt.Errorf("[parseSelectorExpr] %w", err) @@ -428,17 +465,21 @@ func (p *parameterParser) findPackage(importPath string) (*ast.Package, error) { // first cleanup string importPath = strings.Trim(importPath, `"`) - if !strings.HasPrefix(importPath, p.mod.Path) { - // we only allow types declared in the same module - return nil, fmt.Errorf("we do not support parameters from package %v (please use builtin types or time.Duration)", importPath) - } - if pkg, ok := p.imports[importPath]; ok { // it's cached already return pkg, nil } pkgDir := p.mod.Dir + strings.TrimPrefix(importPath, p.mod.Path) + if !strings.HasPrefix(importPath, p.mod.Path) { + // Import path is not part of the module, we need to find the package path + var err error + pkgDir, err = p.packageToPath(importPath) + if err != nil { + return nil, fmt.Errorf("could not get package path for %q: %w", importPath, err) + } + } + pkg, err := parsePackage(pkgDir) if err != nil { return nil, fmt.Errorf("could not parse package dir %q: %w", pkgDir, err) @@ -514,6 +555,11 @@ func (p *parameterParser) attachPrefix(f *ast.Field, params map[string]config.Pa return prefixedParams } +func (p *parameterParser) shouldSkipField(f *ast.Field) bool { + val := p.getTag(f.Tag, tagParamName) + return val == "-" +} + func (p *parameterParser) isBuiltinType(name string) bool { switch name { case "string", "bool", "int", "uint", "int8", "uint8", "int16", "uint16", "int32", "uint32", "int64", "uint64", @@ -593,7 +639,7 @@ func (p *parameterParser) getParamType(i *ast.Ident) config.ParameterType { // lowercase letter. If the string starts with multiple uppercase letters, all // but the last character in the sequence will be converted into lowercase // letters (e.g. HTTPRequest -> httpRequest). -func (p *parameterParser) formatFieldName(name string) string { +func (*parameterParser) formatFieldName(name string) string { if name == "" { return "" } @@ -619,7 +665,7 @@ func (p *parameterParser) formatFieldName(name string) string { return newName } -func (p *parameterParser) formatFieldComment(f *ast.Field) string { +func (*parameterParser) formatFieldComment(f *ast.Field) string { doc := f.Doc if doc == nil { // fallback to line comment @@ -644,7 +690,7 @@ func (p *parameterParser) formatFieldComment(f *ast.Field) string { return c } -func (p *parameterParser) getTag(lit *ast.BasicLit, tag string) string { +func (*parameterParser) getTag(lit *ast.BasicLit, tag string) string { if lit == nil { return "" } @@ -671,7 +717,7 @@ func (p *parameterParser) parseValidateTag(tag string) ([]config.Validation, err return validations, nil } -func (p *parameterParser) parseValidation(str string) (config.Validation, error) { +func (*parameterParser) parseValidation(str string) (config.Validation, error) { if str == validationRequired { return config.ValidationRequired{}, nil } @@ -715,3 +761,33 @@ func (p *parameterParser) parseValidation(str string) (config.Validation, error) return nil, fmt.Errorf("invalid value for tag validate: %s", str) } } + +// packageToPath takes a package import path and returns the path to the directory +// of that package. +func (p *parameterParser) packageToPath(pkg string) (string, error) { + cmd := exec.Command("go", "list", "-f", "{{.Dir}}", pkg) + cmd.Dir = p.mod.Dir + stdout, err := cmd.StdoutPipe() + if err != nil { + return "", fmt.Errorf("error piping stdout of go list command: %w", err) + } + stderr, err := cmd.StderrPipe() + if err != nil { + return "", fmt.Errorf("error piping stderr of go list command: %w", err) + } + if err := cmd.Start(); err != nil { + return "", fmt.Errorf("error starting go list command: %w", err) + } + path, err := io.ReadAll(stdout) + if err != nil { + return "", fmt.Errorf("error reading stdout of go list command: %w", err) + } + errMsg, err := io.ReadAll(stderr) + if err != nil { + return "", fmt.Errorf("error reading stderr of go list command: %w", err) + } + if err := cmd.Wait(); err != nil { + return "", fmt.Errorf("error running command %q (error message: %q): %w", cmd.String(), errMsg, err) + } + return strings.TrimRight(string(path), "\n"), nil +} diff --git a/paramgen/internal/paramgen_test.go b/paramgen/paramgen/paramgen_test.go similarity index 94% rename from paramgen/internal/paramgen_test.go rename to paramgen/paramgen/paramgen_test.go index 9d71bed..fc9502d 100644 --- a/paramgen/internal/paramgen_test.go +++ b/paramgen/paramgen/paramgen_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package internal +package paramgen import ( "errors" @@ -23,7 +23,7 @@ import ( "github.com/matryer/is" ) -func TestParseSpecificationSuccess(t *testing.T) { +func TestParseParametersSuccess(t *testing.T) { testCases := []struct { path string name string @@ -79,6 +79,8 @@ func TestParseSpecificationSuccess(t *testing.T) { "myStringMap.*": {Type: config.ParameterTypeString}, "myStructMap.*.myInt": {Type: config.ParameterTypeInt}, "myStructMap.*.myString": {Type: config.ParameterTypeString}, + "myBoolPtr": {Type: config.ParameterTypeBool}, + "myDurationPtr": {Type: config.ParameterTypeDuration}, }, }, { @@ -170,7 +172,7 @@ func TestParseSpecificationSuccess(t *testing.T) { } } -func TestParseSpecificationFail(t *testing.T) { +func TestParseParametersFail(t *testing.T) { testCases := []struct { path string name string @@ -178,7 +180,7 @@ func TestParseSpecificationFail(t *testing.T) { }{{ path: "./testdata/invalid1", name: "SourceConfig", - wantErr: errors.New("we do not support parameters from package net/http (please use builtin types or time.Duration)"), + wantErr: errors.New("error parsing type spec for http.RoundTripper.Transport: interface types not supported"), }, { path: "./testdata/invalid2", name: "SourceConfig", diff --git a/paramgen/internal/template.go b/paramgen/paramgen/template.go similarity index 99% rename from paramgen/internal/template.go rename to paramgen/paramgen/template.go index fcf3c31..d330a80 100644 --- a/paramgen/internal/template.go +++ b/paramgen/paramgen/template.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package internal +package paramgen import ( "bytes" diff --git a/paramgen/internal/template_test.go b/paramgen/paramgen/template_test.go similarity index 99% rename from paramgen/internal/template_test.go rename to paramgen/paramgen/template_test.go index f4023b6..81e936c 100644 --- a/paramgen/internal/template_test.go +++ b/paramgen/paramgen/template_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package internal +package paramgen import ( "regexp" diff --git a/paramgen/internal/testdata/basic/go.mod b/paramgen/paramgen/testdata/basic/go.mod similarity index 100% rename from paramgen/internal/testdata/basic/go.mod rename to paramgen/paramgen/testdata/basic/go.mod diff --git a/paramgen/internal/testdata/basic/go.sum b/paramgen/paramgen/testdata/basic/go.sum similarity index 100% rename from paramgen/internal/testdata/basic/go.sum rename to paramgen/paramgen/testdata/basic/go.sum diff --git a/paramgen/internal/testdata/basic/specs.go b/paramgen/paramgen/testdata/basic/specs.go similarity index 91% rename from paramgen/internal/testdata/basic/specs.go rename to paramgen/paramgen/testdata/basic/specs.go index efed368..25858c7 100644 --- a/paramgen/internal/testdata/basic/specs.go +++ b/paramgen/paramgen/testdata/basic/specs.go @@ -61,6 +61,12 @@ type SourceConfig struct { MyStringMap map[string]string MyStructMap map[string]structMapVal + MyBoolPtr *bool + MyDurationPtr *time.Duration + + // this field is ignored because it contains the json tag "-" + IgnoredField bool `json:"-"` + // this field is ignored because it is not exported ignoreThis http.Client } diff --git a/paramgen/internal/testdata/basic/want.go b/paramgen/paramgen/testdata/basic/want.go similarity index 92% rename from paramgen/internal/testdata/basic/want.go rename to paramgen/paramgen/testdata/basic/want.go index c7970fb..3dd31f9 100644 --- a/paramgen/internal/testdata/basic/want.go +++ b/paramgen/paramgen/testdata/basic/want.go @@ -10,9 +10,11 @@ import ( const ( SourceConfigFoo = "foo" SourceConfigMyBool = "myBool" + SourceConfigMyBoolPtr = "myBoolPtr" SourceConfigMyByte = "myByte" SourceConfigMyDurSlice = "myDurSlice" SourceConfigMyDuration = "myDuration" + SourceConfigMyDurationPtr = "myDurationPtr" SourceConfigMyFloat32 = "myFloat32" SourceConfigMyFloat64 = "myFloat64" SourceConfigMyFloatSlice = "myFloatSlice" @@ -50,6 +52,12 @@ func (SourceConfig) Parameters() map[string]config.Parameter { Type: config.ParameterTypeBool, Validations: []config.Validation{}, }, + SourceConfigMyBoolPtr: { + Default: "", + Description: "", + Type: config.ParameterTypeBool, + Validations: []config.Validation{}, + }, SourceConfigMyByte: { Default: "", Description: "", @@ -68,6 +76,12 @@ func (SourceConfig) Parameters() map[string]config.Parameter { Type: config.ParameterTypeDuration, Validations: []config.Validation{}, }, + SourceConfigMyDurationPtr: { + Default: "", + Description: "", + Type: config.ParameterTypeDuration, + Validations: []config.Validation{}, + }, SourceConfigMyFloat32: { Default: "", Description: "", diff --git a/paramgen/internal/testdata/complex/global.go b/paramgen/paramgen/testdata/complex/global.go similarity index 96% rename from paramgen/internal/testdata/complex/global.go rename to paramgen/paramgen/testdata/complex/global.go index e0c6b9e..f4f6c85 100644 --- a/paramgen/internal/testdata/complex/global.go +++ b/paramgen/paramgen/testdata/complex/global.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// go:build ignoreBuildTags +//go:build ignoreBuildTags package example diff --git a/paramgen/internal/testdata/complex/go.mod b/paramgen/paramgen/testdata/complex/go.mod similarity index 100% rename from paramgen/internal/testdata/complex/go.mod rename to paramgen/paramgen/testdata/complex/go.mod diff --git a/paramgen/internal/testdata/complex/go.sum b/paramgen/paramgen/testdata/complex/go.sum similarity index 100% rename from paramgen/internal/testdata/complex/go.sum rename to paramgen/paramgen/testdata/complex/go.sum diff --git a/paramgen/internal/testdata/complex/internal/global.go b/paramgen/paramgen/testdata/complex/internal/global.go similarity index 100% rename from paramgen/internal/testdata/complex/internal/global.go rename to paramgen/paramgen/testdata/complex/internal/global.go diff --git a/paramgen/internal/testdata/complex/specs.go b/paramgen/paramgen/testdata/complex/specs.go similarity index 85% rename from paramgen/internal/testdata/complex/specs.go rename to paramgen/paramgen/testdata/complex/specs.go index a6aea79..67dfa31 100644 --- a/paramgen/internal/testdata/complex/specs.go +++ b/paramgen/paramgen/testdata/complex/specs.go @@ -16,6 +16,13 @@ package example import "time" +// DestinationConfig is ignored in tests, they only operate on SourceConfig. +type DestinationConfig struct { + // GlobalConfig parameters should be nested under "global". This comment + // should be ignored. + Global GlobalConfig `json:"global"` +} + type SourceConfig struct { // GlobalConfig parameters should be nested under "global". This comment // should be ignored. diff --git a/paramgen/internal/testdata/complex/specs_test.go b/paramgen/paramgen/testdata/complex/specs_test.go similarity index 100% rename from paramgen/internal/testdata/complex/specs_test.go rename to paramgen/paramgen/testdata/complex/specs_test.go diff --git a/paramgen/internal/testdata/complex/tools.go b/paramgen/paramgen/testdata/complex/tools.go similarity index 100% rename from paramgen/internal/testdata/complex/tools.go rename to paramgen/paramgen/testdata/complex/tools.go diff --git a/paramgen/internal/testdata/complex/want.go b/paramgen/paramgen/testdata/complex/want.go similarity index 100% rename from paramgen/internal/testdata/complex/want.go rename to paramgen/paramgen/testdata/complex/want.go diff --git a/paramgen/paramgen/testdata/dependencies/go.mod b/paramgen/paramgen/testdata/dependencies/go.mod new file mode 100644 index 0000000..a88abea --- /dev/null +++ b/paramgen/paramgen/testdata/dependencies/go.mod @@ -0,0 +1,16 @@ +module example.com/test2 + +go 1.22.4 + +require ( + github.com/conduitio/conduit-commons v0.3.0 + example.com/test v0.0.0 +) + +require ( + github.com/goccy/go-json v0.10.3 // indirect + github.com/mitchellh/mapstructure v1.5.0 // indirect + google.golang.org/protobuf v1.34.2 // indirect +) + +replace example.com/test => ../basic \ No newline at end of file diff --git a/paramgen/paramgen/testdata/dependencies/go.sum b/paramgen/paramgen/testdata/dependencies/go.sum new file mode 100644 index 0000000..6342c6f --- /dev/null +++ b/paramgen/paramgen/testdata/dependencies/go.sum @@ -0,0 +1,4 @@ +github.com/conduitio/conduit-commons v0.3.0/go.mod h1:roxZ88dv+fpbEjjTzkdGwwbmcpunSuiD8he43y0lAoo= +github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= +github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= diff --git a/paramgen/paramgen/testdata/dependencies/specs.go b/paramgen/paramgen/testdata/dependencies/specs.go new file mode 100644 index 0000000..c3c16a6 --- /dev/null +++ b/paramgen/paramgen/testdata/dependencies/specs.go @@ -0,0 +1,24 @@ +// Copyright © 2023 Meroxa, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package dependencies + +import ( + example "example.com/test" +) + +// Config is a reusable config struct used in the source and destination +type Config struct { + example.SourceConfig +} diff --git a/paramgen/paramgen/testdata/dependencies/want.go b/paramgen/paramgen/testdata/dependencies/want.go new file mode 100644 index 0000000..1ded40c --- /dev/null +++ b/paramgen/paramgen/testdata/dependencies/want.go @@ -0,0 +1,203 @@ +// Code generated by paramgen. DO NOT EDIT. +// Source: github.com/ConduitIO/conduit-commons/tree/main/paramgen + +package dependencies + +import ( + "github.com/conduitio/conduit-commons/config" +) + +const ( + ConfigFoo = "foo" + ConfigMyBool = "myBool" + ConfigMyBoolPtr = "myBoolPtr" + ConfigMyByte = "myByte" + ConfigMyDurSlice = "myDurSlice" + ConfigMyDuration = "myDuration" + ConfigMyDurationPtr = "myDurationPtr" + ConfigMyFloat32 = "myFloat32" + ConfigMyFloat64 = "myFloat64" + ConfigMyFloatSlice = "myFloatSlice" + ConfigMyInt = "myInt" + ConfigMyInt16 = "myInt16" + ConfigMyInt32 = "myInt32" + ConfigMyInt64 = "myInt64" + ConfigMyInt8 = "myInt8" + ConfigMyIntSlice = "myIntSlice" + ConfigMyRune = "myRune" + ConfigMyString = "myString" + ConfigMyStringMap = "myStringMap.*" + ConfigMyStructMapMyInt = "myStructMap.*.myInt" + ConfigMyStructMapMyString = "myStructMap.*.myString" + ConfigMyUint = "myUint" + ConfigMyUint16 = "myUint16" + ConfigMyUint32 = "myUint32" + ConfigMyUint64 = "myUint64" + ConfigMyUint8 = "myUint8" +) + +func (Config) Parameters() map[string]config.Parameter { + return map[string]config.Parameter{ + ConfigFoo: { + Default: "bar", + Description: "MyGlobalString is a required field in the global config with the name\n\"foo\" and default value \"bar\".", + Type: config.ParameterTypeString, + Validations: []config.Validation{ + config.ValidationRequired{}, + }, + }, + ConfigMyBool: { + Default: "", + Description: "", + Type: config.ParameterTypeBool, + Validations: []config.Validation{}, + }, + ConfigMyBoolPtr: { + Default: "", + Description: "", + Type: config.ParameterTypeBool, + Validations: []config.Validation{}, + }, + ConfigMyByte: { + Default: "", + Description: "", + Type: config.ParameterTypeString, + Validations: []config.Validation{}, + }, + ConfigMyDurSlice: { + Default: "", + Description: "", + Type: config.ParameterTypeString, + Validations: []config.Validation{}, + }, + ConfigMyDuration: { + Default: "", + Description: "", + Type: config.ParameterTypeDuration, + Validations: []config.Validation{}, + }, + ConfigMyDurationPtr: { + Default: "", + Description: "", + Type: config.ParameterTypeDuration, + Validations: []config.Validation{}, + }, + ConfigMyFloat32: { + Default: "", + Description: "", + Type: config.ParameterTypeFloat, + Validations: []config.Validation{}, + }, + ConfigMyFloat64: { + Default: "", + Description: "", + Type: config.ParameterTypeFloat, + Validations: []config.Validation{}, + }, + ConfigMyFloatSlice: { + Default: "", + Description: "", + Type: config.ParameterTypeString, + Validations: []config.Validation{}, + }, + ConfigMyInt: { + Default: "", + Description: "", + Type: config.ParameterTypeInt, + Validations: []config.Validation{ + config.ValidationLessThan{V: 100}, + config.ValidationGreaterThan{V: 0}, + }, + }, + ConfigMyInt16: { + Default: "", + Description: "", + Type: config.ParameterTypeInt, + Validations: []config.Validation{}, + }, + ConfigMyInt32: { + Default: "", + Description: "", + Type: config.ParameterTypeInt, + Validations: []config.Validation{}, + }, + ConfigMyInt64: { + Default: "", + Description: "", + Type: config.ParameterTypeInt, + Validations: []config.Validation{}, + }, + ConfigMyInt8: { + Default: "", + Description: "", + Type: config.ParameterTypeInt, + Validations: []config.Validation{}, + }, + ConfigMyIntSlice: { + Default: "", + Description: "", + Type: config.ParameterTypeString, + Validations: []config.Validation{}, + }, + ConfigMyRune: { + Default: "", + Description: "", + Type: config.ParameterTypeInt, + Validations: []config.Validation{}, + }, + ConfigMyString: { + Default: "", + Description: "MyString my string description", + Type: config.ParameterTypeString, + Validations: []config.Validation{}, + }, + ConfigMyStringMap: { + Default: "", + Description: "", + Type: config.ParameterTypeString, + Validations: []config.Validation{}, + }, + ConfigMyStructMapMyInt: { + Default: "", + Description: "", + Type: config.ParameterTypeInt, + Validations: []config.Validation{}, + }, + ConfigMyStructMapMyString: { + Default: "", + Description: "", + Type: config.ParameterTypeString, + Validations: []config.Validation{}, + }, + ConfigMyUint: { + Default: "", + Description: "", + Type: config.ParameterTypeInt, + Validations: []config.Validation{}, + }, + ConfigMyUint16: { + Default: "", + Description: "", + Type: config.ParameterTypeInt, + Validations: []config.Validation{}, + }, + ConfigMyUint32: { + Default: "", + Description: "", + Type: config.ParameterTypeInt, + Validations: []config.Validation{}, + }, + ConfigMyUint64: { + Default: "", + Description: "", + Type: config.ParameterTypeInt, + Validations: []config.Validation{}, + }, + ConfigMyUint8: { + Default: "", + Description: "", + Type: config.ParameterTypeInt, + Validations: []config.Validation{}, + }, + } +} diff --git a/paramgen/internal/testdata/invalid1/go.mod b/paramgen/paramgen/testdata/invalid1/go.mod similarity index 100% rename from paramgen/internal/testdata/invalid1/go.mod rename to paramgen/paramgen/testdata/invalid1/go.mod diff --git a/paramgen/internal/testdata/invalid1/specs.go b/paramgen/paramgen/testdata/invalid1/specs.go similarity index 100% rename from paramgen/internal/testdata/invalid1/specs.go rename to paramgen/paramgen/testdata/invalid1/specs.go diff --git a/paramgen/internal/testdata/invalid2/go.mod b/paramgen/paramgen/testdata/invalid2/go.mod similarity index 100% rename from paramgen/internal/testdata/invalid2/go.mod rename to paramgen/paramgen/testdata/invalid2/go.mod diff --git a/paramgen/internal/testdata/invalid2/specs.go b/paramgen/paramgen/testdata/invalid2/specs.go similarity index 100% rename from paramgen/internal/testdata/invalid2/specs.go rename to paramgen/paramgen/testdata/invalid2/specs.go diff --git a/paramgen/internal/testdata/tags/go.mod b/paramgen/paramgen/testdata/tags/go.mod similarity index 100% rename from paramgen/internal/testdata/tags/go.mod rename to paramgen/paramgen/testdata/tags/go.mod diff --git a/paramgen/internal/testdata/tags/go.sum b/paramgen/paramgen/testdata/tags/go.sum similarity index 100% rename from paramgen/internal/testdata/tags/go.sum rename to paramgen/paramgen/testdata/tags/go.sum diff --git a/paramgen/internal/testdata/tags/specs.go b/paramgen/paramgen/testdata/tags/specs.go similarity index 100% rename from paramgen/internal/testdata/tags/specs.go rename to paramgen/paramgen/testdata/tags/specs.go diff --git a/paramgen/internal/testdata/tags/want.go b/paramgen/paramgen/testdata/tags/want.go similarity index 100% rename from paramgen/internal/testdata/tags/want.go rename to paramgen/paramgen/testdata/tags/want.go