-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Program.cs
50 lines (46 loc) · 1.99 KB
/
Program.cs
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
50
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using NJsonSchema;
using NJsonSchema.CodeGeneration;
using NJsonSchema.CodeGeneration.CSharp;
using NJsonSchema.CodeGeneration.CSharp.Models;
using NSwag;
using NSwag.CodeGeneration;
using NSwag.CodeGeneration.CSharp;
namespace NetlifySharp.Generator
{
public class Program
{
public static async Task Main(string[] args)
{
// Read the Open API YAML specification
OpenApiDocument document = await OpenApiYamlDocument.FromUrlAsync("https://raw.githubusercontent.com/netlify/open-api/master/swagger.yml");
// Generate the code
CSharpClientGeneratorSettings clientSettings = new CSharpClientGeneratorSettings
{
ClassName = nameof(NetlifyClient),
CSharpGeneratorSettings =
{
Namespace = nameof(NetlifySharp),
PropertyNameGenerator = new PascalCasePropertyNameGenerator()
},
ParameterNameGenerator = new CamelCaseParameterNameGenerator(),
ExceptionClass = nameof(NetlifyException),
InjectHttpClient = false,
UseHttpClientCreationMethod = true
};
clientSettings.CSharpGeneratorSettings.TemplateFactory = new CustomTemplateFactory(
clientSettings.CSharpGeneratorSettings.TemplateFactory,
clientSettings);
CSharpClientGenerator generator = new CSharpClientGenerator(document, clientSettings);
string code = generator.GenerateFile();
// Make the constructor private so we can write our own
code = code.Replace($"public {clientSettings.ClassName}(", $"private {clientSettings.ClassName}(");
// Write to a file in the client project
System.IO.File.WriteAllText($"../../src/NetlifySharp/{clientSettings.ClassName}.Generated.cs", code);
}
}
}