From 13e8755182472279cd346a9cd2330d2716f23d10 Mon Sep 17 00:00:00 2001 From: Steph Date: Tue, 28 Nov 2023 11:35:08 +0100 Subject: [PATCH] add generic rename processor for fields --- .../processors/field_name_generic_rename.go | 26 +++++++++++++++++++ .../components/schema/processors/fields.go | 1 + 2 files changed, 27 insertions(+) create mode 100644 tools/importer-rest-api-specs/components/schema/processors/field_name_generic_rename.go diff --git a/tools/importer-rest-api-specs/components/schema/processors/field_name_generic_rename.go b/tools/importer-rest-api-specs/components/schema/processors/field_name_generic_rename.go new file mode 100644 index 00000000000..39aa11f8320 --- /dev/null +++ b/tools/importer-rest-api-specs/components/schema/processors/field_name_generic_rename.go @@ -0,0 +1,26 @@ +package processors + +import ( + "github.com/hashicorp/go-azure-helpers/lang/pointer" + "strings" +) + +var _ FieldNameProcessor = fieldNameGenericRename{} + +type fieldNameGenericRename struct{} + +func (fieldNameGenericRename) ProcessField(fieldName string, metadata FieldMetadata) (*string, error) { + // some simple and flat resources that should be easily generated are blocked because of property names + // that don't follow the naming guidelines we have in the provider. This field processor is a temporary + // means of renaming fields to enable generation of the resource but may want some modifying in future + // e.g. specifying name overrides in the terraform resource configuration (like in devcenter.hcl) instead + // of being hard-coded here + + if strings.EqualFold(metadata.TerraformDetails.ResourceName, "dev_center_gallery") { + if strings.EqualFold(strings.ToLower(fieldName), "galleryResourceId") { + return pointer.To("sharedGalleryId"), nil + } + } + + return nil, nil +} diff --git a/tools/importer-rest-api-specs/components/schema/processors/fields.go b/tools/importer-rest-api-specs/components/schema/processors/fields.go index 448cc51b304..68304b974a7 100644 --- a/tools/importer-rest-api-specs/components/schema/processors/fields.go +++ b/tools/importer-rest-api-specs/components/schema/processors/fields.go @@ -23,6 +23,7 @@ var NamingRules = []FieldNameProcessor{ fieldNameRenameBoolean{}, fieldNameRenameMislabelledResourceID{}, fieldNameMaxToMaximum{}, + fieldNameGenericRename{}, } //TODO: if it's a List[Reference] and the model contains a single field `Id` then flatten this into `_ids`.