Skip to content
Merged
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
4 changes: 4 additions & 0 deletions cmd/metamodel/generate/golang/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ func shouldRunGenerator(generator string) bool {
}
}

// In a case where "*" is used, we want compatibility with previous behavior.
// Previous behavior has apiBase="" (default) and all generators, but these new generators did not exist.
// To be compatible, we skip these here.
// Once all consumers are updated, a future refinement could be to disallow "*".
switch generator {
case "builders-alias", "json-alias", "types-alias":
return false
Expand Down
7 changes: 7 additions & 0 deletions pkg/generators/golang/builders_alias_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,11 @@ func (g *BuildersAliasGenerator) generateStructBuilderAliasSource(typ *concepts.
{{ $builderName := builderName .Type }}
{{ $builderCtor := builderCtor .Type }}

// {{ $builderName }} contains the data and logic needed to build '{{ .Type.Name }}' objects.
//
{{ lineComment .Type.Doc }}
type {{ $builderName }} = {{ apiVersionPackage }}.{{ $builderName }}
// {{ $builderCtor }} creates a new builder of '{{ .Type.Name }}' objects.
var {{ $builderCtor }} = {{ apiVersionPackage }}.{{ $builderCtor }}
`,
"Type", typ,
Expand Down Expand Up @@ -212,7 +216,10 @@ func (g *BuildersAliasGenerator) generateStructListBuilderAliasSource(typ *conce
{{ $builderName := builderName .Type }}
{{ $builderCtor := builderCtor .Type }}

// {{ $builderName }} contains the data and logic needed to build
// '{{ .Type.Element.Name }}' objects.
type {{ $builderName }} = {{ apiVersionPackage }}.{{ $builderName }}
// {{ $builderCtor }} creates a new builder of '{{ .Type.Element.Name }}' objects.
var {{ $builderCtor }} = {{ apiVersionPackage }}.{{ $builderCtor }}
`,
"Type", typ,
Expand Down
16 changes: 16 additions & 0 deletions pkg/generators/golang/json_alias_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,10 @@ func (g *JSONSupportAliasGenerator) generateVersionMetadataAliasSource(version *
g.buffer.Import("github.com/json-iterator/go", "jsoniter")
g.buffer.Import(g.packages.APIVersionImport(version), g.packages.APIVersionSelector(version))
g.buffer.Emit(`
// MarshalMetadata writes a value of the metadata type to the given target, which
var MarshalMetadata = {{ apiVersionPackage }}.MarshalMetadata
// UnmarshalMetadata reads a value of the metadata type from the given source, which
// which can be a reader, a slice of byte or a string.
var UnmarshalMetadata = {{ apiVersionPackage }}.UnmarshalMetadata
`,
"Version", version,
Expand Down Expand Up @@ -257,9 +260,14 @@ func (g *JSONSupportAliasGenerator) generateStructTypeAliasSource(version *conce
{{ $unmarshalTypeFunc := unmarshalTypeFunc .Type }}
{{ $readTypeFunc := readTypeFunc .Type }}

// {{ $marshalTypeFunc }} writes a value of the '{{ .Type.Name }}' type to the given writer.
var {{ $marshalTypeFunc }} = {{ apiVersionPackage }}.{{ $marshalTypeFunc }}
// {{ $writeTypeFunc }} writes a value of the '{{ .Type.Name }}' type to the given stream.
var {{ $writeTypeFunc }} = {{ apiVersionPackage }}.{{ $writeTypeFunc }}
// {{ $unmarshalTypeFunc }} reads a value of the '{{ .Type.Name }}' type from the given
// source, which can be an slice of bytes, a string or a reader.
var {{ $unmarshalTypeFunc }} = {{ apiVersionPackage }}.{{ $unmarshalTypeFunc }}
// {{ $readTypeFunc }} reads a value of the '{{ .Type.Name }}' type from the given iterator.
var {{ $readTypeFunc }} = {{ apiVersionPackage }}.{{ $readTypeFunc }}
`,
"Type", typ,
Expand Down Expand Up @@ -319,9 +327,17 @@ func (g *JSONSupportAliasGenerator) generateListTypeAliasSource(
{{ $unmarshalTypeFunc := unmarshalTypeFunc .Type }}
{{ $readTypeFunc := readTypeFunc .Type }}

// {{ $marshalTypeFunc }} writes a list of values of the '{{ .Type.Element.Name }}' type to
// the given writer.
var {{ $marshalTypeFunc }} = {{ apiVersionPackage }}.{{ $marshalTypeFunc }}
// {{ $writeTypeFunc }} writes a list of value of the '{{ .Type.Element.Name }}' type to
// the given stream.
var {{ $writeTypeFunc }} = {{ apiVersionPackage }}.{{ $writeTypeFunc }}
// {{ $unmarshalTypeFunc }} reads a list of values of the '{{ .Type.Element.Name }}' type
// from the given source, which can be a slice of bytes, a string or a reader.
var {{ $unmarshalTypeFunc }} = {{ apiVersionPackage }}.{{ $unmarshalTypeFunc }}
// {{ $readTypeFunc }} reads list of values of the ''{{ .Type.Element.Name }}' type from
// the given iterator.
var {{ $readTypeFunc }} = {{ apiVersionPackage }}.{{ $readTypeFunc }}
`,
"Type", typ,
Expand Down