-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathClientGenerationTests.cs
More file actions
49 lines (40 loc) · 1.5 KB
/
ClientGenerationTests.cs
File metadata and controls
49 lines (40 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using NJsonSchema;
using NSwag.CodeGeneration.Tests;
namespace NSwag.CodeGeneration.CSharp.Tests;
public class ClientGenerationTests
{
[Fact]
public async Task CanGenerateFromJiraOpenApiSpecification()
{
// Jira's OpenAPI spec generates code like this:
//// public bool ShowDaysInColumn { get; set; } = MyNamespace.bool.False;
await VerifyOutput("JIRA_OpenAPI", "jira-open-api.json", compile: false);
}
[Fact]
public async Task CanGenerateFromShipBobOpenApiSpecification()
{
await VerifyOutput("ShipBob_OpenAPI", "shipbob-2025-07.json", compile: true);
}
[Fact]
public async Task CanGenerateFromNhsSpineServicesOpenApiSpecification()
{
await VerifyOutput("NHS_SpineServices_OpenAPI", "nhs-spineservices.json", compile: true);
}
private static async Task VerifyOutput(string name, string fileName, bool compile = true)
{
var specification = await File.ReadAllTextAsync(Path.Combine("TestData", fileName));
var document = await OpenApiDocument.FromJsonAsync(specification, "", SchemaType.OpenApi3);
var generator = new CSharpClientGenerator(document, new CSharpClientGeneratorSettings
{
GenerateOptionalParameters = true,
});
var code = generator.GenerateFile();
await VerifyHelper
.Verify(code, scrubApiComments: false)
.UseFileName(name);
if (compile)
{
CSharpCompiler.AssertCompile(code);
}
}
}