Skip to content

Commit

Permalink
[Refactoring] Fixed an issue deserializing Strings when no response i…
Browse files Browse the repository at this point in the history
…s declared in OpenAPI.
  • Loading branch information
joerghartmann authored Nov 3, 2023
1 parent 76946d4 commit 6f1fe29
Show file tree
Hide file tree
Showing 37 changed files with 212 additions and 270 deletions.
16 changes: 7 additions & 9 deletions Client/Com/Cumulocity/Client/Api/AlarmsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public AlarmsApi(HttpClient httpClient)
using var response = await _httpClient.SendAsync(request: request, cancellationToken: cToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeWithContentInfo().ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializerWrapper.DeserializeAsync<AlarmCollection<TAlarm>?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);;
return await JsonSerializerWrapper.DeserializeAsync<AlarmCollection<TAlarm>?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);
}

/// <inheritdoc />
Expand Down Expand Up @@ -111,8 +111,7 @@ public AlarmsApi(HttpClient httpClient)
request.Headers.TryAddWithoutValidation("Accept", "application/json");
using var response = await _httpClient.SendAsync(request: request, cancellationToken: cToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeWithContentInfo().ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializerWrapper.DeserializeAsync<string?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);;
return await response.Content.ReadAsStringAsync().ConfigureAwait(false);
}

/// <inheritdoc />
Expand Down Expand Up @@ -140,7 +139,7 @@ public AlarmsApi(HttpClient httpClient)
using var response = await _httpClient.SendAsync(request: request, cancellationToken: cToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeWithContentInfo().ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializerWrapper.DeserializeAsync<TAlarm?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);;
return await JsonSerializerWrapper.DeserializeAsync<TAlarm?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);
}

/// <inheritdoc />
Expand Down Expand Up @@ -170,8 +169,7 @@ public AlarmsApi(HttpClient httpClient)
request.Headers.TryAddWithoutValidation("Accept", "application/json");
using var response = await _httpClient.SendAsync(request: request, cancellationToken: cToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeWithContentInfo().ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializerWrapper.DeserializeAsync<string?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);;
return await response.Content.ReadAsStringAsync().ConfigureAwait(false);
}

/// <inheritdoc />
Expand All @@ -188,7 +186,7 @@ public AlarmsApi(HttpClient httpClient)
using var response = await _httpClient.SendAsync(request: request, cancellationToken: cToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeWithContentInfo().ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializerWrapper.DeserializeAsync<TAlarm?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);;
return await JsonSerializerWrapper.DeserializeAsync<TAlarm?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);
}

/// <inheritdoc />
Expand Down Expand Up @@ -218,7 +216,7 @@ public AlarmsApi(HttpClient httpClient)
using var response = await _httpClient.SendAsync(request: request, cancellationToken: cToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeWithContentInfo().ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializerWrapper.DeserializeAsync<TAlarm?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);;
return await JsonSerializerWrapper.DeserializeAsync<TAlarm?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);
}

/// <inheritdoc />
Expand Down Expand Up @@ -246,6 +244,6 @@ public async Task<int> GetNumberOfAlarms(System.DateTime? dateFrom = null, Syste
using var response = await _httpClient.SendAsync(request: request, cancellationToken: cToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeWithContentInfo().ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializerWrapper.DeserializeAsync<int>(responseStream, cancellationToken: cToken).ConfigureAwait(false);;
return await JsonSerializerWrapper.DeserializeAsync<int>(responseStream, cancellationToken: cToken).ConfigureAwait(false);
}
}
10 changes: 4 additions & 6 deletions Client/Com/Cumulocity/Client/Api/ApplicationBinariesApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public ApplicationBinariesApi(HttpClient httpClient)
using var response = await _httpClient.SendAsync(request: request, cancellationToken: cToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeWithContentInfo().ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializerWrapper.DeserializeAsync<ApplicationBinaries?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);;
return await JsonSerializerWrapper.DeserializeAsync<ApplicationBinaries?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);
}

