Skip to content

Commit

Permalink
tools/importer-rest-api-specs: adding a workaround for digitaltwins
Browse files Browse the repository at this point in the history
  • Loading branch information
tombuildsstuff committed Aug 2, 2023
1 parent 27f0726 commit e4ea691
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 == "Automation" && apiDefinition.ApiVersion == "2022-08-08"
}

func (workaroundDigitalTwins25120) Name() string {
return "Automation / 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 e4ea691

Please sign in to comment.