-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools/importer-rest-api-specs: adding a workaround for
digitaltwins
- Loading branch information
1 parent
27f0726
commit e4ea691
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
...mporter-rest-api-specs/components/parser/dataworkarounds/workaround_digitaltwins_25120.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters