Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: code generate #29

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
61 changes: 43 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,25 +1,9 @@
module yunion.io/x/code-generator

go 1.13

require (
github.com/go-openapi/loads v0.19.4
github.com/pkg/errors v0.8.1
github.com/skratchdot/open-golang v0.0.0-20190402232053-79abb63cd66e
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.5
golang.org/x/sys v0.0.0-20221013171732-95e765b1cc43 // indirect
golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4
k8s.io/gengo v0.0.0-20200425085600-19394052f0fa
k8s.io/klog v1.0.0
k8s.io/klog/v2 v2.0.0 // indirect
yunion.io/x/log v0.0.0-20200313080802-57a4ce5966b3
yunion.io/x/pkg v0.0.0-20200416145704-22c189971435
)
go 1.21

replace (
golang.org/x/tools => github.com/yousong/tools v0.0.0-20191028041046-a3599409985d

k8s.io/api => k8s.io/api v0.0.0-20190918155943-95b840bb6a1f
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.0.0-20190918161926-8f644eb6e783
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20190913080033-27d36303b655
Expand All @@ -32,7 +16,6 @@ replace (
k8s.io/component-base => k8s.io/component-base v0.0.0-20190918160511-547f6c5d7090
k8s.io/cri-api => k8s.io/cri-api v0.0.0-20190828162817-608eb1dad4ac
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.0.0-20190918163402-db86a8c7bb21

k8s.io/gengo => github.com/zexi/gengo v0.0.0-20200425085600-19394052f0fa

k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.0.0-20190918161219-8c8f079fddc3
Expand All @@ -48,3 +31,45 @@ replace (
k8s.io/sample-cli-plugin => k8s.io/sample-cli-plugin v0.0.0-20190918162410-e45c26d066f2
k8s.io/sample-controller => k8s.io/sample-controller v0.0.0-20190918161628-92eb3cb7496c
)

require (
github.com/go-openapi/loads v0.22.0
github.com/pkg/errors v0.9.1
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
golang.org/x/tools v0.0.0-00010101000000-000000000000
k8s.io/gengo v0.0.0-00010101000000-000000000000
k8s.io/klog v1.0.0
yunion.io/x/log v1.0.0
yunion.io/x/pkg v1.10.0
)

require (
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-openapi/analysis v0.23.0 // indirect
github.com/go-openapi/errors v0.22.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/spec v0.21.0 // indirect
github.com/go-openapi/strfmt v0.23.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/konsorten/go-windows-terminal-sequences v1.0.3 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.9 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/sirupsen/logrus v1.6.0 // indirect
go.mongodb.org/mongo-driver v1.14.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/term v0.15.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
)
211 changes: 80 additions & 131 deletions go.sum

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions pkg/model-api-gen/generators/apigen.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func (g *apiGen) Imports(c *generator.Context) []string {
parts := strings.Split(line, " ")
if len(parts) == 2 {
pkgName := strings.Trim(parts[1], `"`)
if g.needImportPackages.Has(pkgName) {
if g.needImportPackages.Has(pkgName) || pkgName == g.outputPackage {
continue
}
}
Expand Down Expand Up @@ -515,10 +515,19 @@ func (m *Member) Do(sw *generator.SnippetWriter, args interface{}) {

func (g *apiGen) doSlice(m types.Member, sw *generator.SnippetWriter) {
memType := m.Type.Elem
point := false
if memType.Kind == types.Pointer {
memType = memType.Elem
point = true
}
memPkg := memType.Name.Package
modelMem := NewModelMember(m)
if memPkg == g.outputPackage || memPkg == g.sourcePackage {
modelMem.Type(fmt.Sprintf("[]%s", memType.Name.Name))
if point {
modelMem.Type(fmt.Sprintf("[]*%s", memType.Name.Name))
} else {
modelMem.Type(fmt.Sprintf("[]%s", memType.Name.Name))
}
}
modelMem.Do(sw, g.args(m.Type))
}
Expand Down
15 changes: 15 additions & 0 deletions vendor/github.com/asaskevich/govalidator/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions vendor/github.com/asaskevich/govalidator/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions vendor/github.com/asaskevich/govalidator/CODE_OF_CONDUCT.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions vendor/github.com/asaskevich/govalidator/CONTRIBUTING.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions vendor/github.com/asaskevich/govalidator/LICENSE

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading