Skip to content

Commit

Permalink
Tidyup ARM type naming (#4446)
Browse files Browse the repository at this point in the history
* Remove suppressions

* Remove ARMSuffix now we don't need it
  • Loading branch information
theunrepentantgeek authored Nov 15, 2024
1 parent f6c0c7a commit 04a51d5
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ func (builder *convertToARMBuilder) convertComplexTypeNameProperty(
}

var results []dst.Stmt
propertyLocalVarName := params.Locals.CreateLocal(params.NameHint, astmodel.ARMSuffix)
propertyLocalVarName := params.Locals.CreateLocal(params.NameHint, "_ARM")

// Call ToARM on the property
results = append(results, callToARMFunction(params.GetSource(), dst.NewIdent(propertyLocalVarName), builder.methodName)...)
Expand Down
4 changes: 1 addition & 3 deletions v2/tools/generator/internal/astmodel/identifier_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,9 @@ func createReservedWords() map[string]string {

// createForbiddenReceiverSuffixes creates a case-sensitive list of words we don't want to use as receiver names
func createForbiddenReceiverSuffixes() set.Set[string] {
// If/when Status or Spec are all capitals, ARM isn't separated as a different word
status := strings.TrimPrefix(StatusSuffix, "_")
spec := strings.TrimPrefix(SpecSuffix, "_")
arm := strings.TrimPrefix(ARMSuffix, "_")
return set.Make(status, spec, arm, status+arm, spec+arm)
return set.Make(status, spec)
}

func (factory *identifierFactory) CreateGroupName(group string) string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ func Test_CreateReceiver_GivenTypeName_ReturnsExpectedResult(t *testing.T) {
// Forbidden receiver suffixes
{"Address" + StatusSuffix, "address"},
{"Address" + SpecSuffix, "address"},
{"Address" + StatusSuffix + ARMSuffix, "address"},
{"Address" + SpecSuffix + ARMSuffix, "address"},
// Real world examples
{"EncryptionSettingsCollection", "collection"},
{"RedisLinkedServer", "server"},
Expand All @@ -217,7 +215,7 @@ func Test_CreateReceiver_GivenTypeName_ReturnsExpectedResult(t *testing.T) {
{"DatabaseAccountsMongodbDatabasesCollections" + SpecSuffix, "collections"},
{"DatabaseAccountsMongodbDatabasesCollectionsThroughputSettings" + SpecSuffix, "settings"},
// Very short receiver names need more detail
{"SignalR" + SpecSuffix + ARMSuffix, "signalR"},
{"SignalR" + SpecSuffix, "signalR"},
{"PublicIPAddressSku" + StatusSuffix, "addressSku"},
{"SBSku" + StatusSuffix, "sbSku"},
{"ManagedClusterSKU", "clusterSKU"},
Expand Down
6 changes: 1 addition & 5 deletions v2/tools/generator/internal/astmodel/internal_type_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,7 @@ func (tn InternalTypeName) IsStatus() bool {

// IsARMType returns true if the TypeName identifies an ARM specific type, false otherwise.
func (tn InternalTypeName) IsARMType() bool {
if IsARMPackageReference(tn.InternalPackageReference()) {
return true
}

return strings.HasSuffix(tn.Name(), ARMSuffix)
return IsARMPackageReference(tn.InternalPackageReference())
}

func (tn InternalTypeName) IsEmpty() bool {
Expand Down
12 changes: 0 additions & 12 deletions v2/tools/generator/internal/astmodel/type_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package astmodel

import "github.com/Azure/azure-service-operator/v2/internal/set"

type TypeName interface {
Type
Name() string
Expand All @@ -18,22 +16,12 @@ const (
SpecSuffix = "_Spec"
// StatusSuffix is the suffix used for all Status types
StatusSuffix = "_STATUS"
// ARMSuffix is the suffix used for all ARM types
ARMSuffix = "_ARM"
// ARMPackageName is the name used for ARM subpackages
ARMPackageName = "arm"
)

var armPackageDenyList = set.Make(
"kusto")

// CreateARMTypeName creates an ARM object type name
func CreateARMTypeName(name InternalTypeName) InternalTypeName {
pkg := name.InternalPackageReference()
if armPackageDenyList.Contains(pkg.Group()) {
return MakeInternalTypeName(pkg, name.Name()+ARMSuffix)
}

armPackage := MakeSubPackageReference(ARMPackageName, name.InternalPackageReference())
return MakeInternalTypeName(armPackage, name.Name())
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ type nameHint struct {
var suffixesToFloat = []string{
astmodel.SpecSuffix,
astmodel.StatusSuffix,
astmodel.ARMSuffix,
}

func newNameHint(name astmodel.TypeName) nameHint {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,10 @@ func Test_NewNameHint(t *testing.T) {
},
{
"Simple TypeName",
astmodel.MakeInternalTypeName(test.Pkg2020, "Person"+astmodel.ARMSuffix),
"Person",
"ARM",
"Person_ARM",
},
{
"Simple TypeName",
astmodel.MakeInternalTypeName(test.Pkg2020, "Person"+astmodel.StatusSuffix+astmodel.ARMSuffix),
astmodel.MakeInternalTypeName(test.Pkg2020, "Person"+astmodel.StatusSuffix),
"Person",
"STATUS_ARM",
"Person_STATUS_ARM",
"STATUS",
"Person_STATUS",
},
}

Expand Down

0 comments on commit 04a51d5

Please sign in to comment.