From 79de631de6236869e9e70b8e86f413bea361f392 Mon Sep 17 00:00:00 2001 From: Steph Date: Wed, 8 Feb 2023 15:25:42 +0100 Subject: [PATCH 1/2] add workaround for Batch autoStorage Properties --- .../dataworkarounds/workaround_batch_21291.go | 45 +++++++++++++++++++ .../parser/dataworkarounds/workarounds.go | 1 + 2 files changed, 46 insertions(+) create mode 100644 tools/importer-rest-api-specs/components/parser/dataworkarounds/workaround_batch_21291.go diff --git a/tools/importer-rest-api-specs/components/parser/dataworkarounds/workaround_batch_21291.go b/tools/importer-rest-api-specs/components/parser/dataworkarounds/workaround_batch_21291.go new file mode 100644 index 00000000000..467f9bbdfe1 --- /dev/null +++ b/tools/importer-rest-api-specs/components/parser/dataworkarounds/workaround_batch_21291.go @@ -0,0 +1,45 @@ +package dataworkarounds + +import ( + "fmt" + "github.com/hashicorp/pandora/tools/importer-rest-api-specs/models" +) + +var _ workaround = workaroundBatch21291{} + +// workaroundBatch21291 works around the StorageAccountId property being marked as Required which means it isn't +// nullable/removable like it was with the Azure Track1 SDK. +// The Swagger PR: https://github.com/Azure/azure-rest-api-specs/pull/21291 +type workaroundBatch21291 struct { +} + +func (workaroundBatch21291) IsApplicable(apiDefinition *models.AzureApiDefinition) bool { + serviceMatches := apiDefinition.ServiceName == "Batch" + apiVersionMatches := apiDefinition.ApiVersion == "2022-01-01" + return serviceMatches && apiVersionMatches +} + +func (workaroundBatch21291) Name() string { + return "Batch / 21291" +} + +func (workaroundBatch21291) Process(apiDefinition models.AzureApiDefinition) (*models.AzureApiDefinition, error) { + resource, ok := apiDefinition.Resources["BatchAccount"] + if !ok { + return nil, fmt.Errorf("couldn't find API Resource BatchAccount") + } + model, ok := resource.Models["AutoStorageBaseProperties"] + if !ok { + return nil, fmt.Errorf("couldn't find Model AutoStorageProperties") + } + field, ok := model.Fields["StorageAccountId"] + if !ok { + return nil, fmt.Errorf("couldn't find the field StorageAccountId within model AutoStorageProperties") + } + field.Required = false + + model.Fields["StorageAccountId"] = field + resource.Models["AutoStorageProperties"] = model + apiDefinition.Resources["BatchAccount"] = resource + return &apiDefinition, nil +} diff --git a/tools/importer-rest-api-specs/components/parser/dataworkarounds/workarounds.go b/tools/importer-rest-api-specs/components/parser/dataworkarounds/workarounds.go index bd61c3c7e97..7284a51a440 100644 --- a/tools/importer-rest-api-specs/components/parser/dataworkarounds/workarounds.go +++ b/tools/importer-rest-api-specs/components/parser/dataworkarounds/workarounds.go @@ -8,6 +8,7 @@ import ( ) var workarounds = []workaround{ + workaroundBatch21291{}, workaroundContainerService21394{}, workaroundLoadTest20961{}, workaroundMedia21581{}, From 38b39bfbdc4d8e8ef6c1ccd8c413fe40910a4915 Mon Sep 17 00:00:00 2001 From: Steph Date: Wed, 8 Feb 2023 15:39:45 +0100 Subject: [PATCH 2/2] overwrite base properties model --- .../parser/dataworkarounds/workaround_batch_21291.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/importer-rest-api-specs/components/parser/dataworkarounds/workaround_batch_21291.go b/tools/importer-rest-api-specs/components/parser/dataworkarounds/workaround_batch_21291.go index 467f9bbdfe1..e0f15d5513f 100644 --- a/tools/importer-rest-api-specs/components/parser/dataworkarounds/workaround_batch_21291.go +++ b/tools/importer-rest-api-specs/components/parser/dataworkarounds/workaround_batch_21291.go @@ -30,7 +30,7 @@ func (workaroundBatch21291) Process(apiDefinition models.AzureApiDefinition) (*m } model, ok := resource.Models["AutoStorageBaseProperties"] if !ok { - return nil, fmt.Errorf("couldn't find Model AutoStorageProperties") + return nil, fmt.Errorf("couldn't find Model AutoStorageBaseProperties") } field, ok := model.Fields["StorageAccountId"] if !ok { @@ -39,7 +39,7 @@ func (workaroundBatch21291) Process(apiDefinition models.AzureApiDefinition) (*m field.Required = false model.Fields["StorageAccountId"] = field - resource.Models["AutoStorageProperties"] = model + resource.Models["AutoStorageBaseProperties"] = model apiDefinition.Resources["BatchAccount"] = resource return &apiDefinition, nil }