forked from Azure/azure-functions-openapi-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Startup.cs
106 lines (93 loc) · 5.67 KB
/
Startup.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
using System;
using System.Reflection;
using System.Threading.Tasks;
using AutoFixture;
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Abstractions;
using Microsoft.Azure.WebJobs.Extensions.OpenApi.Core.Configurations;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
[assembly: FunctionsStartup(typeof(Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.InProc.Startup))]
namespace Microsoft.Azure.WebJobs.Extensions.OpenApi.FunctionApp.InProc
{
public class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.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;
})
;
}
}
}