/// <inheritdoc />
Expand All @@ -71,7 +71,7 @@ public ApplicationBinariesApi(HttpClient httpClient)
using var response = await _httpClient.SendAsync(request: request, cancellationToken: cToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeWithContentInfo().ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializerWrapper.DeserializeAsync<Application?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);;
return await JsonSerializerWrapper.DeserializeAsync<Application?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);
}

/// <inheritdoc />
Expand All @@ -87,8 +87,7 @@ public ApplicationBinariesApi(HttpClient httpClient)
request.Headers.TryAddWithoutValidation("Accept", "application/vnd.com.nsn.cumulocity.error+json, application/zip");
using var response = await _httpClient.SendAsync(request: request, cancellationToken: cToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeWithContentInfo().ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializerWrapper.DeserializeAsync<string?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);;
return await response.Content.ReadAsStringAsync().ConfigureAwait(false);
}

/// <inheritdoc />
Expand All @@ -104,7 +103,6 @@ public ApplicationBinariesApi(HttpClient httpClient)
request.Headers.TryAddWithoutValidation("Accept", "application/json");
using var response = await _httpClient.SendAsync(request: request, cancellationToken: cToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeWithContentInfo().ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializerWrapper.DeserializeAsync<string?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);;
return await response.Content.ReadAsStringAsync().ConfigureAwait(false);
}
}
11 changes: 5 additions & 6 deletions Client/Com/Cumulocity/Client/Api/ApplicationVersionsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public ApplicationVersionsApi(HttpClient httpClient)
using var response = await _httpClient.SendAsync(request: request, cancellationToken: cToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeWithContentInfo().ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializerWrapper.DeserializeAsync<ApplicationVersion?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);;
return await JsonSerializerWrapper.DeserializeAsync<ApplicationVersion?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);
}

/// <inheritdoc />
Expand All @@ -69,7 +69,7 @@ public ApplicationVersionsApi(HttpClient httpClient)
using var response = await _httpClient.SendAsync(request: request, cancellationToken: cToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeWithContentInfo().ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializerWrapper.DeserializeAsync<ApplicationVersionCollection?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);;
return await JsonSerializerWrapper.DeserializeAsync<ApplicationVersionCollection?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);
}

/// <inheritdoc />
Expand All @@ -95,7 +95,7 @@ public ApplicationVersionsApi(HttpClient httpClient)
using var response = await _httpClient.SendAsync(request: request, cancellationToken: cToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeWithContentInfo().ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializerWrapper.DeserializeAsync<ApplicationVersion?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);;
return await JsonSerializerWrapper.DeserializeAsync<ApplicationVersion?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);
}

/// <inheritdoc />
Expand All @@ -115,8 +115,7 @@ public ApplicationVersionsApi(HttpClient httpClient)
request.Headers.TryAddWithoutValidation("Accept", "application/json");
using var response = await _httpClient.SendAsync(request: request, cancellationToken: cToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeWithContentInfo().ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializerWrapper.DeserializeAsync<string?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);;
return await response.Content.ReadAsStringAsync().ConfigureAwait(false);
}

/// <inheritdoc />
Expand All @@ -136,6 +135,6 @@ public ApplicationVersionsApi(HttpClient httpClient)
using var response = await _httpClient.SendAsync(request: request, cancellationToken: cToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeWithContentInfo().ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializerWrapper.DeserializeAsync<ApplicationVersion?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);;
return await JsonSerializerWrapper.DeserializeAsync<ApplicationVersion?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);
}
}
21 changes: 10 additions & 11 deletions Client/Com/Cumulocity/Client/Api/ApplicationsApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ApplicationsApi(HttpClient httpClient)
using var response = await _httpClient.SendAsync(request: request, cancellationToken: cToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeWithContentInfo().ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializerWrapper.DeserializeAsync<ApplicationCollection?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);;
return await JsonSerializerWrapper.DeserializeAsync<ApplicationCollection?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);
}

