ringcentral / RingCentral.Net

RingCentral SDK for .NET
MIT License
19 stars 26 forks source link

SDK - Parse Phone Number (Beta) #5

Closed stephen-slm closed 5 years ago

stephen-slm commented 5 years ago

General

The SDK properties are incorrectly matched up with the SDK documentation that causes a casting error within the JSON parsing. The RingCentral.GetCountryInfoNumberParser[] just needs to be updated to match the documentation with RingCentral.GetCountryInfoNumberParser Reference 1 and Reference 2

Error

Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'RingCentral.GetCountryInfoNumberParser[]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.

To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object. Path 'homeCountry.uri', line 4, position 11.

Info

Code Snippet(s)

var parseRequest = new ParsePhoneNumberRequest() { originalStrings = new string[] { phoneNumber } };
ParsePhoneNumberResponse phoneNumbers = await this.client.Restapi(this.version).NumberParser().Parse().Post(parseRequest);
tylerlong commented 5 years ago

@tehstun thanks for reporting this.

Actually all of the C# model classes are auto generated from swagger spec here: https://github.com/ringcentral/RingCentral.Net/blob/master/code-generator/rc-platform.yml

And according to https://github.com/ringcentral/RingCentral.Net/blob/be3248d8d8fb4b3e9eed9558e6f140613de744c9/code-generator/rc-platform.yml#L21125 That field is indeed an array.

So the root cause is the swagger spec mismatches with server side behavior.

Please double check and confirm my conclusion. I will ask my teammate to fix the swagger first then I will re-generate the C# code here.

As a workaround, you can request the endpoint directly and parse the response yourself:

var bodyString = await client.Post<string>('/restapi/v1.0/number-parser/parse', parseRequest)
// parse `bodyString` yourself.
tylerlong commented 5 years ago

Issue fixed in latest version

stephen-slm commented 5 years ago

🎉