Skip to content

Commit 194dd6d

Browse files
committed
Try sending a request body: requires to modify generated code to set correct Content-Type.
1 parent b300e38 commit 194dd6d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Example;
44
using JsonApiDotNetCoreClientExample;
55
using JsonApiDotNetCoreClientExample.Config;
6+
using JsonApiDotNetCoreClientExample.Models;
67
using Environment = JsonApiDotNetCoreClientExample.Http.Environment;
78

89
var config = new JsonApiDotNetCoreClientExampleConfig
@@ -18,4 +19,9 @@
1819
// Commented out because it does not work due to broken inheritance.
1920
//PeopleMessageFormatter.PrintPeople(response);
2021

22+
var postResponse = await client.People.PostPersonAsync(new PersonPostRequestDocument(new PersonDataInPostRequest(PersonResourceType.People)
23+
{
24+
Attributes = new PersonAttributesInPostRequest("Doe", "John")
25+
}));
26+
2127
Console.WriteLine(response);

src/Examples/OpenApiLiblabClientExample/output/csharp/JsonApiDotNetCoreClientExample/Http/RequestBuilder.cs

Lines changed: 4 additions & 1 deletion
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.Http.Headers;
34
using System.Net.Http.Json;
45
using System.Text.Json;
56
using JsonApiDotNetCoreClientExample.Http.Serialization;
@@ -112,7 +113,9 @@ public RequestBuilder SetOptionalHeader(string key, object? value, bool explode
112113
/// </summary>
113114
public RequestBuilder SetContentAsJson(object content, JsonSerializerOptions? options = null)
114115
{
115-
_content = JsonContent.Create(content, options: options);
116+
// HACK: There's no way to set the Content-Type header, which is required for JSON:API.
117+
//_content = JsonContent.Create(content, options: options);
118+
_content = JsonContent.Create(content, MediaTypeHeaderValue.Parse("application/vnd.api+json"), options);
116119
return this;
117120
}
118121

0 commit comments

Comments
 (0)