0

I'm using the client api specification code that was created from their openapi-specifcation located here https://github.com/googlemaps/openapi-specification/releases. (version v1.17.6) I created all the client libraries and I'm using them to call the method Method signature

I'm only using the first 2 parameters destinations and origins.

I have 2 destinations and 1 origin. The get request turns out to be this https://maps.googleapis.com/maps/api/distancematrix/json?destinations=42.7101%2c-78.8026%2c42.991077%2c-78.759279&origins=43.004179%2c-78.751965&key=[mykey]

The response is view of get in browser

I'm not sure what's going on.

1 Answers1

0

Found the issue and there's a bug in the open api specification that ignored the delimiter to use for origins and destinations in method DistanceMatrixAsyncWithHttpInfo() where it was calling this line of code

        if (destinations != null) localVarQueryParams.AddRange(this.Configuration.ApiClient.ParameterToKeyValuePairs("pipe", "destinations", destinations)); // query parameter
        if (origins != null) localVarQueryParams.AddRange(this.Configuration.ApiClient.ParameterToKeyValuePairs("pipe", "origins", origins)); // query parameter

The ParameterToKeyValuePairs() method didn't pass along "pipe" to ParameterToString(). So I had to add the collectionFormat

    public IEnumerable<KeyValuePair<string, string>> ParameterToKeyValuePairs(string collectionFormat, string name, object value)
    {
        var parameters = new List<KeyValuePair<string, string>>();

        if (IsCollection(value) && collectionFormat == "multi")
        {
            var valueCollection = value as IEnumerable;
            parameters.AddRange(from object item in valueCollection select new KeyValuePair<string, string>(name, ParameterToString(collectionFormat,item)));
        }
        else
        {
            parameters.Add(new KeyValuePair<string, string>(name, ParameterToString(collectionFormat, value)));
        }

        return parameters;
    }

So in the ParameterToString() method needed to add the switch statement

        else if (obj is IList)
        {
            var flattenedString = new StringBuilder();
            foreach (var param in (IList)obj)
            {
                if (flattenedString.Length > 0)
                    switch (collectionFormat)
                    {
                        case "pipe": 
                            flattenedString.Append("|"); 
                            break;
                        default: 
                            flattenedString.Append(",");
                            break;
                    };
                flattenedString.Append(param);
            }
            return flattenedString.ToString();
        }