hashicorp / go-azure-helpers

This repository contains various helpers and wrappers for working with Azure and the Azure SDK for Go.
Mozilla Public License 2.0
57 stars 43 forks source link

Investigate: Another Common Type for Availability Zone #192

Open tombuildsstuff opened 10 months ago

tombuildsstuff commented 10 months ago

SQL @ 2023-02-01-preview now contains:

type AvailabilityZoneType string

const (
    AvailabilityZoneTypeNoPreference AvailabilityZoneType = "NoPreference"
    AvailabilityZoneTypeOne          AvailabilityZoneType = "1"
    AvailabilityZoneTypeThree        AvailabilityZoneType = "3"
    AvailabilityZoneTypeTwo          AvailabilityZoneType = "2"
)

func PossibleValuesForAvailabilityZoneType() []string {
    return []string{
        string(AvailabilityZoneTypeNoPreference),
        string(AvailabilityZoneTypeOne),
        string(AvailabilityZoneTypeThree),
        string(AvailabilityZoneTypeTwo),
    }
}

func (s *AvailabilityZoneType) UnmarshalJSON(bytes []byte) error {
    var decoded string
    if err := json.Unmarshal(bytes, &decoded); err != nil {
        return fmt.Errorf("unmarshaling: %+v", err)
    }
    out, err := parseAvailabilityZoneType(decoded)
    if err != nil {
        return fmt.Errorf("parsing %q: %+v", decoded, err)
    }
    *s = *out
    return nil
}

Which differs from other services - we need to investigate whether this needs to become a new Common Type (e.g. is centrally defined/used as a common swagger type) - and then create custom Expand and Flatten functions to normalise this on our side.

tombuildsstuff commented 10 months ago

Checking the Swagger repository, it looks like this is specific to SQL at present: https://github.com/pmahanandire/azure-rest-api-specs/blob/0a58e97bb58d5e878b628511a0b29111bd184e95/specification/sql/resource-manager/Microsoft.Sql/preview/2023-02-01-preview/Databases.json#L1404-L1417