From e2293a74fa190de40939107b5414fb94a739e0c5 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Wed, 2 Aug 2023 17:19:32 +0200 Subject: [PATCH] tools/importer-rest-api-specs: adding a workaround for `digitaltwins` Unblocks https://github.com/hashicorp/terraform-provider-azurerm/pull/22782 --- .../workaround_digitaltwins_25120.go | 53 +++++++++++++++++++ .../parser/dataworkarounds/workarounds.go | 1 + 2 files changed, 54 insertions(+) create mode 100644 tools/importer-rest-api-specs/components/parser/dataworkarounds/workaround_digitaltwins_25120.go diff --git a/tools/importer-rest-api-specs/components/parser/dataworkarounds/workaround_digitaltwins_25120.go b/tools/importer-rest-api-specs/components/parser/dataworkarounds/workaround_digitaltwins_25120.go new file mode 100644 index 00000000000..c14e664713b --- /dev/null +++ b/tools/importer-rest-api-specs/components/parser/dataworkarounds/workaround_digitaltwins_25120.go @@ -0,0 +1,53 @@ +package dataworkarounds + +import ( + "fmt" + + "github.com/hashicorp/pandora/tools/importer-rest-api-specs/models" +) + +var _ workaround = workaroundDigitalTwins25120{} + +// Swagger PR: https://github.com/Azure/azure-rest-api-specs/pull/21520 +type workaroundDigitalTwins25120 struct{} + +func (workaroundDigitalTwins25120) IsApplicable(apiDefinition *models.AzureApiDefinition) bool { + // API Defines a Constant with the string values `"true"` and `"false`: + // RecordPropertyAndItemRemovals *RecordPropertyAndItemRemovals `json:"recordPropertyAndItemRemovals,omitempty"` + // but the API returns a boolean: + // "recordPropertyAndItemRemovals": false, + return apiDefinition.ServiceName == "DigitalTwins" && apiDefinition.ApiVersion == "2023-01-31" +} + +func (workaroundDigitalTwins25120) Name() string { + return "DigitalTwins / 25120" +} + +func (workaroundDigitalTwins25120) Process(apiDefinition models.AzureApiDefinition) (*models.AzureApiDefinition, error) { + resource, ok := apiDefinition.Resources["TimeSeriesDatabaseConnections"] + if !ok { + return nil, fmt.Errorf("expected a Resource named `TimeSeriesDatabaseConnections`") + } + + model, ok := resource.Models["AzureDataExplorerConnectionProperties"] + if !ok { + return nil, fmt.Errorf("expected a Model named `AzureDataExplorerConnectionProperties`") + } + field, ok := model.Fields["RecordPropertyAndItemRemovals"] + if !ok { + return nil, fmt.Errorf("expected a Field named `RecordPropertyAndItemRemovals`") + } + field.ObjectDefinition = &models.ObjectDefinition{ + Type: models.ObjectDefinitionBoolean, + } + model.Fields["RecordPropertyAndItemRemovals"] = field + resource.Models["AzureDataExplorerConnectionProperties"] = model + + if _, ok := resource.Constants["RecordPropertyAndItemRemovals"]; !ok { + return nil, fmt.Errorf("expected a Constant named `RecordPropertyAndItemRemovals`") + } + delete(resource.Constants, "RecordPropertyAndItemRemovals") + + apiDefinition.Resources["TimeSeriesDatabaseConnections"] = 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 aa1687164bf..5b8d74552d1 100644 --- a/tools/importer-rest-api-specs/components/parser/dataworkarounds/workarounds.go +++ b/tools/importer-rest-api-specs/components/parser/dataworkarounds/workarounds.go @@ -9,6 +9,7 @@ import ( var workarounds = []workaround{ workaroundAuthorization25080{}, + workaroundDigitalTwins25120{}, workaroundAutomation25108{}, workaroundBatch21291{}, workaroundContainerService21394{},