/// <inheritdoc />
Expand All @@ -92,7 +92,7 @@ public ApplicationsApi(HttpClient httpClient)
using var response = await _httpClient.SendAsync(request: request, cancellationToken: cToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeWithContentInfo().ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializerWrapper.DeserializeAsync<Application?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);;
return await JsonSerializerWrapper.DeserializeAsync<Application?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);
}

/// <inheritdoc />
Expand All @@ -109,7 +109,7 @@ public ApplicationsApi(HttpClient httpClient)
using var response = await _httpClient.SendAsync(request: request, cancellationToken: cToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeWithContentInfo().ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializerWrapper.DeserializeAsync<Application?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);;
return await JsonSerializerWrapper.DeserializeAsync<Application?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);
}

/// <inheritdoc />
Expand All @@ -136,7 +136,7 @@ public ApplicationsApi(HttpClient httpClient)
using var response = await _httpClient.SendAsync(request: request, cancellationToken: cToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeWithContentInfo().ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializerWrapper.DeserializeAsync<Application?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);;
return await JsonSerializerWrapper.DeserializeAsync<Application?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);
}

/// <inheritdoc />
Expand All @@ -156,8 +156,7 @@ public ApplicationsApi(HttpClient httpClient)
request.Headers.TryAddWithoutValidation("Accept", "application/json");
using var response = await _httpClient.SendAsync(request: request, cancellationToken: cToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeWithContentInfo().ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializerWrapper.DeserializeAsync<string?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);;
return await response.Content.ReadAsStringAsync().ConfigureAwait(false);
}

/// <inheritdoc />
Expand All @@ -179,7 +178,7 @@ public ApplicationsApi(HttpClient httpClient)
using var response = await _httpClient.SendAsync(request: request, cancellationToken: cToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeWithContentInfo().ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializerWrapper.DeserializeAsync<Application?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);;
return await JsonSerializerWrapper.DeserializeAsync<Application?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);
}

/// <inheritdoc />
Expand All @@ -196,7 +195,7 @@ public ApplicationsApi(HttpClient httpClient)
using var response = await _httpClient.SendAsync(request: request, cancellationToken: cToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeWithContentInfo().ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializerWrapper.DeserializeAsync<ApplicationCollection?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);;
return await JsonSerializerWrapper.DeserializeAsync<ApplicationCollection?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);
}

/// <inheritdoc />
Expand All @@ -213,7 +212,7 @@ public ApplicationsApi(HttpClient httpClient)
using var response = await _httpClient.SendAsync(request: request, cancellationToken: cToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeWithContentInfo().ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializerWrapper.DeserializeAsync<ApplicationCollection?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);;
return await JsonSerializerWrapper.DeserializeAsync<ApplicationCollection?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);
}

/// <inheritdoc />
Expand All @@ -236,7 +235,7 @@ public ApplicationsApi(HttpClient httpClient)
using var response = await _httpClient.SendAsync(request: request, cancellationToken: cToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeWithContentInfo().ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializerWrapper.DeserializeAsync<ApplicationCollection?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);;
return await JsonSerializerWrapper.DeserializeAsync<ApplicationCollection?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);
}

/// <inheritdoc />
Expand All @@ -259,6 +258,6 @@ public ApplicationsApi(HttpClient httpClient)
using var response = await _httpClient.SendAsync(request: request, cancellationToken: cToken).ConfigureAwait(false);
await response.EnsureSuccessStatusCodeWithContentInfo().ConfigureAwait(false);
await using var responseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
return await JsonSerializerWrapper.DeserializeAsync<ApplicationCollection?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);;
return await JsonSerializerWrapper.DeserializeAsync<ApplicationCollection?>(responseStream, cancellationToken: cToken).ConfigureAwait(false);
}
}
Loading

0 comments on commit 6f1fe29

Please sign in to comment.