Skip to content

Commit a4975ad

Browse files
committed
Try patch request (requires hack in generated code, otherwise only works the first time)
1 parent 777b7f9 commit a4975ad

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Examples/OpenApiLiblabClientExample/output/csharp/Example/Program.cs

+5
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@
2424
Attributes = new PersonAttributesInPostRequest("Doe", "John")
2525
}));
2626

27+
var patchResponse = await client.People.PatchPersonAsync(new PersonPatchRequestDocument(new PersonDataInPatchRequest(PersonResourceType.People, "1")
28+
{
29+
Attributes = new PersonAttributesInPatchRequest("Mister2", "Smith")
30+
}), "1");
31+
2732
Console.WriteLine(response);

src/Examples/OpenApiLiblabClientExample/output/csharp/JsonApiDotNetCoreClientExample/Services/PeopleService.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// This file was generated by liblab | https://liblab.com/
22

3+
using System.Net;
34
using System.Net.Http.Json;
45
using JsonApiDotNetCoreClientExample.Http;
56
using JsonApiDotNetCoreClientExample.Http.Serialization;
@@ -124,7 +125,7 @@ public async Task<PersonPrimaryResponseDocument> GetPersonAsync(
124125
/// <param name="input">The attributes and relationships of the person to update. Omitted fields are left unchanged.</param>
125126
/// <param name="id">The identifier of the person to update.</param>
126127
/// <param name="query">For syntax, see the documentation for the [`include`](https://www.jsonapi.net/usage/reading/including-relationships.html)/[`filter`](https://www.jsonapi.net/usage/reading/filtering.html)/[`sort`](https://www.jsonapi.net/usage/reading/sorting.html)/[`page`](https://www.jsonapi.net/usage/reading/pagination.html)/[`fields`](https://www.jsonapi.net/usage/reading/sparse-fieldset-selection.html) query string parameters.</param>
127-
public async Task<PersonPrimaryResponseDocument> PatchPersonAsync(
128+
public async Task<PersonPrimaryResponseDocument?> PatchPersonAsync(
128129
PersonPatchRequestDocument input,
129130
string id,
130131
object? query = null,
@@ -146,6 +147,12 @@ public async Task<PersonPrimaryResponseDocument> PatchPersonAsync(
146147
.ConfigureAwait(false);
147148
response.EnsureSuccessStatusCode();
148149

150+
// HACK: Prevent crash during deserialization, caused by empty response body.
151+
if (response.StatusCode == HttpStatusCode.NoContent)
152+
{
153+
return null;
154+
}
155+
149156
return await response
150157
.Content.ReadFromJsonAsync<PersonPrimaryResponseDocument>(
151158
_jsonSerializerOptions,

0 commit comments

Comments
 (0)