-
Notifications
You must be signed in to change notification settings - Fork 719
Expand file tree
/
Copy pathProgram.cs
More file actions
68 lines (57 loc) · 2.7 KB
/
Program.cs
File metadata and controls
68 lines (57 loc) · 2.7 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
63
64
65
66
67
68
using Asp.Versioning;
using Scalar.AspNetCore;
using System.Reflection;
[assembly: Microsoft.AspNetCore.Mvc.ApiController]
[assembly: AssemblyDescription( "An example API" )]
var builder = WebApplication.CreateBuilder( args );
builder.Services.AddControllers();
builder.Services.AddProblemDetails();
builder.Services.AddApiVersioning(
options =>
{
// reporting api versions will return the headers
// "api-supported-versions" and "api-deprecated-versions"
options.ReportApiVersions = true;
options.Policies.Deprecate( 0.9 )
.Effective( DateTimeOffset.Now )
.Link( "policy.html" )
.Title( "Version Deprecation Policy" )
.Type( "text/html" );
options.Policies.Sunset( 0.9 )
.Effective( DateTimeOffset.Now.AddDays( 60 ) )
.Link( "policy.html" )
.Title( "Version Sunset Policy" )
.Type( "text/html" );
} )
.AddMvc()
.AddApiExplorer(
options =>
{
// add the versioned api explorer, which also adds IApiVersionDescriptionProvider service
// note: the specified format code will format the version as "'v'major[.minor][-status]"
options.GroupNameFormat = "'v'VVV";
// note: this option is only necessary when versioning by url segment. the SubstitutionFormat
// can also be used to control the format of the API version in route templates
options.SubstituteApiVersionInUrl = true;
} )
.AddOpenApi( options => options.Document.AddScalarTransformers() );
var app = builder.Build();
if ( app.Environment.IsDevelopment() )
{
app.MapOpenApi().WithDocumentPerVersion();
app.MapScalarApiReference(
options =>
{
var descriptions = app.DescribeApiVersions();
for ( var i = 0; i < descriptions.Count; i++ )
{
var description = descriptions[i];
var isDefault = i == descriptions.Count - 1;
options.AddDocument( description.GroupName, description.GroupName, isDefault: isDefault );
}
} );
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.Run();