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.58k stars 815 forks source link

insights.WebTestLocationsClient.List fails with JSON deserialisation error #9284

Closed ppanyukov closed 4 years ago

ppanyukov commented 4 years ago

Bug Report

Full repro program here: https://github.com/ppanyukov/azure-sdk-for-go-issues/tree/master/issues/webtest-locations-json-error


Using code like this ends up with JSON desrialisation error.

    locationsClient := insights.NewWebTestLocationsClient(subID)
    locationsClient.Authorizer = authoriser
    _, gotErr := locationsClient.List(ctx, aiRg, aiName)  // <== error here

error (formatted for bettter readability):

BUG: webtest-locations-json-error
  - Want: <nil>
  - Got : insights.WebTestLocationsClient#List: Failure responding to request: StatusCode=200 -- 
          Original Error: Error occurred unmarshalling JSON - 
          Error = 'json: cannot unmarshal array into Go value of type insights.ApplicationInsightsWebTestLocationsListResult' JSON = 
          '
              [
                  {
                      "DisplayName": "North Central US",
                      "Tag": "us-il-ch1-azr"
                  },
                  {
                      "DisplayName": "West Europe",
                      "Tag": "emea-nl-ams-azr"
                  },
                  {
                      "DisplayName": "Southeast Asia",
                      "Tag": "apac-sg-sin-azr"
                  },
                  {
                      "DisplayName": "West US",
                      "Tag": "us-ca-sjc-azr"
                  },
                  {
                      "DisplayName": "South Central US",
                      "Tag": "us-tx-sn1-azr"
                  },
                  {
                      "DisplayName": "East US",
                      "Tag": "us-va-ash-azr"
                  },
                  {
                      "DisplayName": "East Asia",
                      "Tag": "apac-hk-hkn-azr"
                  },
                  {
                      "DisplayName": "North Europe",
                      "Tag": "emea-gb-db3-azr"
                  },
                  {
                      "DisplayName": "Japan East",
                      "Tag": "apac-jp-kaw-edge"
                  },
                  {
                      "DisplayName": "Australia East",
                      "Tag": "emea-au-syd-edge"
                  },
                  {
                      "DisplayName": "France Central (Formerly France South)",
                      "Tag": "emea-ch-zrh-edge"
                  },
                  {
                      "DisplayName": "France Central",
                      "Tag": "emea-fr-pra-edge"
                  },
                  {
                      "DisplayName": "UK South",
                      "Tag": "emea-ru-msa-edge"
                  },
                  {
                      "DisplayName": "UK West",
                      "Tag": "emea-se-sto-edge"
                  },
                  {
                      "DisplayName": "Brazil South",
                      "Tag": "latam-br-gru-edge"
                  },
                  {
                      "DisplayName": "Central US",
                      "Tag": "us-fl-mia-edge"
                  }
              ]
          '
ghost commented 4 years ago

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @azmonapplicationinsights.

ArcturusZhang commented 4 years ago

Hi @ppanyukov thanks for this issue!

While this issue should be a swagger or service issue, the response of this List request is defined here, therefore the SDK is expecting that the response body should be something like this:

{
   "value": [
      // the array of list result
   ]
}

instead, the service returns the array without wrapping it. This does not conform the convention of List response in Azure. I will take some time to open an issue in azure-rest-api-specs and the progress will be tracked there.

ArcturusZhang commented 4 years ago

This issue is closed in favor of the upstream issue: https://github.com/Azure/azure-rest-api-specs/issues/9463 Thanks!