Skip to content

Commit

Permalink
Importer: add workaround for batch account autoStorageBaseProperties (#…
Browse files Browse the repository at this point in the history
…2091)

* add workaround for Batch autoStorage Properties

* overwrite base properties model
  • Loading branch information
stephybun authored Feb 8, 2023
1 parent 5ed86d1 commit 11b4ce4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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 AutoStorageBaseProperties")
}
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["AutoStorageBaseProperties"] = model
apiDefinition.Resources["BatchAccount"] = resource
return &apiDefinition, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

var workarounds = []workaround{
workaroundBatch21291{},
workaroundContainerService21394{},
workaroundLoadTest20961{},
workaroundMedia21581{},
Expand Down

0 comments on commit 11b4ce4

Please sign in to comment.