Azure / azure-sdk-for-net

This repository is for active development of the Azure SDK for .NET. For consumers of the SDK we recommend visiting our public developer docs at https://learn.microsoft.com/dotnet/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-net.
MIT License
5.37k stars 4.78k forks source link

[BUG] GetApiAsync throws exception when the api doesn't have a service url #34627

Closed ilmax closed 1 year ago

ilmax commented 1 year ago

Library name and version

Azure.ResourceManager.ApiManagement 1.0.1

Describe the bug

There's a bug in the deserialization code of the SDK whereas the api returns a 200 response that looks like this:

"id": "/subscriptions/{sub-id}/resourceGroups/{rg-name}/providers/Microsoft.ApiManagement/service/{apim-name}/apis/{api-name}",
  "type": "Microsoft.ApiManagement/service/apis",
  "name": "{apim-name}",
  "properties": {
    "displayName": "{DisplayName}",
    "apiRevision": "1",
    "description": "",
    "subscriptionRequired": true,
    "serviceUrl": "",
    "path": "{path}",
    "protocols": [
      "https"
    ],
    "authenticationSettings": {
      "oAuth2": null,
      "openid": null
    },
    "subscriptionKeyParameterNames": {
      "header": "Ocp-Apim-Subscription-Key",
      "query": "subscription-key"
    },
    "isCurrent": true,
    "apiRevisionDescription": "",
    "apiVersion": "",
    "apiVersionDescription": ""
  }
}

and the library throws this exception: An exception of type 'System.UriFormatException' occurred in System.Private.CoreLib.dll but was not handled in user code Invalid URI: The URI is empty

Stack Trace:

Unhandled exception. System.UriFormatException: Invalid URI: The URI is empty.
   at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind, UriCreationOptions& creationOptions)
   at System.Uri..ctor(String uriString)
   at Azure.ResourceManager.ApiManagement.ApiData.DeserializeApiData(JsonElement element)
   at Azure.ResourceManager.ApiManagement.ApiRestOperations.GetAsync(String subscriptionId, String resourceGroupName, String serviceName, String apiId, CancellationToken cancellationToken)
   at Azure.ResourceManager.ApiManagement.ApiCollection.GetAsync(String apiId, CancellationToken cancellationToken)
   at Azure.ResourceManager.ApiManagement.ApiManagementServiceResource.GetApiAsync(String apiId, CancellationToken cancellationToken)

Expected behavior

The call should succeed

Actual behavior

The call throws exception

Reproduction Steps

1: Create an apim service 2: Create an api without a backed service 3: use the SDK to get the api

Here's the wrong check: https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/apimanagement/Azure.ResourceManager.ApiManagement/src/Generated/Models/ApiData.Serialization.cs#L336-L344 The code looks for a null string but the api call returns an empty string.

Environment

No response

jsquire commented 1 year ago

Thank you for your feedback. Tagging and routing to the team member best able to assist.

HarveyLink commented 1 year ago

Hi @ilmax , Thank you for using Azure SDK for .NET. The issue has been fixed in the latest package. Please take a look.

dennis1f commented 1 year ago

Hi @HarveyLink, In which package has this been fixed? I'm using 1.1.0-beta.1 and am still experiencing the same exception.