-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStartup.cs
More file actions
62 lines (59 loc) · 2.17 KB
/
Copy pathStartup.cs
File metadata and controls
62 lines (59 loc) · 2.17 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
50
51
52
53
54
55
56
57
58
59
60
61
62
using AzureFunctions.Extensions.Swashbuckle;
using Microsoft.Azure.Functions.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using Swashbuckle.AspNetCore.SwaggerGen;
using Microsoft.OpenApi;
using AzureFunctions.Extensions.Swashbuckle.Settings;
[assembly: FunctionsStartup(typeof(SampleFunction.Startup))]
namespace SampleFunction
{
class Startup : FunctionsStartup
{
public override void Configure(IFunctionsHostBuilder builder)
{
builder.AddSwashBuckle(Assembly.GetExecutingAssembly(), opts =>
{
opts.SpecVersion = OpenApiSpecVersion.OpenApi3_0;
opts.ConfigureSwaggerGen = (x =>
{
x.DocumentFilter<CustomSwaggerDocumentAttribute>();
x.EnableAnnotations();
x.CustomOperationIds(apiDesc =>
{
return apiDesc.TryGetMethodInfo(out MethodInfo methodInfo)
? methodInfo.Name
: new Guid().ToString();
});
});
// remove code as query parameter
opts.AddCodeParameter = false;
// see host.json to remove /api/ from route prefix
opts.PrependOperationWithRoutePrefix = true;
opts.Title = "Sample Function API Swagger";
});
}
}
public class CustomSwaggerDocumentAttribute : IDocumentFilter
{
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
{
swaggerDoc.Info = new OpenApiInfo
{
Title = "Sample Function API",
Version = "v1",
Description = "Sample Function API",
Contact = new OpenApiContact
{
Name = "Bill Chesnut",
Email = "bill.chesnut@sixpivot.com.au",
Url = new Uri("https://www.sixpivot.com.au/"),
},
};
}
}
}