I'm using the swagger definitions to generate a C# client (using nswagstudio) and the deserialisation of responses is blowing up with an exception which is basically the "id" is not valid.
- Code: Select all | TOGGLE FULL SIZE
if (status_ == "200")
{
var responseData_ = await response_.Content.ReadAsStringAsync().ConfigureAwait(false);
var result_ = default(Data);
try
{
result_ = Newtonsoft.Json.JsonConvert.DeserializeObject<Data>(responseData_, _settings.Value);
return result_;
}
catch (System.Exception exception_)
{
throw new SwaggerException("Could not deserialize the response body.", status_, responseData_, headers_, exception_);
}
}
If I look at the response payload
"{\"id\":\"0DRTNY0EBWPW9G1SHNV641B06C\",\"value\":\"1.23\",\"feed_id\":745760,\"feed_key\":null,\"created_at\":\"2017-12-31T04:17:08Z\",\"location\":null,\"lat\":null,\"lon\":null,\"ele\":null,\"created_epoch\":1514693828,\"expiration\":\"2018-01-30T04:17:08Z\"}"
and then compare with the response definition
- Code: Select all | TOGGLE FULL SIZE
"Data": {
"type": "object",
"properties": {
"id": {
"type": "number",
"readOnly": true
},
"value": {
"type": "string"
},
"feed_id": {
"type": "number"
},
"group_id": {
"readOnly": true,
"type": "number"
},
"expiration": {
"type": "string"
},
"lat": {
"type": "number"
},
"lon": {
"type": "number"
},
"ele": {
"type": "number"
},
"completed_at": {
"readOnly": true,
"type": "string"
},
"created_at": {
"readOnly": true,
"type": "string"
},
"updated_at": {
"readOnly": true,
"type": "string"
},
"created_epoch": {
"readOnly": true,
"type": "number"
}
}
}
It looks like "id" is expected to be a number but "0DRTNY0EBWPW9G1SHNV641B06C" doesn't look like a number to me.
I have a modified local copy of the definition file (changed id to a string) and my client appears to work ok for my CreateData call, but I haven't tried any others.
What am I missing?
Thanks
@KiwiBryn
blog.devmobile.co.nz