Skip to content

Commit

Permalink
workaround for machine learning registry status code
Browse files Browse the repository at this point in the history
  • Loading branch information
wuxu92 committed Aug 3, 2023
1 parent 5266df9 commit 369bec3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package dataworkarounds

import (
"fmt"
"net/http"

"github.com/hashicorp/pandora/tools/importer-rest-api-specs/models"
)

var _ workaround = workaroundMachineLearning25142{}

// workaroundMachineLearning25142 works around the missed 202 status code.
// Swagger PR: https://github.com/Azure/azure-rest-api-specs/pull/25142
type workaroundMachineLearning25142 struct {
}

func (workaroundMachineLearning25142) IsApplicable(apiDefinition *models.AzureApiDefinition) bool {
serviceMatches := apiDefinition.ServiceName == "MachineLearningServices"
apiVersionMatches := apiDefinition.ApiVersion == "2023-04-01"
return serviceMatches && apiVersionMatches
}

func (workaroundMachineLearning25142) Name() string {
return "MachineLearningServices / 25142"
}

func (workaroundMachineLearning25142) Process(apiDefinition models.AzureApiDefinition) (*models.AzureApiDefinition, error) {
resource, ok := apiDefinition.Resources["RegistryManagement"]
if !ok {
return nil, fmt.Errorf("couldn't find API Resource MachineLearningServices")
}

operation, ok := resource.Operations["RegistriesCreateOrUpdate"]
if !ok {
return nil, fmt.Errorf("couldn't find Operation RegistriesCreateOrUpdate")
}

operation.ExpectedStatusCodes = append(operation.ExpectedStatusCodes, http.StatusAccepted)
resource.Operations["RegistriesCreateOrUpdate"] = operation

apiDefinition.Resources["RegistryManagement"] = resource
return &apiDefinition, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ var workarounds = []workaround{

// @tombuildsstuff: we also have to account for package names which aren't valid in Go:
workaroundInvalidGoPackageNames{},

workaroundMachineLearning25142{},
}

func ApplyWorkarounds(input []models.AzureApiDefinition, logger hclog.Logger) (*[]models.AzureApiDefinition, error) {
Expand Down

0 comments on commit 369bec3

Please sign in to comment.