Skip to content

Commit 04a51d5

Browse files
Tidyup ARM type naming (#4446)
* Remove suppressions * Remove ARMSuffix now we don't need it
1 parent f6c0c7a commit 04a51d5

7 files changed

+7
-35
lines changed

v2/tools/generator/internal/armconversion/convert_to_arm_function_builder.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ func (builder *convertToARMBuilder) convertComplexTypeNameProperty(
867867
}
868868

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

872872
// Call ToARM on the property
873873
results = append(results, callToARMFunction(params.GetSource(), dst.NewIdent(propertyLocalVarName), builder.methodName)...)

v2/tools/generator/internal/astmodel/identifier_factory.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,9 @@ func createReservedWords() map[string]string {
293293

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

303301
func (factory *identifierFactory) CreateGroupName(group string) string {

v2/tools/generator/internal/astmodel/identifier_factory_test.go

+1-3
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,6 @@ func Test_CreateReceiver_GivenTypeName_ReturnsExpectedResult(t *testing.T) {
203203
// Forbidden receiver suffixes
204204
{"Address" + StatusSuffix, "address"},
205205
{"Address" + SpecSuffix, "address"},
206-
{"Address" + StatusSuffix + ARMSuffix, "address"},
207-
{"Address" + SpecSuffix + ARMSuffix, "address"},
208206
// Real world examples
209207
{"EncryptionSettingsCollection", "collection"},
210208
{"RedisLinkedServer", "server"},
@@ -217,7 +215,7 @@ func Test_CreateReceiver_GivenTypeName_ReturnsExpectedResult(t *testing.T) {
217215
{"DatabaseAccountsMongodbDatabasesCollections" + SpecSuffix, "collections"},
218216
{"DatabaseAccountsMongodbDatabasesCollectionsThroughputSettings" + SpecSuffix, "settings"},
219217
// Very short receiver names need more detail
220-
{"SignalR" + SpecSuffix + ARMSuffix, "signalR"},
218+
{"SignalR" + SpecSuffix, "signalR"},
221219
{"PublicIPAddressSku" + StatusSuffix, "addressSku"},
222220
{"SBSku" + StatusSuffix, "sbSku"},
223221
{"ManagedClusterSKU", "clusterSKU"},

v2/tools/generator/internal/astmodel/internal_type_name.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,7 @@ func (tn InternalTypeName) IsStatus() bool {
186186

187187
// IsARMType returns true if the TypeName identifies an ARM specific type, false otherwise.
188188
func (tn InternalTypeName) IsARMType() bool {
189-
if IsARMPackageReference(tn.InternalPackageReference()) {
190-
return true
191-
}
192-
193-
return strings.HasSuffix(tn.Name(), ARMSuffix)
189+
return IsARMPackageReference(tn.InternalPackageReference())
194190
}
195191

196192
func (tn InternalTypeName) IsEmpty() bool {

v2/tools/generator/internal/astmodel/type_name.go

-12
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
package astmodel
77

8-
import "github.com/Azure/azure-service-operator/v2/internal/set"
9-
108
type TypeName interface {
119
Type
1210
Name() string
@@ -18,22 +16,12 @@ const (
1816
SpecSuffix = "_Spec"
1917
// StatusSuffix is the suffix used for all Status types
2018
StatusSuffix = "_STATUS"
21-
// ARMSuffix is the suffix used for all ARM types
22-
ARMSuffix = "_ARM"
2319
// ARMPackageName is the name used for ARM subpackages
2420
ARMPackageName = "arm"
2521
)
2622

27-
var armPackageDenyList = set.Make(
28-
"kusto")
29-
3023
// CreateARMTypeName creates an ARM object type name
3124
func CreateARMTypeName(name InternalTypeName) InternalTypeName {
32-
pkg := name.InternalPackageReference()
33-
if armPackageDenyList.Contains(pkg.Group()) {
34-
return MakeInternalTypeName(pkg, name.Name()+ARMSuffix)
35-
}
36-
3725
armPackage := MakeSubPackageReference(ARMPackageName, name.InternalPackageReference())
3826
return MakeInternalTypeName(armPackage, name.Name())
3927
}

v2/tools/generator/internal/codegen/pipeline/name_types_for_crd.go

-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ type nameHint struct {
192192
var suffixesToFloat = []string{
193193
astmodel.SpecSuffix,
194194
astmodel.StatusSuffix,
195-
astmodel.ARMSuffix,
196195
}
197196

198197
func newNameHint(name astmodel.TypeName) nameHint {

v2/tools/generator/internal/codegen/pipeline/name_types_for_crd_test.go

+3-10
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,10 @@ func Test_NewNameHint(t *testing.T) {
4646
},
4747
{
4848
"Simple TypeName",
49-
astmodel.MakeInternalTypeName(test.Pkg2020, "Person"+astmodel.ARMSuffix),
50-
"Person",
51-
"ARM",
52-
"Person_ARM",
53-
},
54-
{
55-
"Simple TypeName",
56-
astmodel.MakeInternalTypeName(test.Pkg2020, "Person"+astmodel.StatusSuffix+astmodel.ARMSuffix),
49+
astmodel.MakeInternalTypeName(test.Pkg2020, "Person"+astmodel.StatusSuffix),
5750
"Person",
58-
"STATUS_ARM",
59-
"Person_STATUS_ARM",
51+
"STATUS",
52+
"Person_STATUS",
6053
},
6154
}
6255

0 commit comments

Comments
 (0)