mirror of https://github.com/k3s-io/k3s
allow exceptions to be specified to handle conflicting group and resourc enames
parent
3660ff466f
commit
c59e211a7c
|
@ -41,9 +41,36 @@ func NameSystems() namer.NameSystems {
|
||||||
"Endpoints": "Endpoints",
|
"Endpoints": "Endpoints",
|
||||||
}
|
}
|
||||||
lowercaseNamer := namer.NewAllLowercasePluralNamer(pluralExceptions)
|
lowercaseNamer := namer.NewAllLowercasePluralNamer(pluralExceptions)
|
||||||
|
|
||||||
|
publicNamer := &ExceptionNamer{
|
||||||
|
Exceptions: map[string]string{
|
||||||
|
// these exceptions are used to deconflict the generated code
|
||||||
|
// you can put your fully qualified package like
|
||||||
|
// to generate a name that doesn't conflict with your group.
|
||||||
|
// "k8s.io/apis/events/v1alpha1.Event": "EventResource"
|
||||||
|
},
|
||||||
|
KeyFunc: func(t *types.Type) string {
|
||||||
|
return t.Name.Package + "." + t.Name.Name
|
||||||
|
},
|
||||||
|
Delegate: namer.NewPublicNamer(0),
|
||||||
|
}
|
||||||
|
privateNamer := &ExceptionNamer{
|
||||||
|
Exceptions: map[string]string{
|
||||||
|
// these exceptions are used to deconflict the generated code
|
||||||
|
// you can put your fully qualified package like
|
||||||
|
// to generate a name that doesn't conflict with your group.
|
||||||
|
// "k8s.io/apis/events/v1alpha1.Event": "eventResource"
|
||||||
|
},
|
||||||
|
KeyFunc: func(t *types.Type) string {
|
||||||
|
return t.Name.Package + "." + t.Name.Name
|
||||||
|
},
|
||||||
|
Delegate: namer.NewPrivateNamer(0),
|
||||||
|
}
|
||||||
|
|
||||||
return namer.NameSystems{
|
return namer.NameSystems{
|
||||||
"public": namer.NewPublicNamer(0),
|
"singularKind": namer.NewPublicNamer(0),
|
||||||
"private": namer.NewPrivateNamer(0),
|
"public": publicNamer,
|
||||||
|
"private": privateNamer,
|
||||||
"raw": namer.NewRawNamer("", nil),
|
"raw": namer.NewRawNamer("", nil),
|
||||||
"publicPlural": namer.NewPublicPluralNamer(pluralExceptions),
|
"publicPlural": namer.NewPublicPluralNamer(pluralExceptions),
|
||||||
"privatePlural": namer.NewPrivatePluralNamer(pluralExceptions),
|
"privatePlural": namer.NewPrivatePluralNamer(pluralExceptions),
|
||||||
|
@ -52,6 +79,24 @@ func NameSystems() namer.NameSystems {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ExceptionNamer allows you specify exceptional cases with exact names. This allows you to have control
|
||||||
|
// for handling various conflicts, like group and resource names for instance.
|
||||||
|
type ExceptionNamer struct {
|
||||||
|
Exceptions map[string]string
|
||||||
|
KeyFunc func(*types.Type) string
|
||||||
|
|
||||||
|
Delegate namer.Namer
|
||||||
|
}
|
||||||
|
|
||||||
|
// Name provides the requested name for a type.
|
||||||
|
func (n *ExceptionNamer) Name(t *types.Type) string {
|
||||||
|
key := n.KeyFunc(t)
|
||||||
|
if exception, ok := n.Exceptions[key]; ok {
|
||||||
|
return exception
|
||||||
|
}
|
||||||
|
return n.Delegate.Name(t)
|
||||||
|
}
|
||||||
|
|
||||||
// DefaultNameSystem returns the default name system for ordering the types to be
|
// DefaultNameSystem returns the default name system for ordering the types to be
|
||||||
// processed by the generators in this package.
|
// processed by the generators in this package.
|
||||||
func DefaultNameSystem() string {
|
func DefaultNameSystem() string {
|
||||||
|
|
|
@ -213,7 +213,7 @@ var $.type|allLowercasePlural$Resource = $.GroupVersionResource|raw${Group: "$.g
|
||||||
`
|
`
|
||||||
|
|
||||||
var kind = `
|
var kind = `
|
||||||
var $.type|allLowercasePlural$Kind = $.GroupVersionKind|raw${Group: "$.groupName$", Version: "$.version$", Kind: "$.type|public$"}
|
var $.type|allLowercasePlural$Kind = $.GroupVersionKind|raw${Group: "$.groupName$", Version: "$.version$", Kind: "$.type|singularKind$"}
|
||||||
`
|
`
|
||||||
|
|
||||||
var listTemplate = `
|
var listTemplate = `
|
||||||
|
|
Loading…
Reference in New Issue