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.18k stars 4.54k forks source link

[BUG] Using GeographyEntity.Neighborhood causes RequestFailedException #40183

Closed jlrosenlof-kr closed 3 months ago

jlrosenlof-kr commented 7 months ago

Library name and version

Azure.Maps.Search 1.0.0-beta.4

Describe the bug

I can do an address search with other GeographicEntity types such as GeographicEntity.Municipality and GeographicEntity.MunicipalitySubdivision but when I try to use the GeographicEntity.Neighborhood property to set the GeographicEntity type, I get a RequestFailedException. The exception lists acceptable GeographicEntity types and one of the types listed is spelled "Neighbourhood". It seems that either the GeographicEntity.Neighborhood is setting the wrong string or it is setting the string to be Neighborhood and the Maps API doesn't accept the spelling "Neighborhood".

Expected behavior

Use the GeographicEntity.Neighborhood property to set the SearchAddressOptions.EntityType and be able to do a successful address search.

Actual behavior

Request fails with the following exception:

RequestFailedException: Invalid EntityType value. Allowed value(s): Country, CountrySubdivision, CountrySecondarySubdivision, CountryTertiarySubdivision, Municipality, MunicipalitySubdivision, Neighbourhood, PostalCodeArea
Status: 400 (Bad Request)
ErrorCode: 400 BadRequest

Content:
{"error":{"code":"400 BadRequest","message":"Invalid EntityType value. Allowed value(s): Country, CountrySubdivision, CountrySecondarySubdivision, CountryTertiarySubdivision, Municipality, MunicipalitySubdivision, Neighbourhood, PostalCodeArea"}}

Headers:
x-ms-azuremaps-region: REDACTED
X-Content-Type-Options: REDACTED
Strict-Transport-Security: REDACTED
X-Cache: REDACTED
X-MSEdge-Ref: REDACTED
Date: Thu, 23 Nov 2023 02:40:25 GMT
Content-Length: 246
Content-Type: application/json; charset=utf-8

Reproduction Steps

This code works:

string subscriptionKey = "key-goes-here";
AzureKeyCredential keyCred = new AzureKeyCredential(subscriptionKey);
MapsSearchClient searchClient = new MapsSearchClient(keyCred);
SearchAddressOptions searchOpts = new SearchAddressOptions();
searchOpts.EntityType = GeographicEntity.Municipality;

var rslt = await searchClient.SearchAddressAsync("Los Angeles, CA", searchOpts).ConfigureAwait(false);

This code doesn't work:

string subscriptionKey = "key-goes-here";
AzureKeyCredential keyCred = new AzureKeyCredential(subscriptionKey);
MapsSearchClient searchClient = new MapsSearchClient(keyCred);
SearchAddressOptions searchOpts = new SearchAddressOptions();
searchOpts.EntityType = GeographicEntity.Neighborhood;

var rslt = await searchClient.SearchAddressAsync("Los Angeles, CA", searchOpts).ConfigureAwait(false);

Environment

OS: Windows 10 .NET runtime version: .NET 5.0.17

dubiety commented 5 months ago

Hi @jlrosenlof-kr ,

Thanks you for reporting this issue. We'll look into this issue soon!

mayrro commented 5 months ago

Hi, There is is spelling error in GeographicEntity. The NeighbourhoodValue is missing an "u". The value is also defined in the generated GeographicEntity, but the property Neighbourhood is missing there.

The entire GeographicEntity cs file could be dropped if the property is moved to the generated one:

public static GeographicEntity Neighbourhood { get; } = new GeographicEntity(NeighbourhoodValue);
/// <summary> Determines if two <see cref="GeographicEntity"/> values are the same. </summary>     

The NeighbourhoodValue is already spelled correctly here. private const string NeighbourhoodValue = "Neighbourhood";

When you fix this, please also add the Neighbourhood property to the MapsAddress and parse it's value in MapsAddress.Serialization.cs.

if (property.NameEquals("neighbourhood"u8))
{
    neighbourhood = property.Value.GetString();
    continue;
}

It's in the json response, but not added to the class yet. Thank you!