Skip to content

Commit 280e449

Browse files
committed
Add a very minimal example of a generated OpenAPI client for JsonApiDotNetCoreExample project. The only call that currently doesn't crash is the one associated to deleting a primary resource
1 parent a0d5bff commit 280e449

File tree

6 files changed

+2757
-0
lines changed

6 files changed

+2757
-0
lines changed

JsonApiDotNetCore.sln

+15
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenApiTests", "test\OpenAp
5050
EndProject
5151
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JsonApiDotNetCore.OpenApiClient", "src\JsonApiDotNetCore.OpenApiClient\JsonApiDotNetCore.OpenApiClient.csproj", "{5ADAA902-5A75-4ECB-B4B4-03291D63CE9C}"
5252
EndProject
53+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JsonApiDotNetCoreExampleClient", "src\Examples\JsonApiDotNetCoreExampleClient\JsonApiDotNetCoreExampleClient.csproj", "{7FC5DFA3-6F66-4FD8-820D-81E93856F252}"
54+
EndProject
5355
Global
5456
GlobalSection(SolutionConfigurationPlatforms) = preSolution
5557
Debug|Any CPU = Debug|Any CPU
@@ -252,6 +254,18 @@ Global
252254
{5ADAA902-5A75-4ECB-B4B4-03291D63CE9C}.Release|x64.Build.0 = Release|Any CPU
253255
{5ADAA902-5A75-4ECB-B4B4-03291D63CE9C}.Release|x86.ActiveCfg = Release|Any CPU
254256
{5ADAA902-5A75-4ECB-B4B4-03291D63CE9C}.Release|x86.Build.0 = Release|Any CPU
257+
{7FC5DFA3-6F66-4FD8-820D-81E93856F252}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
258+
{7FC5DFA3-6F66-4FD8-820D-81E93856F252}.Debug|Any CPU.Build.0 = Debug|Any CPU
259+
{7FC5DFA3-6F66-4FD8-820D-81E93856F252}.Debug|x64.ActiveCfg = Debug|Any CPU
260+
{7FC5DFA3-6F66-4FD8-820D-81E93856F252}.Debug|x64.Build.0 = Debug|Any CPU
261+
{7FC5DFA3-6F66-4FD8-820D-81E93856F252}.Debug|x86.ActiveCfg = Debug|Any CPU
262+
{7FC5DFA3-6F66-4FD8-820D-81E93856F252}.Debug|x86.Build.0 = Debug|Any CPU
263+
{7FC5DFA3-6F66-4FD8-820D-81E93856F252}.Release|Any CPU.ActiveCfg = Release|Any CPU
264+
{7FC5DFA3-6F66-4FD8-820D-81E93856F252}.Release|Any CPU.Build.0 = Release|Any CPU
265+
{7FC5DFA3-6F66-4FD8-820D-81E93856F252}.Release|x64.ActiveCfg = Release|Any CPU
266+
{7FC5DFA3-6F66-4FD8-820D-81E93856F252}.Release|x64.Build.0 = Release|Any CPU
267+
{7FC5DFA3-6F66-4FD8-820D-81E93856F252}.Release|x86.ActiveCfg = Release|Any CPU
268+
{7FC5DFA3-6F66-4FD8-820D-81E93856F252}.Release|x86.Build.0 = Release|Any CPU
255269
EndGlobalSection
256270
GlobalSection(SolutionProperties) = preSolution
257271
HideSolutionNode = FALSE
@@ -273,6 +287,7 @@ Global
273287
{71287D6F-6C3B-44B4-9FCA-E78FE3F02289} = {7A2B7ADD-ECB5-4D00-AA6A-D45BD11C97CF}
274288
{B693DE14-BB28-496F-AB39-B4E674ABCA80} = {24B15015-62E5-42E1-9BA0-ECE6BE7AA15F}
275289
{5ADAA902-5A75-4ECB-B4B4-03291D63CE9C} = {7A2B7ADD-ECB5-4D00-AA6A-D45BD11C97CF}
290+
{7FC5DFA3-6F66-4FD8-820D-81E93856F252} = {026FBC6C-AF76-4568-9B87-EC73457899FD}
276291
EndGlobalSection
277292
GlobalSection(ExtensibilityGlobals) = postSolution
278293
SolutionGuid = {A2421882-8F0A-4905-928F-B550B192F9A4}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using JsonApiDotNetCore.OpenApiClient;
2+
using Newtonsoft.Json;
3+
4+
namespace JsonApiDotNetCoreExampleClient.GeneratedCode
5+
{
6+
public partial class ExampleApiClient : JsonApiClient
7+
{
8+
partial void UpdateJsonSerializerSettings(JsonSerializerSettings settings)
9+
{
10+
SetSerializerSettingsForJsonApi(settings);
11+
12+
settings.Formatting = Formatting.Indented;
13+
}
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using JsonApiDotNetCore.OpenApiClient;
2+
3+
namespace JsonApiDotNetCoreExampleClient.GeneratedCode
4+
{
5+
partial interface IExampleApiClient : IJsonApiClient
6+
{
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>$(NetCoreAppVersion)</TargetFramework>
5+
</PropertyGroup>
6+
7+
<ItemGroup>
8+
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
9+
<PackageReference Include="Microsoft.Extensions.ApiDescription.Client" Version="5.0.9">
10+
<PrivateAssets>all</PrivateAssets>
11+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
12+
</PackageReference>
13+
<PackageReference Include="NSwag.ApiDescription.Client" Version="13.13.2">
14+
<PrivateAssets>all</PrivateAssets>
15+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
16+
</PackageReference>
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<OpenApiReference Include="swagger.json">
21+
<ClassName>ExampleApiClient</ClassName>
22+
<CodeGenerator>NSwagCSharp</CodeGenerator>
23+
<Namespace>JsonApiDotNetCoreExampleClient.GeneratedCode</Namespace>
24+
<Options>/UseBaseUrl:false /GenerateClientInterfaces:true</Options>
25+
</OpenApiReference>
26+
</ItemGroup>
27+
28+
<ItemGroup>
29+
<ProjectReference Include="..\..\JsonApiDotNetCore.OpenApiClient\JsonApiDotNetCore.OpenApiClient.csproj" />
30+
</ItemGroup>
31+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Net.Http;
3+
using System.Threading.Tasks;
4+
using JsonApiDotNetCoreExampleClient.GeneratedCode;
5+
6+
#pragma warning disable AV1210 // Catch a specific exception instead of Exception, SystemException or ApplicationException
7+
8+
namespace JsonApiDotNetCoreExampleClient
9+
{
10+
internal class Program
11+
{
12+
private static async Task Main()
13+
{
14+
using var httpClient = new HttpClient
15+
{
16+
BaseAddress = new Uri("http://localhost:14140")
17+
};
18+
19+
IExampleApiClient exampleApiClient = new ExampleApiClient(httpClient);
20+
21+
try
22+
{
23+
const int nonExistingId = int.MaxValue;
24+
await exampleApiClient.Delete_personAsync(nonExistingId);
25+
}
26+
catch (ApiException exception)
27+
{
28+
Console.WriteLine(exception.Response);
29+
}
30+
31+
Console.WriteLine("Press any key to close.");
32+
Console.ReadKey();
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)