diff --git a/tools/importer-rest-api-specs/components/parser/dataworkarounds/workaround_recoveryservicessiterecovery_26680.go b/tools/importer-rest-api-specs/components/parser/dataworkarounds/workaround_recoveryservicessiterecovery_26680.go new file mode 100644 index 00000000000..fb08c064309 --- /dev/null +++ b/tools/importer-rest-api-specs/components/parser/dataworkarounds/workaround_recoveryservicessiterecovery_26680.go @@ -0,0 +1,87 @@ +package dataworkarounds + +import ( + "fmt" + + "github.com/hashicorp/go-azure-helpers/lang/pointer" + "github.com/hashicorp/pandora/tools/importer-rest-api-specs/models" +) + +var _ workaround = workaroundRecoveryServicesSiteRecovery26680{} + +// workaroundRecoveryServicesSiteRecovery26680 works around the model `CreateCertificateOptions` being +// present within the API but not being documented in the API Definitions - as such this adds the missing +// model/fields to make this useful. +// +// Swagger PR: https://github.com/Azure/azure-rest-api-specs/pull/26680 +type workaroundRecoveryServicesSiteRecovery26680 struct { +} + +func (w workaroundRecoveryServicesSiteRecovery26680) IsApplicable(apiDefinition *models.AzureApiDefinition) bool { + if apiDefinition.ServiceName != "RecoveryServicesSiteRecovery" { + return false + } + + apiVersions := map[string]struct{}{ + "2022-10-01": {}, + "2023-01-01": {}, + "2023-02-01": {}, + "2023-04-01": {}, + "2023-06-01": {}, + } + if _, apiVersionMatches := apiVersions[apiDefinition.ApiVersion]; !apiVersionMatches { + return false + } + + if _, resourceExists := apiVersions["VaultCertificates"]; !resourceExists { + return false + } + + return true +} + +func (w workaroundRecoveryServicesSiteRecovery26680) Name() string { + return "RecoveryServicesSiteRecovery / 26680" +} + +func (w workaroundRecoveryServicesSiteRecovery26680) Process(apiDefinition models.AzureApiDefinition) (*models.AzureApiDefinition, error) { + resource, ok := apiDefinition.Resources["VaultCertificates"] + if !ok { + return nil, fmt.Errorf("expected a Resource named `VaultCertificates` but didn't get one") + } + + // 1. Add the missing model + resource.Models["CertificateCreateOptions"] = models.ModelDetails{ + Fields: map[string]models.FieldDetails{ + "ValidityInHours": { + Required: false, + JsonName: "validityInHours", + ObjectDefinition: &models.ObjectDefinition{ + Type: models.ObjectDefinitionInteger, + }, + }, + }, + } + + // 2. Add the field referencing the missing model + model, ok := resource.Models["CertificateRequest"] + if !ok { + return nil, fmt.Errorf("expected a Model named `CertificateRequest` but didn't get one") + } + model.Fields["CertificateCreateOptions"] = models.FieldDetails{ + Required: false, + ReadOnly: false, + Sensitive: false, + JsonName: "certificateCreateOptions", + Description: "", + CustomFieldType: nil, + ObjectDefinition: &models.ObjectDefinition{ + ReferenceName: pointer.To("CertificateCreateOptions"), + Type: models.ObjectDefinitionReference, + }, + } + resource.Models["CertificateRequest"] = model + + apiDefinition.Resources["VaultCertificates"] = resource + return &apiDefinition, nil +} diff --git a/tools/importer-rest-api-specs/components/parser/dataworkarounds/workarounds.go b/tools/importer-rest-api-specs/components/parser/dataworkarounds/workarounds.go index 2f39ba61f96..6d000d97fed 100644 --- a/tools/importer-rest-api-specs/components/parser/dataworkarounds/workarounds.go +++ b/tools/importer-rest-api-specs/components/parser/dataworkarounds/workarounds.go @@ -20,6 +20,8 @@ var workarounds = []workaround{ workaroundRedis22407{}, workaroundMachineLearning25142{}, + workaroundRecoveryServicesSiteRecovery26680{}, + // @tombuildsstuff: this is an odd place for this however this allows working around inconsistencies in the Swagger // we should look at moving this into the `resourceids` package when time allows. workaroundInconsistentlyDefinedSegments{},