You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
REQUIRED:
- Replace duplicate code with AddOpenApi() calls per version with 1 "AddOpenApi" call from Asp.Versioning itself
- Change GroupNameFormat from 4 V's to 3 V's to prevent exception about keyed services.
OPTIONAL:
- Call "AddMvc" for controllers. Without it, things seem to work, but I believe it's an integral part. All the examples from the asp.versioning repo have it, so I believe this should, too.
Copy file name to clipboardExpand all lines: v10/controllers/queryheader-versioning/Program.cs
+11-6Lines changed: 11 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,6 @@
2
2
3
3
varbuilder=WebApplication.CreateBuilder(args);
4
4
5
-
builder.Services.AddOpenApi("v1");
6
-
builder.Services.AddOpenApi("v2");
7
-
8
5
builder.Services.AddControllers();
9
6
10
7
builder.Services.AddApiVersioning(options =>
@@ -48,12 +45,20 @@
48
45
// note: the specified format code will format the version as "'v'major[.minor][-status]"
49
46
// More information: https://github.com/dotnet/aspnet-api-versioning/wiki/Version-Format#custom-api-version-format-strings
50
47
// Without this, the OpenAPI document will not generate correctly.
51
-
options.GroupNameFormat="'v'VVVV";
52
-
});
48
+
options.GroupNameFormat="'v'VVV";
49
+
})
50
+
.AddMvc()
51
+
// You must call "AddOpenApi" after "AddApiVersioning" to ensure you use Asp.Versioning's variant.
52
+
// This variant of "AddOpenApi" is required to properly integrate with API versioning and generate versioned OpenAPI documents.
53
+
.AddOpenApi();
53
54
54
55
varapp=builder.Build();
55
56
56
-
app.MapOpenApi();
57
+
// WithDocumentPerVersion() is an extension method provided by the Asp.Versioning.OpenApi package.
58
+
// It configures the OpenAPI endpoint to generate a separate document for each API version.
59
+
// This allows clients to retrieve documentation specific to the version of the API they are using.
60
+
// This approach is preferable compared to having to call "services.AddOpenApi()" multiple times for each version, which can lead to maintenance issues and potential misconfigurations when adding new versions.
Copy file name to clipboardExpand all lines: v10/controllers/url-versioning/Program.cs
+10-5Lines changed: 10 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,6 @@
2
2
3
3
varbuilder=WebApplication.CreateBuilder(args);
4
4
5
-
builder.Services.AddOpenApi("v1");
6
-
builder.Services.AddOpenApi("v2");
7
-
8
5
builder.Services.AddControllers();
9
6
10
7
builder.Services.AddApiVersioning(options =>
@@ -31,11 +28,19 @@
31
28
// note: this option is only necessary when versioning by url segment. the SubstitutionFormat
32
29
// can also be used to control the format of the API version in route templates
33
30
options.SubstituteApiVersionInUrl=true;
34
-
});
31
+
})
32
+
.AddMvc()
33
+
// You must call "AddOpenApi" after "AddApiVersioning" to ensure you use Asp.Versioning's variant.
34
+
// This variant of "AddOpenApi" is required to properly integrate with API versioning and generate versioned OpenAPI documents.
35
+
.AddOpenApi();
35
36
36
37
varapp=builder.Build();
37
38
38
-
app.MapOpenApi();
39
+
// WithDocumentPerVersion() is an extension method provided by the Asp.Versioning.OpenApi package.
40
+
// It configures the OpenAPI endpoint to generate a separate document for each API version.
41
+
// This allows clients to retrieve documentation specific to the version of the API they are using.
42
+
// This approach is preferable compared to having to call "services.AddOpenApi()" multiple times for each version, which can lead to maintenance issues and potential misconfigurations when adding new versions.
// Supported/deprecated API versions will be reported in response headers
@@ -52,12 +49,19 @@
52
49
// note: the specified format code will format the version as "'v'major[.minor][-status]"
53
50
// More information: https://github.com/dotnet/aspnet-api-versioning/wiki/Version-Format#custom-api-version-format-strings
54
51
// Without this, the OpenAPI document will not generate correctly.
55
-
options.GroupNameFormat="'v'VVVV";
56
-
});
52
+
options.GroupNameFormat="'v'VVV";
53
+
})
54
+
// You must call "AddOpenApi" after "AddApiVersioning" to ensure you use Asp.Versioning's variant.
55
+
// This variant of "AddOpenApi" is required to properly integrate with API versioning and generate versioned OpenAPI documents.
56
+
.AddOpenApi();
57
57
58
58
varapp=builder.Build();
59
59
60
-
app.MapOpenApi();
60
+
// WithDocumentPerVersion() is an extension method provided by the Asp.Versioning.OpenApi package.
61
+
// It configures the OpenAPI endpoint to generate a separate document for each API version.
62
+
// This allows clients to retrieve documentation specific to the version of the API they are using.
63
+
// This approach is preferable compared to having to call "services.AddOpenApi()" multiple times for each version, which can lead to maintenance issues and potential misconfigurations when adding new versions.
Copy file name to clipboardExpand all lines: v10/minimal-api/queryheader-versioning/Program.cs
+10-6Lines changed: 10 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,6 @@
2
2
3
3
varbuilder=WebApplication.CreateBuilder(args);
4
4
5
-
builder.Services.AddOpenApi("v1");
6
-
builder.Services.AddOpenApi("v2");
7
-
8
5
builder.Services.AddApiVersioning(options =>
9
6
{
10
7
// Supported/deprecated API versions will be reported in response headers
@@ -46,12 +43,19 @@
46
43
// note: the specified format code will format the version as "'v'major[.minor][-status]"
47
44
// More information: https://github.com/dotnet/aspnet-api-versioning/wiki/Version-Format#custom-api-version-format-strings
48
45
// Without this, the OpenAPI document will not generate correctly.
49
-
options.GroupNameFormat="'v'VVVV";
50
-
});
46
+
options.GroupNameFormat="'v'VVV";
47
+
})
48
+
// You must call "AddOpenApi" after "AddApiVersioning" to ensure you use Asp.Versioning's variant.
49
+
// This variant of "AddOpenApi" is required to properly integrate with API versioning and generate versioned OpenAPI documents.
50
+
.AddOpenApi();
51
51
52
52
varapp=builder.Build();
53
53
54
-
app.MapOpenApi();
54
+
// WithDocumentPerVersion() is an extension method provided by the Asp.Versioning.OpenApi package.
55
+
// It configures the OpenAPI endpoint to generate a separate document for each API version.
56
+
// This allows clients to retrieve documentation specific to the version of the API they are using.
57
+
// This approach is preferable compared to having to call "services.AddOpenApi()" multiple times for each version, which can lead to maintenance issues and potential misconfigurations when adding new versions.
Copy file name to clipboardExpand all lines: v10/minimal-api/url-versioning/Program.cs
+9-5Lines changed: 9 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -2,9 +2,6 @@
2
2
3
3
varbuilder=WebApplication.CreateBuilder(args);
4
4
5
-
builder.Services.AddOpenApi("v1");
6
-
builder.Services.AddOpenApi("v2");
7
-
8
5
builder.Services.AddApiVersioning(options =>
9
6
{
10
7
// Supported/deprecated API versions will be reported in response headers
@@ -29,11 +26,18 @@
29
26
// note: this option is only necessary when versioning by url segment. the SubstitutionFormat
30
27
// can also be used to control the format of the API version in route templates
31
28
options.SubstituteApiVersionInUrl=true;
32
-
});
29
+
})
30
+
// You must call "AddOpenApi" after "AddApiVersioning" to ensure you use Asp.Versioning's variant.
31
+
// This variant of "AddOpenApi" is required to properly integrate with API versioning and generate versioned OpenAPI documents.
32
+
.AddOpenApi();
33
33
34
34
varapp=builder.Build();
35
35
36
-
app.MapOpenApi();
36
+
// WithDocumentPerVersion() is an extension method provided by the Asp.Versioning.OpenApi package.
37
+
// It configures the OpenAPI endpoint to generate a separate document for each API version.
38
+
// This allows clients to retrieve documentation specific to the version of the API they are using.
39
+
// This approach is preferable compared to having to call "services.AddOpenApi()" multiple times for each version, which can lead to maintenance issues and potential misconfigurations when adding new versions.
0 commit comments