-
Notifications
You must be signed in to change notification settings - Fork 197
/
Program.cs
113 lines (100 loc) · 5.82 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Reflection;
using System.Threading.Tasks;
using AutoFixture;
using Microsoft.Azure.Functions.Worker.Extensions.OpenApi.Extensions;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;
namespace Microsoft.Azure.Functions.Worker.Extensions.OpenApi.FunctionApp.OutOfProc
{
public class Program
{
public static void Main()
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults(worker => worker.UseNewtonsoftJson())
.ConfigureServices(services =>
{
services.AddSingleton<Fixture>(new Fixture())
.AddSingleton<IOpenApiConfigurationOptions>(_ =>
{
var options = new OpenApiConfigurationOptions()
{
Info = new OpenApiInfo()
{
Version = DefaultOpenApiConfigurationOptions.GetOpenApiDocVersion(),
Title = $"{DefaultOpenApiConfigurationOptions.GetOpenApiDocTitle()} (Injected)",
Description = DefaultOpenApiConfigurationOptions.GetOpenApiDocDescription(),
TermsOfService = new Uri("https://github.com/Azure/azure-functions-openapi-extension"),
Contact = new OpenApiContact()
{
Name = "Enquiry",
Email = "[email protected]",
Url = new Uri("https://github.com/Azure/azure-functions-openapi-extension/issues"),
},
License = new OpenApiLicense()
{
Name = "MIT",
Url = new Uri("http://opensource.org/licenses/MIT"),
}
},
Servers = DefaultOpenApiConfigurationOptions.GetHostNames(),
OpenApiVersion = DefaultOpenApiConfigurationOptions.GetOpenApiVersion(),
IncludeRequestingHostName = DefaultOpenApiConfigurationOptions.IsFunctionsRuntimeEnvironmentDevelopment(),
ForceHttps = DefaultOpenApiConfigurationOptions.IsHttpsForced(),
ForceHttp = DefaultOpenApiConfigurationOptions.IsHttpForced(),
};
return options;
})
.AddSingleton<IOpenApiHttpTriggerAuthorization>(_ =>
{
var auth = new OpenApiHttpTriggerAuthorization(req =>
{
var result = default(OpenApiAuthorizationResult);
// ⬇️⬇️⬇️ Add your custom authorisation logic ⬇️⬇️⬇️
//
// CUSTOM AUTHORISATION LOGIC
//
// ⬆️⬆️⬆️ Add your custom authorisation logic ⬆️⬆️⬆️
return Task.FromResult(result);
});
return auth;
})
.AddSingleton<IOpenApiCustomUIOptions>(_ =>
{
var assembly = Assembly.GetExecutingAssembly();
var options = new OpenApiCustomUIOptions(assembly)
{
GetStylesheet = () =>
{
var result = string.Empty;
// ⬇️⬇️⬇️ Add your logic to get your custom stylesheet ⬇️⬇️⬇️
//
// CUSTOM LOGIC TO GET STYLESHEET
//
// ⬆️⬆️⬆️ Add your logic to get your custom stylesheet ⬆️⬆️⬆️
return Task.FromResult(result);
},
GetJavaScript = () =>
{
var result = string.Empty;
// ⬇️⬇️⬇️ Add your logic to get your custom JavaScript ⬇️⬇️⬇️
//
// CUSTOM LOGIC TO GET JAVASCRIPT
//
// ⬆️⬆️⬆️ Add your logic to get your custom JavaScript ⬆️⬆️⬆️
return Task.FromResult(result);
}
};
return options;
})
;
})
.Build();
host.Run();
}
}
}