|
9 | 9 | using Swashbuckle.AspNetCore.Swagger; |
10 | 10 | using System.IO; |
11 | 11 | using System.Reflection; |
| 12 | + using static Microsoft.AspNetCore.Mvc.CompatibilityVersion; |
12 | 13 |
|
13 | 14 | /// <summary> |
14 | 15 | /// Represents the startup process for the application. |
@@ -36,20 +37,26 @@ public Startup( IConfiguration configuration ) |
36 | 37 | /// <param name="services">The collection of services to configure the application with.</param> |
37 | 38 | public void ConfigureServices( IServiceCollection services ) |
38 | 39 | { |
39 | | - // add the versioned api explorer, which also adds IApiVersionDescriptionProvider service |
40 | | - // note: the specified format code will format the version as "'v'major[.minor][-status]" |
| 40 | + // the sample application always uses the latest version, but you may want an explict version such as Version_2_2 |
| 41 | + // note: Endpoint Routing is enabled by default; however, if you need legacy style routing via IRouter, change it to false |
| 42 | + services.AddMvc( options => options.EnableEndpointRouting = true ).SetCompatibilityVersion( Latest ); |
| 43 | + services.AddApiVersioning( |
| 44 | + options => |
| 45 | + { |
| 46 | + // reporting api versions will return the headers "api-supported-versions" and "api-deprecated-versions" |
| 47 | + options.ReportApiVersions = true; |
| 48 | + } ); |
41 | 49 | services.AddVersionedApiExplorer( |
42 | 50 | options => |
43 | 51 | { |
| 52 | + // add the versioned api explorer, which also adds IApiVersionDescriptionProvider service |
| 53 | + // note: the specified format code will format the version as "'v'major[.minor][-status]" |
44 | 54 | options.GroupNameFormat = "'v'VVV"; |
45 | 55 |
|
46 | 56 | // note: this option is only necessary when versioning by url segment. the SubstitutionFormat |
47 | 57 | // can also be used to control the format of the API version in route templates |
48 | 58 | options.SubstituteApiVersionInUrl = true; |
49 | 59 | } ); |
50 | | - |
51 | | - services.AddMvc(); |
52 | | - services.AddApiVersioning( options => options.ReportApiVersions = true ); |
53 | 60 | services.AddSwaggerGen( |
54 | 61 | options => |
55 | 62 | { |
@@ -110,7 +117,7 @@ static Info CreateInfoForApiVersion( ApiVersionDescription description ) |
110 | 117 | { |
111 | 118 | var info = new Info() |
112 | 119 | { |
113 | | - Title = $"Sample API {description.ApiVersion}", |
| 120 | + Title = "Sample API", |
114 | 121 | Version = description.ApiVersion.ToString(), |
115 | 122 | Description = "A sample application with Swagger, Swashbuckle, and API versioning.", |
116 | 123 | Contact = new Contact() { Name = "Bill Mei", Email = "bill.mei@somewhere.com" }, |
|
0 commit comments