Skip to content

Commit

Permalink
Merge pull request #2883 from hashicorp/b/workaround-for-digitaltwins
Browse files Browse the repository at this point in the history
tools/importer-rest-api-specs: adding a workaround for `digitaltwins`
  • Loading branch information
tombuildsstuff authored Aug 3, 2023
2 parents 0c9ee99 + e2293a7 commit 35e27b8
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

var workarounds = []workaround{
workaroundAuthorization25080{},
workaroundDigitalTwins25120{},
workaroundAutomation25108{},
workaroundBatch21291{},
workaroundContainerService21394{},
Expand Down

0 comments on commit 35e27b8

Please sign in to comment.