Azure / azure-sdk-for-go

This repository is for active development of the Azure SDK for Go. For consumers of the SDK we recommend visiting our public developer docs at:
https://docs.microsoft.com/azure/developer/go/
MIT License
1.59k stars 821 forks source link

ResourceSKUZoneDetails.UnmarshalJSON can't parse uppercase keys #23342

Open HuShaoRu opened 1 month ago

HuShaoRu commented 1 month ago

Bug Report

When I used ResourceSKUsClient to get the list of Microsoft.Compute SKUs, I found I couldn't get sku.LocationInfo[].ZoneDetails[].Name (always empty).

I find, the api returns Name in zoneDetails, however, the sdk only matches name (see func (r *ResourceSKUZoneDetails) UnmarshalJSON in models_serde.go

It might be an error from resource provider, but at least the sdk can't work now.

sku.LocationInfo[].ZoneDetails[].Name should not be empty if API returns it.

use Resource Skus - List or az vm list-skus --resource-type virtualMachines --location eastus2 --query "[?name=='Standard_D2s_v3'].locationInfo[0].zoneDetails[0]", you will find the api returns Name instead of name.

> az vm list-skus --resource-type virtualMachines  --location eastus2 --query "[?name=='Standard_D2s_v3'].locationInfo[0].zoneDetails[0]"
[
  {
    "Name": [
      "3",
      "2",
      "1"
    ],
    "capabilities": [
      {
        "name": "UltraSSDAvailable",
        "value": "True"
      }
    ],
    "name": null
  }
]

Here I use a simple program to reproduce:

package main

import (
    "encoding/json"
    "fmt"

    "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/compute/armcompute/v6"
    "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2022-03-01/compute"
)

func main() {
    var d armcompute.ResourceSKUZoneDetails // track2
    _ = json.Unmarshal([]byte("{\"Name\":[\"1\",\"2\",\"3\"]}"), &d)
    fmt.Println(len(d.Name)) // 0

    type Details armcompute.ResourceSKUZoneDetails
    var dd Details // wrapped track2, so it won't use defined UnmarshalJSON
    _ = json.Unmarshal([]byte("{\"Name\":[\"1\",\"2\",\"3\"]}"), &dd)
    fmt.Println(len(dd.Name)) // 3

    var ddd compute.ResourceSkuZoneDetails // track1
    _ = json.Unmarshal([]byte("{\"Name\":[\"1\",\"2\",\"3\"]}"), &ddd)
    fmt.Println(len(*ddd.Name)) // 3
}
github-actions[bot] commented 1 month ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @amjads1 @avirishuv @Drewm3 @vaibhav-agar.

lirenhe commented 1 month ago

Looks this is a SDK issue, remove the 'service attention' label for now.

Alancere commented 1 month ago

Hi @HuShaoRu,armcompute sdk UnmarshalJSON parses keys starting with lowercase characters by default:https://github.com/Azure/azure-sdk-for-go/blob/main/sdk/resourcemanager/compute/armcompute/models_serde.go#L10582


swagger defineitions(lower case): https://github.com/Azure/azure-rest-api-specs/blob/main/specification/compute/resource-manager/Microsoft.Compute/Skus/stable/2021-07-01/skus.json#L164


    type Details armcompute.ResourceSKUZoneDetails
    var dd Details // wrapped track2, so it won't use defined UnmarshalJSON

The method you mentioned above does not inherit the UnmarshalJSON functions of armcompute.ResourceSKUZoneDetails, so it can Unmarshal to Name

github-actions[bot] commented 1 month ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @amjads1 @avirishuv @Drewm3 @vaibhav-agar.

TravisCragg-MSFT commented 2 weeks ago

@HuShaoRu We are aware of these capitalization inconsistencies and are working to resolve them via a larger project.