-
Notifications
You must be signed in to change notification settings - Fork 54
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 Azure/azure-re…
- Loading branch information
1 parent
c6b7d93
commit f411380
Showing
3 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
49 changes: 49 additions & 0 deletions
49
...s/importer-rest-api-specs/components/parser/dataworkarounds/workaround_devcenter_26189.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,49 @@ | ||
package dataworkarounds | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/hashicorp/pandora/tools/importer-rest-api-specs/models" | ||
) | ||
|
||
// This workaround fixes an issue in DevCenter where the field `DevCenterUri` is not | ||
// marked as ReadOnly, meaning that it's surfaced as an Optional field rather than | ||
// being Computed. | ||
// | ||
// PR: https://github.com/Azure/azure-rest-api-specs/pull/26189 | ||
// Additional: https://github.com/hashicorp/pandora/pull/2675#issuecomment-1759115231 | ||
|
||
var _ workaround = workaroundDevCenter26189{} | ||
|
||
type workaroundDevCenter26189 struct { | ||
} | ||
|
||
func (workaroundDevCenter26189) IsApplicable(apiDefinition *models.AzureApiDefinition) bool { | ||
return apiDefinition.ServiceName == "DevCenter" && apiDefinition.ApiVersion == "2022-04-01" | ||
} | ||
|
||
func (workaroundDevCenter26189) Name() string { | ||
return "DevCenter / 26189" | ||
} | ||
|
||
func (workaroundDevCenter26189) Process(apiDefinition models.AzureApiDefinition) (*models.AzureApiDefinition, error) { | ||
resource, ok := apiDefinition.Resources["DevCenters"] | ||
if !ok { | ||
return nil, fmt.Errorf("expected a Resource named `DevCenters` but didn't get one") | ||
} | ||
|
||
model, ok := resource.Models["DevCenterProperties"] | ||
if !ok { | ||
return nil, fmt.Errorf("expected a Model named `DevCenterProperties` but didn't get one") | ||
} | ||
field, ok := model.Fields["DevCenterUri"] | ||
if !ok { | ||
return nil, fmt.Errorf("expected a Field named `DevCenterUri` but didn't get one") | ||
} | ||
field.ReadOnly = true | ||
|
||
model.Fields["DevCenterUri"] = field | ||
resource.Models["DevCenterProperties"] = model | ||
apiDefinition.Resources["DevCenters"] = 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